Technical Report: Towards a Universal Code Formatter through Machine Learning
Terence Parr, Jurgin Vinju

TL;DR
This paper presents CodeBuff, a machine learning-based code formatter that automatically derives formatting rules for any language from a representative corpus, reducing manual effort and increasing adaptability.
Contribution
The paper introduces a novel machine learning approach to automatically generate language-agnostic code formatters without expert intervention.
Findings
Efficient and accurate formatting across multiple languages.
Grammar invariance and generalization to unseen languages.
Reduces the need for manual rule specification.
Abstract
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…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Engineering Research · Software Reliability and Analysis Research · Advanced Software Engineering Methodologies
