ultraq / thymeleafjs

A basic implementation of the Thymeleaf templating engine in JavaScript
Apache License 2.0
52 stars 9 forks source link

Babel plugin for the parser/grammar language #36

Open ultraq opened 4 years ago

ultraq commented 4 years ago

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 commented 3 years ago

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