Giter Club home page Giter Club logo

mothertode's Introduction

As of 17th August 2022... I'm currently redesigning and rewriting MotherTode. Everything is broken and work-in-progress. For the old version, go to the legacy repo.

Follow the rewrite progress here!

MotherTode

MotherTode is a language that helps me to make languages. It's a language language.
For more info, check out the documentation.

How does it work?

Define your language by defining terms, like these:

let Expression = Number | String
let Greeting = {
    match "greeting"
    emit "Hello world!"
}

What does it look like?

This is a mini language that lets you add numbers (don't worry if you don't understand it yet):

match Number

let Number = Add | Literal
let Literal = /[0-9]/+
let Add = {
    match @(Number - Add) "+" @Number
    emit (left, right) => left + right
)

How do I use it?

You can embed it, like this:

<script src="mothertode-embed.js"></script>
<script>
	const language = MotherTode("emit (name) => `Hello ${name}!`")
	console.log(language("world")) //Hello world!
</script>

Or import it, like this:

import { MotherTode } from "./mothertode-import.js"
const language = MotherTode("emit (name) => `Hello ${name}!`")
console.log(language("world")) //Hello world!

Or use it from the command line, like this:

mothertode ./hello.mt "world"

mothertode's People

Contributors

magnogen avatar todepond avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

magnogen

mothertode's Issues

Chain operator works weirdly

++ works unintuitively sometimes. Consider if this is correct, or should change.

You need to manually specify that you want to carry over the rest of a source after a chain, NOT JUST the matched source.

Should this work the same/different as the then operator? #10

'not' operator

Maybe it would be worth being able to match something by saying what it's NOT. Example:

Comment :: "/*" Inner "*/"
Inner :: { not "*/” }

Specify number of repeated term

It might be useful to be able to specify how many times you want a term to be repeated. Imagine you want to match a hex colour code:

:: "#" HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit

It would be great if you could specify that you want only 6 of them... maybe like this... Not sure what syntax would be best.

:: "#" 6 HexDigit

Mass rewrite

Complete redesign + rewrite based on my shower thoughts of the last 9 months.

  • Step 1: TodePond/Frogasaurus#1
  • Step 2: Figure out the different use-cases of MotherTode and structure
  • Step 3: Write the new spec (including lots of words, not funny symbols)
  • Get sidetracked: TodePond/Habitat#54
  • Step 4: Write a minimal term.js #26
  • Step 5: Make the new MotherTode using term.js

Make a standalone mothertode transpiler

I used to have a standalone mothertode parser as part of Frogasaurus, but I removed it to keep that smaller + simpler. I should make a standalone one as part of the Mothertode project I think.

MotherTode(`...`) doesn't always return a function

I wanted to get something working, so I copied your code at the end of README.md
image

That seemed to go semi-well, but it wasnt outputting anything - so I added in a console.log(...). That was a bit finicky.
image

Then I decided to just copy the FizzBuzz language from https://l2wilson94.gitbook.io/mothertode/examples, but that didnt turn out very well either.
image

Turns out language is actually an jumbled mess of otherwise empty arrays... (not all of them are expanded out here)
image

How do I actually use this tool?

`then` operator

Implement a then operator/keyword that lets you perform one match after another.

`term.js`

Literals

  • string
  • regexp

Scope

  • proxy
  • reference
  • hoist
  • scope

Operators

  • list
  • skip
  • maybe
  • many
  • any
  • or
  • except
  • not
  • and
  • select
  • until
  • before

Built-In

  • default
  • end
  • rest
  • anything
  • nothing

Automatic Properties

  • type
  • name
  • translate
  • test

Manual Properties

  • throw
  • match
  • travel
  • select
  • emit
  • check
  • then
  • toString

Performance

  • memo

State

  • options
  • except

There is no error logging!

I removed error logging because it was causing big performance issues. Is this a stupid idea? Maybe. But I should reimplement it in a better way, either way.

Full list of implemented and possible operators

List of operators

It seemed as though the list was going quite quickly, so I've compiled them here.

  • ✔ Many Term+
    Matches 1 or more occurences of a term

  • ✔ Any Term* { Terms }
    Matches 0 or more occurences of a term ( perhaps this could just be replaced with Term+? or Term?+ ? )

  • ✔ Maybe Term? [ Terms ]
    Matches 0 or 1 occurences of a term

  • ✔ Or Term1 | Term2 < Terms >
    Matches any of the terms in the 'list' of options

  • ✔ Except Term1~Term2
    Matches a term, but only if its not a part of another term

  • ❌ Select @Term
    Labels a term for later use, serves no functional purpose

  • ❌ Then Term THEN Term Term, Term
    Matches multiple terms in sequence

  • ❌ Count N Term ( perhaps can be simplified to NTerm, if you restrict terms to only be defined with alphabetic characters)
    Matches a specific number (N) of terms in sequence

The following are suggestions for possible operators

  • ❔ But / Not #Term NOT Term ( { Terms } if you end up removing the Any term, as mentioned above )
    Matches anything that is not a Term

  • ❔ Anything ... ANY
    Any term. After thinking about this, it'd probably be a bad idea to use this in conjunction with Many or Any, unless it becomes lazy like in regex

  • ❔ Built-ins :name: ( inspired by Character Classes in the regex POSIX standard Source )
    This is more like a group of built in terms, but I thought I could put it in here anyway
    Types of characters which turn up it lots of places, so its helpful to have a group that can be used from the beginning, including:

    • :alnum:
      Alphanumeric characters
    • :punct:
      Punctuation characters
    • :xdigit:
      Characters that are hexadecimal digits

In-built syntax

In-built terms could have their own syntax so that they don't overlap with users' created terms

EOF could become :eof:

Add optional comma

Make it so that you can optionally put commas between terms in a sequence of terms

Remove chain operator

The chain operator is kinda confusing, and I think its uses could be fulfilled by an upcoming 'then' operator instead. So maybe remove it?

Embedded JavaScript questions

So I noticed in notes.txt on line 70 - 71, that there seems to be js's arrow function syntax.

Is that an actual js function? If so, will any javascript there work? If not (which would make sense from the | instead of ||) why use syntax that's similar to js, when you can use keywords like and/or and a syntax that's similar to what you've already done with the basic structure of MotherTode, namely:

let either = (a, b) {
    try {
        match a
    } else {
        match b
    }
}
either("foo", "bar")

Not sure if the try thing works, it's up to you, I was trying to make it more side-effecty, instead of returning values, which is similar to how match, throw, let and term work. (at least from what I can see)

If you don't like the try, then this'd probably work instead.

let either = (a, b) {
    match a or b
}
either("foo", "bar")

Loving the notes, very interesting!

Oh and another suggestion: Make MotherTode with MotherTode!

Example in readme refers to discontinued feature

const language = MotherTode(`:: /[a-zA-Z]/+ >> (name) => 'Hello #{name}!'`)
language("world")

Uses the crazy idea I had for string interpolation inside string interpolation. I got rid of that feature because it was weird, so the example should be updated to remove it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.