Using the operators of the parser to build out the grammar can get quite long, eg: to code the standard variable expression syntax, I have to write this JavaScript: Sequence(/\${/, 'Chain', /\}/).
One idea of simplifying this is to maybe write a Babel plugin that can take some marker and then convert everything inside it to the relevant code, ie: so I could express the above as something like this instead: ${ Chain }.
While that gain might not look like much, it becomes more apparent with longer sequences like the definition of "chain":
Sequence(Optional('Negation'), 'ChainLink', ZeroOrMore(Sequence(/\./, 'ChainLink')))
In the grammar notation, that could be written as:
Negation? ChainLink .* ChainLink
Also, parsers are hard 😵 Maybe I should think of leaning on an existing parsing library? This one looks very good to me: https://github.com/jneen/parsimmon
Using the operators of the parser to build out the grammar can get quite long, eg: to code the standard variable expression syntax, I have to write this JavaScript:
Sequence(/\${/, 'Chain', /\}/)
.One idea of simplifying this is to maybe write a Babel plugin that can take some marker and then convert everything inside it to the relevant code, ie: so I could express the above as something like this instead:
${ Chain }
.While that gain might not look like much, it becomes more apparent with longer sequences like the definition of "chain":
Sequence(Optional('Negation'), 'ChainLink', ZeroOrMore(Sequence(/\./, 'ChainLink')))
In the grammar notation, that could be written as:
Negation? ChainLink .* ChainLink