Technical Report: Towards a Universal Code Formatter through Machine Learning

06/28/2016
by   Terence Parr, et al.
0

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.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
01/18/2022

Learning grammar with a divide-and-concur neural network

We implement a divide-and-concur iterative projection approach to contex...
research
09/08/2023

A Rapid Prototyping Language Workbench for Textual DSLs based on Xtext: Vision and Progress

Metamodel-based DSL development in language workbenches like Xtext allow...
research
06/06/2023

DashQL – Complete Analysis Workflows with SQL

We present DashQL, a language that describes complete analysis workflows...
research
07/28/2020

Formal Fields: A Framework to Automate Code Generation Across Domains

Code generation, defined as automatically writing a piece of code to sol...
research
05/08/2020

Corrigendum to Improve Language Modelling for Code Completion through Learning General Token Repetition of Source Code

This paper is written because I receive several inquiry emails saying it...
research
11/16/2017

An Encoder-Decoder Framework Translating Natural Language to Database Queries

Machine translation is going through a radical revolution, driven by the...
research
08/14/2022

Synthesis of Semantic Actions in Attribute Grammars

Attribute grammars allow the association of semantic actions to the prod...

Please sign up or login with your details

Forgot password? Click here to reset