3 ms·
How to succeed at parsing without really trying
- codelion 13y agoAlso, recursive descent parsing can be used to generate extensible parsers using frameworks like Campl4. http://www.reddit.com/r/ocaml/comments/1gx71p/building_extensible_parsers_with_camlp4/ http://www.reddit.com/r/ocaml/comments/1gx71p/building_exten...
- barrkel 13y agoThe syntax shown is completely trivial, it should be parseable with about a dozen lines without using any generators, frameworks, libraries, string replacements, or anything else. Unless I missed something.
- jmmcd 13y agoYou didn't miss anything. The point (or "the only point") is that he was able to reuse the language's own parser rather than writing any parsing code of his own. For anyone who hasn't seen that technique, it's worth seeing. Whether it's a win depends on taste maybe.
- draegtun 13y agoFor reference, a parser for Newick string/format comes with the Bio::Phylo Perl CPAN module - https://metacpan.org/release/Bio-Phylo https://metacpan.org/release/Bio-Phylo
- lucian1900 13y agoI've done this before with Python, making AST literals directly out of tokens. It's potentially dangerous however, similar to eval-ing input. It can be done safely with care.
- icebraining 13y agoYou can use ast.literal_eval[1] which is supposedly safe (only accepts literal values, not code). [1] http://docs.python.org/2/library/ast.html#ast.literal_eval http://docs.python.org/2/library/ast.html#ast.literal_eval