mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
TextMate grammars can include other grammars
This commit is contained in:
@@ -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]
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user