Full rewrite with a lexer/parser grammar
virtualtam opened this issue · 3 comments
virtualtam commented
It would be more elegant and maintainable to describe the Netscape variants as a grammar, and generate/write a corresponding tokenizer/lexer/parser to process data.
Inspired by:
See:
- https://en.wikipedia.org/wiki/Comparison_of_parser_generators
- https://stackoverflow.com/questions/8002617/php-lexer-and-parser-generator
- https://stackoverflow.com/questions/2093228/lex-and-yacc-in-php
- https://stackoverflow.com/questions/2245962/is-there-an-alternative-for-flex-bison-that-is-usable-on-8-bit-embedded-systems
- https://stackoverflow.com/questions/25049751/constructing-an-abstract-syntax-tree-with-a-list-of-tokens/25106688#25106688
virtualtam commented
I've started experimenting with Hoa\Compiler
, which is a PHP library to define grammars and generate the corresponding tokenizer/lexer/parser:
Documentation:
- https://hoa-project.net/En/Literature/Hack/Compiler.html
- https://www.reddit.com/r/PHP/comments/2hrt8n/hoacompiler_manipulating_dsls_has_never_been/
Example grammars:
virtualtam commented
Experiment code and notes can be found at https://github.com/virtualtam/hoa-netscape-bookmark-parser
virtualtam commented
Interesting use of the PHP DOMDocument API: