Technical Report: Towards a Universal Code Formatter through Machine Learning
By Terence John Parr, Jurgen J. Vinju. 2016
5 citations recorded by the source corpus.
There are many declarative frameworks that allow us to implement code formatters relatively easily for any specific language, but constructing them is cumbersome. The first problem is that "everybody" wants to format their code differently, leading to either many formatter variants or a ridiculous number of configuration options. Second, the size of each implementation scales with a language's grammar size, leading to hundreds of rules. In this paper, we solve the formatter construction problem using a novel approach, one that automatically derives formatters for any given language without intervention from a language expert. We introduce a code formatter called CodeBuff that uses machine learning to abstract formatting rules from a representative corpus, using a carefully designed feature set. Our experiments on Java, SQL, and ANTLR grammars show that CodeBuff is efficient, has excellent accuracy, and is grammar invariant for a given language. It also generalizes to a 4th language tested during manuscript preparation.
Subfields: Artificial Intelligence, Information Systems, Software, Natural Language Processing
How researchers see this paper
The researchers whose trusted networks rank it highest, strongest advocate first. Every researcher gets a different order.
In Artificial Intelligence
- Miltiadis Allamanis
- Charles Sutton
- Earl T. Barr
- Premkumar T. Devanbu
- Eran Yahav
- Uri Alon
- Rishabh Singh
- Rafael-Michael Karampatsis
In Information Systems
- Charles Sutton
- Miltiadis Allamanis
- Earl T. Barr
- Premkumar T. Devanbu
- Michael Pradel
- Rishabh Singh
- Rafael-Michael Karampatsis
- Eran Yahav
In Software
- Charles Sutton
- Miltiadis Allamanis
- Earl T. Barr
- Premkumar T. Devanbu
- Michael Pradel
- Rishabh Singh
- Marc Brockschmidt
- Sahil Bhatia
In Natural Language Processing
- Charles Sutton
- Premkumar T. Devanbu
- Miltiadis Allamanis
- Earl T. Barr
- Michael Pradel
- Rishabh Singh
- Rafael-Michael Karampatsis
- Marc Brockschmidt
Citations in the corpus
- A Survey of Machine Learning for Big Code and Naturalness (2017, methodology): “To handle code formatting conventions, Parr and Vinju [152] learn a source code formatter from data by using a set of hand-crafted features from the AST and a k-NN classifier.”