3 ms·
I've written a JS regexp parser and engine. It did not fit in 40 lines. The most obnoxious part is backreferences. The atom \3 is a backreference if the whole
by ridiculous_fish 9y ago
I've written a JS regexp parser and engine. It did not fit in 40 lines.
The most obnoxious part is backreferences. The atom \3 is a backreference if the whole regexp contains at least 3 capture groups; otherwise it is an octal (!) escape for char code 3. But you don't know how many capture groups there are until you're done parsing. This is why JS regexp parsers sometimes must make two passes!
- masklinn 9y agoFWIW back references mean you're way outside of "regular languages" so e.g. DFA usually don't support them.