4 ms·
Perl has always been really good at enabling cargo-cult parsing -- the vast majority of "parsers" I've seen in Perl 5 have been ad-hoc, buggy, slow, and informa
by groovy2shoes 11y ago
Perl has always been really good at enabling cargo-cult parsing -- the vast majority of "parsers" I've seen in Perl 5 have been ad-hoc, buggy, slow, and informally-specified. The nice thing about grammars as a language construct is that you get formal specification for free; this aids in understanding the parser. When it comes to parsing, grammars really are the right way to go, either as a built-in or as a library (Elisp, for example, has a few parsing libraries available in MELPA, and there's always good ol' LPeg for Lua).
When all you have are regeces, there's a tendency to model a parser as a finite automaton where transitions are labeled with regex matches, but given how frequently programmers deal with extracting information from text, I think there's a solid argument for grammars or parser combinators being readily available in a language. Really, any text processing task more sophisticated than grep calls for tools more sophisticated than regular expressions.