Custom Parser Starting Point

I have domain specific language I wish to design a custom parser for, but I’m a bit lost on where to start with the new product. Is there a starting point example of basic documentation that walks through the key pieces that must be implemented to make a custom parser?

Hi,

It depends on what you need to achieve with your custom parser.

If you need custom highlighting only, this can be implemented using our generic or TextMate parsers.
If you need to provide advanced editing features, such as syntax/semantic parsing, error highlighting, etc., you would either need to use one of our advanced or Language Server Protocol parsers or implement a custom parser from scratch.

You may find the following blogs useful:

Creating a generic parser is covered in our documentation:
https://docs.alternetsoft.com/introduction/code-editor/syntax-parsing/syntax-parsing.html

TextMate parsers cover a vast subset of programming languages. However, creating one’s own grammar is not an easy task.

Implementing advanced parsers, such as XML parser, is non-trivial and not covered by the documentation. We’re happy to provide source code for this parser so you can look at how it’s implemented.

If you provide more information on the language you’d like to implement parsing for, I can give you a more detailed answer.

Kind regards,
Dmitry

Thank you, this is all very helpful. I dusted off an old SyntaxParser implementation I did from the QWhale days and comparing that to the newer source, it looks to be just as relevant now. The language I’m trying to build the parser for is called AL. It’s a DSL used in a corporate ERP software that was called Navision, that was then bought by Microsoft and rebranded multiple times. I do have a textmate grammar file they published, that they use in VS Code (which is their new editor of choice in the latest iteration). The current name of the product is Dynamics 365 Business Central. While I do like VS Code, it really kind of sucks developing for their environment using a text editor, so I was looking into building my own IDE with full syntax highlighting, code completion and refactoring tools. In the short term I can use the TextMate support while I work on something more robust and targeted. I’m assuming the typical approach is to inherit from the SyntaxParser class? I’m slowing reading through source in the latest version of the tools to try to familiarize myself. I just didn’t know if there was a basic readme somewhere the went over the most common things that had to be implemented in a SyntaxParser class when building a custom parser.
Their current language tooling for AL leaves much to be desired. The current approach to a rename refactoring is find/replace.

Hi,

Sorry for the late reply. Somehow, we missed your post.

As I wrote above, implementing a custom parser that supports syntax and semantic analysis (which would be needed for code completion and code refactoring) is not a trivial task. Yes, it will need to be inherited from SyntaxParser, and most of the methods declared there will need to be implemented.

We’re happy to send you a source of our hand-written Python parser. For Python, we could not find any non-Language server protocol-based implementations, so we wrote our own. It performs syntax and semantic analysis but does not provide code refactoring capabilities.

Should you be interested please drop me an email at dmitry.medvedev@alternetsoft.com

Kind regards,
Dmitry

Yes, thank you, that would be great :smile:

I’ve just sent an email to you with the link to the source code.

Kind regards,
Dmitry

I must be missing something, I can’t seem to find a Python parser in the source among all the parsers. Could you point me to the class. I have tried text searching and see references to the word Python, but no syntax parser class that I find. I’m sure I’m just looking right past it.

Hi,

In the sources we’ve sent you, please look at

Parsers\Python\Classes\PythonParser.cs

Kind regards,
Dmtiry

Ok, thank you so much, I figured I was just failing to see what was in front of me haha.

1 Like