lark-parser/lark

Using lark for a language server

Open

#684 opened on Sep 7, 2020

View on GitHub
 (22 comments) (1 reaction) (0 assignees)Python (4,275 stars) (384 forks)batch import
discussionenhancementhelp wanted

Description

Hey, I'm wondering how conducive lark would be for creating a language server implementation for a given DSL.

For some background:

  • I have a custom DSL I'm using to describe device interfaces and then using jinja2 to generate the specific interface into the target language
  • The main implementation of this obviously in Python
  • I'm using antlr4 to define the grammar, which is used to generate a python and typescript implementations.
  • I have written a basic language server extension for vscode in typescript using the antlr completion engine antlr4-c3. This provides live validation and auto-completion which is really useful.

Problems:

  • Antlr's python implementation is quite slow (~350ms to parse + transform a sample file compared to ~50ms with lark)
  • I'm having to duplicate a lot of work between python & typescript, though admittedly they are solving slightly different problems.

I would quite like to use to Lark and implement the language server as part of the main python package if possible.

I realize a language sever requires some specific parser features namely:

  • Error tolerance: This can partly be resolved by making the grammar itself more error tolerant and solving those errors later. I notice lark also an error puppet which can maybe be used for this purpose.
  • Support for auto completion information: Its is namely done by parsing an incomplete source file up to the current caret position and extracting both the next possible tokens and the currently parser rule context from the parser. This can be combined with info from the last successful parse to produce auto completion options.

I'm wondering if lark as any support for these features? And If so how I might go about implementing them?

If something like this is possible, it might also be cool to write a language server for the lark grammar itself to aid development.

Cheers, Rob

Contributor guide

Using lark for a language server · lark-parser/lark#684 | Good First Issue