3 ms·
It is Perl code to parse X using regular expressions. This is always the worst kind of Perl code imaginable to try to tinker with. It will be fiddly. It will
by bsder 10y ago
It is Perl code to parse X using regular expressions.
This is always the worst kind of Perl code imaginable to try to tinker with.
It will be fiddly. It will have exceptional cases piled upon exceptional cases. It will have hideous numbers of undocumented corners.
All because it isn't a real, actual, fscking parser.
Because we don't really need a parser for this, right now, do we, really?
Yeah, this is one of those cases where "Do the simplest thing" breaks down horribly and very rarely does someone have the wherewithal to apply 2x4 cluebats to the people who persist in writing parsers with regular expressions.
Yes, I have done so (in Python actually). However, my code has a little "counter" in the comments along the lines of "You have debugged a regular expression in this code: <n> times. Use a real parser you idiot."
It is depressing how large I have let that number get before I actually pull my head out of my ass.
- echlebek 10y ago> "Do the simplest thing" You have to do the simplest thing that could actually, possibly work!
- zzzcpan 10y agoYeah, proper parsers are actually super easy once you are comfortable with them and take much much less time than a pile of regexps. Like higher-order parser combinators. You can implement them for most languages in no time and then just construct your parser from a few basic higher-order primitives: regexp tokens, alternations, sequences and repetitions. Getting there though takes a bit of practice, from recursive descent parsers to parser generators.
- kemayo 10y agoWith Python in particular, I think it's because it's the jump from "I can use the standard library" to choosing from the large list of other parser libraries out there. (Or writing your own parser from scratch, but that has some of the same drawbacks as just using regular expressions.)