thymeleafjs icon indicating copy to clipboard operation
thymeleafjs copied to clipboard

Babel plugin for the parser/grammar language

Open ultraq opened this issue 5 years ago • 1 comments

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

ultraq avatar Feb 12 '20 10:02 ultraq

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

ultraq avatar Jan 17 '21 03:01 ultraq