Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why do you need a grammar if this is supposed to learn it itself from the code?


The grammar is used to compute the code layout features that CodeBuff learns from: it parses each file and associates spacing and indentation features to trees' contextual features.

Then, when we parse a new file to pretty-print, we parse again with the _same parser_ and the features that were learned are matched to the tree at hand to recover the "right" spacing and indentation features for the given example code.


The hard part of building a code formatter by hand is coding all the formatting rules, not the parsing. All formatters are based upon parsers so that is a constant across them. Creating a grammar from exemplars is still an unsolved problem.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: