by sumtechguy · 1y ago · 0 comments
Libraries like python's lrparsing [0] let you assign regex's (aka tokens) to variables, then build grammars by combining them using python expressions. For example:
while_statement = Keyword('while') + '(' + expression + ')' + block
statement = while_statement | ....
block = Token('{') + Repeat(statement + ';') + Token('}')
These grammars are more complex, with more rules you have to follow, but also more checking is done when they are compiled. They tend to mostly work once they do compile. So they are what you asked for, but there is no free lunch.On the down side, lrparsing is pure python so it's slower than python's inbuilt regex's.
We don’t need better language tools. Better parsers can, and already have, been implemented in libraries.
I’d have a look at parser combinators.
Is true though, or perhaps "state"? I know I had to come up with an algorithm because regexp alone couldn't do what I wanted (not even advanced features like lookahead, lookbehind, etc.)