3 ms·
I'm very glad you asked. I wrote my own parser combinator library in TypeScript partly based on eulalie[0], so it doesn't have a separate lexer and parser and d
by tonyonodi 4y ago
I'm very glad you asked. I wrote my own parser combinator library in TypeScript partly based on eulalie[0], so it doesn't have a separate lexer and parser and doesn't rely heavily on regexes (though it does use them to do things like match a single alphanumeric character). I plan on open sourcing this library one day once I can tidy up the API because I think it would be useful to other people.
But to give you an idea of what that all looks like this is the code for the parser that parses the "as a % of" operator:
append(
string("as"),
oneOrMore(space),
optional(append(string("a"), oneOrMore(space))),
percentSymbol,
oneOrMore(space),
string("of")
)
[0] https://github.com/bodil/eulalie https://github.com/bodil/eulalie
- joe8756438 4y agoThanks for sharing, I had the same question! I wasn't familiar with Eulalie, that's a really interesting approach. I built functionality [0] similar to numpad into a larger record-keeping system, Tap [1]. Precedence rules kindof scramble my brain so I ended up implementing s-expression syntax for Tap formulas. I ended up writing the parser myself, called sowhat, but used a library for tokenization, moo.js [2]. You can see a demo of just the sowhat editor here [3]. 0. https://www.tatatap.com/formulas https://www.tatatap.com/formulas 1. https://www.tatatap.com https://www.tatatap.com 2. https://github.com/no-context/moo https://github.com/no-context/moo 3. https://tatatap-com.github.io/sowhat-editor/ https://tatatap-com.github.io/sowhat-editor/