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

  1. Miltiadis Allamanis
  2. Charles Sutton
  3. Earl T. Barr
  4. Premkumar T. Devanbu
  5. Eran Yahav
  6. Uri Alon
  7. Rishabh Singh
  8. Rafael-Michael Karampatsis

In Information Systems

  1. Charles Sutton
  2. Miltiadis Allamanis
  3. Earl T. Barr
  4. Premkumar T. Devanbu
  5. Michael Pradel
  6. Rishabh Singh
  7. Rafael-Michael Karampatsis
  8. Eran Yahav

In Software

  1. Charles Sutton
  2. Miltiadis Allamanis
  3. Earl T. Barr
  4. Premkumar T. Devanbu
  5. Michael Pradel
  6. Rishabh Singh
  7. Marc Brockschmidt
  8. Sahil Bhatia

In Natural Language Processing

  1. Charles Sutton
  2. Premkumar T. Devanbu
  3. Miltiadis Allamanis
  4. Earl T. Barr
  5. Michael Pradel
  6. Rishabh Singh
  7. Rafael-Michael Karampatsis
  8. Marc Brockschmidt

Citations in the corpus