-
Notifications
You must be signed in to change notification settings - Fork 0
Description
The following:
let g: TextMateGrammar = {
name: 'A',
extensions: [],
modes: [
cat(CARDINALITY, rep0(Space), SEP, rep0(Space), cardinalityValue, rep0(Space), DOTDOT, rep0(Space), cardinalityValue),
]
}Generates this JSON:
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "A",
"scopeName": "source.a",
"fileTypes": [],
"patterns": [
{
"match": "(@Cardinality\\b)\\s*(:)\\s*(?:([0-9]+(?:\\.[0-9]+)?)|(\\*))\\s*(\\.\\.)\\s*(?:([0-9]+(?:\\.[0-9]+)?)|(\\*))",
"captures": {
"1": {
"name": "keyword.other.class.a"
},
"2": {
"name": "punctuation.a"
},
"5": {
"name": "punctuation.a"
},
"6": {
"name": "constant.numeric.a"
},
"7": {
"name": "constant.numeric.a"
}
}
}
]
}Which is incorrect, one of the captures is missing its scope. This is likely because of reusing patterns (cardinalityValue in this case). The likely wrong component is, TagPattern, which blindly overwrites tag values under the same key. Instead, it should likely merge the tags. The extendMap call should be replaced with something more appropriate, that merges tag lists.
The other (maybe even more) likely candidate is the fact that tag creates a capture at construction, not at regex-generation. This is super problematic, as the capture will be reused. The if (!(this.element instanceof CapturePattern)) throw new Error('Tagging requires an underlying capture'); should be removed and wrapping should happen there instead.
Most likely: captures should map to a list of indices instead of one index, since a capture can appear multiple places.