Regex literals optimization (or how to cheat on benchmarks)
nitely.github.io
nitely.github.io
I remember a neat feature of re2 was you could give it a bunch of regex, and get it to check for all of them at the same time. Made all the difference in an early spam filter I built.
That's true, but mostly irrelevant in practice as you say. Because the NFA is linear in proportion to PATTERN size, not input size, and even an exponential blowup from there isn't a problem. (and many patterns may not blow up)
For example I wrote a very large set of regular languages to describe shell syntax. Compiling it all to a full DFA and then assembly via re2c creates something like 30 KiB of machine code. And it runs fast.
https://www.oilshell.org/release/0.8.5/source-code.wwz/_devb...
http://www.oilshell.org/blog/2020/01/parser-benchmarks.html
So as you say, you get the best of both worlds: a concise language, and speed. The only problem is the syntax, which I'm fixing:
The eggex approach looks very interesting, stand alone, independent from oil. I appreciate they are separate!
When Are Lexer Modes Useful? http://www.oilshell.org/blog/2017/12/17.html
Overview of the parser:
How to Parse Shell Like a Programming Language http://www.oilshell.org/blog/2019/02/07.html
You could look at the architecture like this:
reader -> matcher (generated regular languages) -> lexer -> multiple parsers
The lexer takes the mode parameter and has extra logic for disambiguation. There are multiple parsers for multiple dialects, and they're both hand-written and generated.Feel free to follow up if this catches your interest. I'm looking for feedback on both Eggex and Oil!
more posts:
http://www.oilshell.org/blog/tags.html?tag=eggex#eggex
http://www.oilshell.org/blog/tags.html?tag=parsing-shell#par...
I'm aware of Laurikari's algorithm, I'm not aware of it being correct[0]. Also, their algorithm has POSIX semantics, RE2 (and most PLs regex engines) has PCRE semantics.