3 ms·
Can you elaborate a bit on this please? I'd be interested in resources on writing better parsers! Quickly looking at the python standard lib (urlparse, shlex,
by madelyn 7y ago
Can you elaborate a bit on this please? I'd be interested in resources on writing better parsers!
Quickly looking at the python standard lib (urlparse, shlex, etc) and Python packages (NLTK Treebank tokenizer), a lot of packages related to slicing, dicing and parsing strings use a mashup of regex and rule based code.
- IceDane 7y agoParser combinators are the way to go. I don't use python often enough to know if such a library exists for python, but I would assume so.
- cben 7y agoNo experience with them in python, but look also for PEG grammars. They are significantly simpler than the traditional tower of lexer + ambiguous limited lookahead grammar. Plus the memoized Packrat algorithm allows throwing in functions with custom conditions. (Somewhat like parser combinators, they also support custom logic.)