diff --git a/spec/app/text-mate-grammar-spec.coffee b/spec/app/text-mate-grammar-spec.coffee
index a2e350c31..a6bfa90ee 100644
--- a/spec/app/text-mate-grammar-spec.coffee
+++ b/spec/app/text-mate-grammar-spec.coffee
@@ -190,3 +190,30 @@ describe "TextMateGrammar", ->
expect(tokens[9]).toEqual value: ' ', scopes: ["source.ruby"]
expect(tokens[10]).toEqual value: '#', scopes: ["source.ruby","comment.line.number-sign.ruby","punctuation.definition.comment.ruby"]
expect(tokens[11]).toEqual value: ' damn.', scopes: ["source.ruby","comment.line.number-sign.ruby"]
+
+ describe "when the pattern includes rules from another grammar", ->
+ it "parses tokens inside the begin/end patterns based on the included grammar's rules", ->
+ grammar = TextMateBundle.grammarsByFileType["html.erb"]
+ {tokens} = grammar.getLineTokens("
<%= User.find(2).full_name %>
")
+
+ expect(tokens[0]).toEqual value: '<', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.begin.html"]
+ expect(tokens[1]).toEqual value: 'div', scopes: ["text.html.ruby","meta.tag.block.any.html","entity.name.tag.block.any.html"]
+ expect(tokens[2]).toEqual value: ' class=', scopes: ["text.html.ruby","meta.tag.block.any.html"]
+ expect(tokens[3]).toEqual value: '\'', scopes: ["text.html.ruby","meta.tag.block.any.html","string.quoted.single.html","punctuation.definition.string.begin.html"]
+ expect(tokens[4]).toEqual value: 'name', scopes: ["text.html.ruby","meta.tag.block.any.html","string.quoted.single.html"]
+ expect(tokens[5]).toEqual value: '\'', scopes: ["text.html.ruby","meta.tag.block.any.html","string.quoted.single.html","punctuation.definition.string.end.html"]
+ expect(tokens[6]).toEqual value: '>', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.end.html"]
+ expect(tokens[7]).toEqual value: '<%=', scopes: ["text.html.ruby","source.ruby.rails.embedded.html","punctuation.section.embedded.ruby"]
+ expect(tokens[8]).toEqual value: ' ', scopes: ["text.html.ruby","source.ruby.rails.embedded.html"]
+ expect(tokens[9]).toEqual value: 'User', scopes: ["text.html.ruby","source.ruby.rails.embedded.html","support.class.ruby"]
+ expect(tokens[10]).toEqual value: '.', scopes: ["text.html.ruby","source.ruby.rails.embedded.html","punctuation.separator.method.ruby"]
+ expect(tokens[11]).toEqual value: 'find', scopes: ["text.html.ruby","source.ruby.rails.embedded.html"]
+ expect(tokens[12]).toEqual value: '(', scopes: ["text.html.ruby","source.ruby.rails.embedded.html","punctuation.section.function.ruby"]
+ expect(tokens[13]).toEqual value: '2', scopes: ["text.html.ruby","source.ruby.rails.embedded.html","constant.numeric.ruby"]
+ expect(tokens[14]).toEqual value: ')', scopes: ["text.html.ruby","source.ruby.rails.embedded.html","punctuation.section.function.ruby"]
+ expect(tokens[15]).toEqual value: '.', scopes: ["text.html.ruby","source.ruby.rails.embedded.html","punctuation.separator.method.ruby"]
+ expect(tokens[16]).toEqual value: 'full_name ', scopes: ["text.html.ruby","source.ruby.rails.embedded.html"]
+ expect(tokens[17]).toEqual value: '%>', scopes: ["text.html.ruby","source.ruby.rails.embedded.html","punctuation.section.embedded.ruby"]
+ expect(tokens[18]).toEqual value: '', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.begin.html"]
+ expect(tokens[19]).toEqual value: 'div', scopes: ["text.html.ruby","meta.tag.block.any.html","entity.name.tag.block.any.html"]
+ expect(tokens[20]).toEqual value: '>', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.end.html"]
diff --git a/src/app/text-mate-bundle.coffee b/src/app/text-mate-bundle.coffee
index 5cb713b59..6bdc04aa6 100644
--- a/src/app/text-mate-bundle.coffee
+++ b/src/app/text-mate-bundle.coffee
@@ -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]
diff --git a/src/app/text-mate-grammar.coffee b/src/app/text-mate-grammar.coffee
index dd4d7a46a..601acf259 100644
--- a/src/app/text-mate-grammar.coffee
+++ b/src/app/text-mate-grammar.coffee
@@ -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