This Engineering Notebook post discusses adding syntax coloring for section references and Leo directives to leoInteg. It will be of interest mainly to Félix.
Background
At present, leoInteg only syntax colors Leonine syntax. In addition, we want leoInteg to color language-specif constructs.
Syntax description files drive syntax coloring in vs code. There is (probably) one such file for each language that vs code can color. Various plugins add their own syntax description files.
The
syntax of syntax description files is json. A
TextMate grammar specifies the valid
contents (semantics) of these files.
In python, parsing a json file is very easy. If "contents" is the contents of a .json file, the following parses the file:
import json
...
d = json.loads(contents)
For TextMate grammar files, d will be a top-level python dict, whose values are inner dicts, lists, strings, etc.
Please read the
TextMate grammar carefully before reading further. The documentation is good, but it took me awhile to get my head around all the details.
Merging Leo's rules into existing grammar rules
The task is to create Leonine versions of all existing syntax description files. For each existing file, we must create a new file that adds Leo's constructs. It's important to automate this process with Leo script. Let's call this script the description script.
There are, maybe, two ways forward. The description script could either copy Leonine rules into existing description files, or it could reference Leonine rules. A few experiments should tell if reference a separate (embedded) Leo language description will work. If not, the description script will copy (merge), say, leo.json into the existing language description file.
Summary
Vs code uses language description files, in json format, to drive syntax coloring. Parsing these files is easy.
A language description script will create a new, Leonine, language description file for every existing language description file. Merging Leo's syntax coloring rules into the existing description should be fairly straightforward. However, some hand tweaks may be necessary.
I am about to start work on this script. Once it works for one language, it is likely to work for most languages.
Edward