Abstract
We report on the experience of developing Merlin, a language server for the OCaml programming language in development since 2013. Merlin is a daemon that connects to your favourite text editor and provides services that require a fine-grained understanding of the programming language syntax and static semantics: instant feedback on warnings and errors, autocompletion, "type of the code under the cursor", "go to definition", etc.
Language servers need to handle incomplete and partially-incorrect programs, and try to be incremental to minimize recomputation after small editing actions. Merlin was built by carefully adapting the existing tools (the OCamllex lexer and Menhir parser generators) to better support incrementality, incompleteness and error handling. These extensions are elegant and general, as demonstrated by the interesting, unplanned uses that the OCaml community found for them. They could be adapted to other frontends -- in any language.
Besides incrementality, we discuss the way Merlin communicates with editors, describe the design decisions that went into some demanding features and report on some of the non-apparent difficulties in building good editor support, emerging from expressive programming languages or frustrating tooling ecosystems.
We expect this experience report to be of interest to authors of interactive language tooling for any programming language; many design choices may be reused, and some hard-won lessons can serve as warnings.
Supplemental Material
- Lukas Diekmann and Laurence Tratt. 2014. Eco: A language composition editor. In Software Language Engineering (SLE).Google Scholar
- Matthew Flatt, Eli Barzilay, and Robert Bruce Findler. 2009. Scribble: closing the book on ad hoc documentation tools. In ICFP. Google ScholarDigital Library
- Nicolas Jeannerod, Yann Régis-Gianas, and Ralf Treinen. 2017. Having Fun With 31.521 Shell Scripts. (April 2017). https://hal.archives-ouvertes.fr/hal-01513750 .Google Scholar
- Clinton L. Jeffery. 2003. Generating LR Syntax Error Messages from Examples. TOPLAS 25, 5 (Sept. 2003), 631–640. Google ScholarDigital Library
- Cyrus Omar, Ian Voysey, Michael Hilton, Joshua Sunshine, Claire Le Goues, Jonathan Aldrich, and Matthew A. Hammer. 2017. Toward Semantic Foundations for Program Editors. In SNAPL.Google Scholar
- François Pottier. 2016. Reachability and error diagnosis in LR(1) parsers. In Proceedings of the 25th International Conference on Compiler Construction (CC 2016). 88–98. Google ScholarDigital Library
- François Pottier and Yann Régis-Gianas. 2006. Towards efficient, typed LR parsers. In ACM Workshop on ML (Electronic Notes in Theoretical Computer Science), Vol. 148. 155–180. Google ScholarDigital Library
- Tim A. Wagner. 1998. Practical Algorithms for Incremental Software Development Environments. Ph.D. Dissertation. Berkeley. Google ScholarDigital Library
- Tim A. Wagner and Susan L. Graham. 1997. History-Sensitive Error Recover. IEEE Trans. on Software Engineering (1997).Google Scholar
- Tim A. Wagner and Susan L. Graham. 1998. Efficient and Flexible Incremental Parsing. ACM Trans. on Programming Languages and Systems 20, 5 (1998). Google ScholarDigital Library
Index Terms
- Merlin: a language server for OCaml (experience report)
Recommendations
Modular language implementation in Rascal - experience report
All software evolves, and programming languages and programming language tools are no exception. And just like in ordinary software construction, modular implementations can help ease the process of changing a language implementation and its dependent ...
Syntax error recovery in parsing expression grammars
SAC '18: Proceedings of the 33rd Annual ACM Symposium on Applied ComputingParsing Expression Grammars (PEGs) are a formalism used to describe top-down parsers with backtracking. As PEGs do not provide a good error recovery mechanism, PEG-based parsers usually do not recover from syntax errors in the input, or recover from ...
Language extension and composition with language workbenches
OOPSLA '10: Proceedings of the ACM international conference companion on Object oriented programming systems languages and applications companionDomain-specific languages (DSLs) provide high expressive power focused on a particular problem domain. They provide linguistic abstractions and specialized syntax specifically designed for a domain, allowing developers to avoid boilerplate code and low-...
Comments