3 ms·
This reminds me quite a lot of the "pegs" module in Nim. https://nim-lang.org/docs/pegs.html https://nim-lang.org/docs/pegs.html identifier <- [A-Za-z][A-
by girvo 4y ago
This reminds me quite a lot of the "pegs" module in Nim.
https://nim-lang.org/docs/pegs.html https://nim-lang.org/docs/pegs.html
identifier <- [A-Za-z][A-Za-z0-9_]*
charsetchar <- "\\" . / [^\]]
charset <- "[" "^"? (charsetchar ("-" charsetchar)?)+ "]"
Thats a small snippet of how it is used. It's been one of my favourite parts of using Nim to be honest.
The fact one can get similar ergonomics this way in straight Python is wonderful! I'm definitely going to leverage this.
I've done similar in other languages, but it's never felt quite right. re.VERBOSE is also handy to know.
- WaxProlix 4y agoYou might already be aware of this, but 'pegs' likely refers to Parsing Expression Grammars [1], a super powerful and imho very chill concept which translates into great tooling in lots of languages. 1 https://en.wikipedia.org/wiki/Parsing_expression_grammar https://en.wikipedia.org/wiki/Parsing_expression_grammar
- girvo 4y agoYou surmised right, though I adore Nim's particular implementation of it compared to the times I've attempted it in, say, Javascript :) Parsing expression grammars are easily one of my favourite tools. Honestly, I find them superior to regexes.
- ogogmad 4y agoNever used them, but don't they have memory usage in proportion to the string being parsed? Regexes, LL and LR don't have this shortcoming. This should surely constrain their applications.