Hacker News new | ask | show | jobs
by _xgw 2936 days ago
Couldn't you start from Dart's BNF grammar, create a BNF grammar of "formatted" Dart and then format the code accordingly?
2 comments

Maybe. If you think of the formatted output as a grammar that includes whitespace, you'll probably discover it is very context-sensitive. Then determining what context to synthesize when making the translation is probably more or less equivalent to how you'd otherwise write the formatter.
You could, but in reality it won't work very well due to recursive rules.