I need to support a couple related languages that are not currently supported across all three products (editor, scripter, and forms designer), but first and foremost I need syntax highlighting and initial language support in the editor.
I understand this is a non-trivial task, but preparation in advance and some notion of the practical steps involved can help increase chance of success.
So I was wondering if there is an advanced tutorial or example available for creating a non-trivial custom parser and integrating it into the editor (and eventually the other products)? I would like some pointers about how to begin to create the abstractions I need based on core classes provided by the syntax editor framework.
Some features I need that I don’t see discussed much include auto-indenting and formatting, which are particularly important for my application. I am working with languages based on s-expressions, if that helps refine the advice.
Any code examples would be appreciated.
We do have a user guide that explains how to create own lexer scheme for your own language, please refer to Creating a new generic parser topic in the Code Editor user guide which can be found here:
It does not explain though how to create an advanced parser that would implement features like code outlining, auto-indenting, etc.
You can look at the source code of our xml parser that have both lexical and syntax analysis hard-coded here:
During syntax analysis it creates a syntax tree, some nodes in this tree have Indentation and Outlining options that tells parser how to calculate indentation level in method GetSmartIndent and outline sections in method Outline- potentially you can implement these methods without building a syntax tree.
In order to support your own language in other products (like Scripter and Form Designer), this would require a custom scripting engine which will allow to run the code in your language - if this is not something already supported, it could be a lot more difficult.
For the WinForms Form Designer in order to serialize form initialization code into your own language, you would need to implement both parser that loads code into CodeDOM and code generator, that serializes it back. We have implemented these parsers/generators for Roslyn and TypeScript and working on IronPython.
The parser in particular has to implement semantic analysis as well, as it would need to determine whether given identifier in the code is field, variable or parameter.
Hope this helps,