Fix how repositories work in TextMate grammars

Previously, we treated all grammar repositories as rules, but some
grammars have repositories that are a single pattern. If it is a single
pattern, transform it into a rule with one pattern.

Fix how repositories work in TextMate grammars

Previously, we treated all grammar repositories as rules, but some grammars have repositories that are a single pattern. If it is a single pattern, transform it into a rule with one pattern.
This commit is contained in:
Corey Johnson
2012-11-07 16:18:05 -08:00
parent 608b7ee9e1
commit 00a26ae4da
2 changed files with 27 additions and 20 deletions

View File

@@ -26,6 +26,7 @@ class TextMateGrammar
@firstLineRegex = new OnigRegExp(firstLineMatch) if firstLineMatch
for name, data of repository
data = {patterns: [data], tempName: name} if data.begin? or data.match?
@repository[name] = new Rule(this, data)
tokenizeLine: (line, {ruleStack, tabLength}={}) ->
@@ -111,7 +112,6 @@ class Rule
# Add a `\n` to appease patterns that contain '\n' explicitly
return null unless result = @getScanner().findNextMatch(line + "\n", position)
{ index, captureIndices } = result
# Since the `\n' (added above) is not part of the line, truncate captures to the line's actual length
lineLength = line.length
captureIndices = captureIndices.map (value, index) ->