TextMate grammars can include other grammars

This commit is contained in:
Nathan Sobo
2012-09-28 17:28:40 -06:00
parent 9b8a73d4ed
commit 4e49fbec72
3 changed files with 38 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ TextMateGrammar = require 'text-mate-grammar'
module.exports =
class TextMateBundle
@grammarsByFileType: {}
@grammarsByScopeName: {}
@preferencesByScopeSelector: {}
@bundles: []
@@ -28,6 +29,7 @@ class TextMateBundle
for grammar in bundle.grammars
for fileType in grammar.fileTypes
@grammarsByFileType[fileType] = grammar
@grammarsByScopeName[grammar.scopeName] = grammar
@grammarForFileName: (fileName) ->
extension = fs.extension(fileName)?[1...]
@@ -36,6 +38,9 @@ class TextMateBundle
@grammarsByFileType[extension] or @grammarsByFileType["txt"]
@grammarForScopeName: (scopeName) ->
@grammarsByScopeName[scopeName]
@getPreferenceInScope: (scopeSelector, preferenceName) ->
@preferencesByScopeSelector[scopeSelector]?[preferenceName]

View File

@@ -13,12 +13,13 @@ class TextMateGrammar
name: null
fileTypes: null
scopeName: null
foldEndRegex: null
repository: null
initialRule: null
constructor: ({ @name, @fileTypes, scopeName, patterns, repository, foldingStopMarker}) ->
@initialRule = new Rule(this, {scopeName, patterns})
constructor: ({ @name, @fileTypes, @scopeName, patterns, repository, foldingStopMarker}) ->
@initialRule = new Rule(this, {@scopeName, patterns})
@repository = {}
@foldEndRegex = new OnigRegExp(foldingStopMarker) if foldingStopMarker
@@ -62,6 +63,9 @@ class TextMateGrammar
@repository[name[1..]]
else if name == "$self"
@initialRule
else
TextMateBundle = require 'text-mate-bundle'
TextMateBundle.grammarForScopeName(name)?.initialRule
class Rule
grammar: null