The syntax definition for Wolfram Language is very complicated. It is hard to write such a big JSON file with expansibility and maintainability, so I use YAML to define all the syntaxes and use some special tags to simplify the writing process. This page will tell you how the extended schema works.
All the source files can be found under directory build/types.
Every tag has its own environment and parameter type. In this schema, there are 4 environments and 3 parameter types.
- regex: used under
match
,begin
andend
. - capture: used under
captures
,beginCaptures
andendCaptures
. - rule: used as a wrapper of a rule under a list of patterns.
- context: used under
patterns
or as the root of a context.
- scalar: parameters are written in a line separated by whitespaces after the tag name.
- sequence: parameters are witten in a list under the tag name.
- mapping: parameters are witten in an object under the tag name.
There are some basic types in the schema. These types are all very simple and easy to use. src/syntaxes/simplest.yaml only uses tags from this category so it may serves as a perfect example of how to use these tags.
(capture/mapping) It traverses all the captures and turn every string value into objects. For example:
endCaptures: !raw
1: '#function-identifier'
2: keyword.operator.call.wolfram
will be transpiled into
{
"endCaptures": {
"1": { "patterns": [{ "include": "#function-identifier" }] },
"2": { "name": "keyword.operator.call.wolfram" }
}
}
(capture/scalar) It turns the parameter into the only capture of the regex. For Example:
beginCaptures: !all keyword.operator.call.wolfram
will be transpiled into
{
"beginCaptures": {
"0": { "name": "keyword.operator.call.wolfram" }
}
}
(context/scalar) It turns the parameter into the only rule of the context. The parameter will serves as the include target. For Example:
patterns: !push expressions
will be transpiled into
{
"patterns": [{ "include": "#expressions" }]
}
(rule/scalar) It generates a rule for bracketing by the name of bracket given by the parameter. For Example:
- !bracket association
will be transpiled into
[{
"begin": "<\\|",
"beginCaptures": {
"0": { "name": "punctuation.section.association.begin.wolfram" }
},
"end": "\\|>",
"endCaptures": {
"0": { "name": "punctuation.section.association.end.wolfram" }
},
"name": "meta.association.wolfram",
"patterns": [{ "include": "#expressions" }]
}]
See type inference.