about
On-the-Fly Syntax Highlighting Using Neural Networks (arxiv.org)
1 point by belter on Aug 5, 2022 | hide | past | pdf | 1 comment on HN

In plain words: A neural network learns to color code by reusing a language's existing parser rules, so it can highlight quickly even when the code is incomplete or broken. Across three popular languages it reached near-perfect accuracy, beating the regular-expression tools used in web code viewers.

Abstract · On-the-Fly Syntax Highlighting using Neural Networks

With the presence of online collaborative tools for software developers, source code is shared and consulted frequently, from code viewers to merge requests and code snippets. Typically, code highlighting quality in such scenarios is sacrificed in favor of system responsiveness. In these on-the-fly settings, performing a formal grammatical analysis of the source code is not only expensive, but also intractable for the many times the input is an invalid derivation of the language. Indeed, current popular highlighters heavily rely on a system of regular expressions, typically far from the specification of the language's lexer. Due to their complexity, regular expressions need to be periodically updated as more feedback is collected from the users and their design unwelcome the detection of more complex language formations. This paper delivers a deep learning-based approach suitable for on-the-fly grammatical code highlighting of correct and incorrect language derivations, such as code viewers and snippets. It focuses on alleviating the burden on the developers, who can reuse the language's parsing strategy to produce the desired highlighting specification. Moreover, this approach is compared to nowadays online syntax highlighting tools and formal methods in terms of accuracy and execution time, across different levels of grammatical coverage, for three mainstream programming languages. The results obtained show how the proposed approach can consistently achieve near-perfect accuracy in its predictions, thereby outperforming regular expression-based strategies.

Marco Edoardo Palma, Pasquale Salza, Harald C. Gall
arXiv:2208.02815 · cs.SE · submitted Aug 4, 2022
abstract · pdf · html · Accepted for publication in the ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering (ESEC/FSE 2022)

add comment on HN

"...This paper delivers a deep learning-based approach suitable for on-the-fly grammatical code highlighting of correct and incorrect language derivations, such as code viewers and snippets...

...It focuses on alleviating the burden on the developers, who can reuse the language’s parsing strategy to produce the desired highlighting specification. Moreover, this approach is compared to nowadays online syntax highlighting tools and formal methods in terms of accuracy and execution time, across different levels of grammatical coverage, for three mainstream programming languages...

...The results obtained show how the proposed approach can consistently achieve near-perfect accuracy in its predictions, thereby outperforming regular expression-based strategies..."

[PDF]: https://arxiv.org/pdf/2208.02815.pdf