4 ms·
Neat! The comments are an issue, though. But it can be solved: Just parse the comments as AST nodes, too. I did just that for a converter/transpiler which "upd
by archi42 5y ago
Neat! The comments are an issue, though. But it can be solved: Just parse the comments as AST nodes, too.
I did just that for a converter/transpiler which "updated" code written in an old DSL into a much newer variant of that DSL: A lexer, a parser, a transformer and a printer. The result was not as perfect as doing a mindful, manual transformations for each individual case - but the result is still well maintainable. And, most important, the whole task took us merely months instead of years.
Also, Perl/regexes are awesome for this: With a one-shot transformation it does not matter if transforming 100000 lines takes 5m or 10s, so I could save a lot of time by letting lexer & parser try regexes (essentially guessing and some backtracking = stupid long lookahead) instead of writing a minimal LR parser ;-)