Add initial support for injection grammars

Build scope selectors and patterns when setting up the grammar
for all entries under the grammar's injection object.

Include the injection patterns in the scanner when the injection's
scope selector matches the current rule stack.
This commit is contained in:
Kevin Sawicki
2013-04-17 18:17:15 -07:00
parent 2568aa086e
commit c2eca1ff99
3 changed files with 55 additions and 8 deletions

View File

@@ -443,3 +443,27 @@ describe "TokenizedBuffer", ->
expect(tokens[2].value).toBe '@"'
expect(tokens[2].scopes).toEqual ["source.objc++", "meta.function.c", "meta.block.c", "string.quoted.double.objc", "punctuation.definition.string.begin.objc"]
describe "when the grammar has injections", ->
beforeEach ->
atom.activatePackage('php.tmbundle', sync: true)
editSession = project.buildEditSession('hello.php', autoIndent: false)
tokenizedBuffer = editSession.displayBuffer.tokenizedBuffer
editSession.setVisible(true)
fullyTokenize(tokenizedBuffer)
afterEach ->
editSession.destroy()
it "correctly includes the injected patterns when tokenizing", ->
functionLine = tokenizedBuffer.lineForScreenRow(0)
{ tokens } = functionLine
expect(tokens[0].value).toBe "<?php"
expect(tokens[0].scopes).toEqual ["text.html.php", "meta.embedded.line.php", "punctuation.section.embedded.begin.php"]
expect(tokens[2].value).toBe "function"
expect(tokens[2].scopes).toEqual ["text.html.php", "meta.embedded.line.php", "source.php", "meta.function.php", "storage.type.function.php"]
expect(tokens[4].value).toBe "hello"
expect(tokens[4].scopes).toEqual ["text.html.php", "meta.embedded.line.php", "source.php", "meta.function.php", "entity.name.function.php"]

1
spec/fixtures/hello.php vendored Normal file
View File

@@ -0,0 +1 @@
<?php function hello() {} ?>