mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 23:48:05 +03:00
Eliminate syntax.grammarsByFileType hash
This commit is contained in:
parent
05d6adc6c7
commit
16b53d3183
@ -138,7 +138,7 @@ describe "TextMateGrammar", ->
|
|||||||
|
|
||||||
describe "when the line matches a pattern with no `name` or `contentName`", ->
|
describe "when the line matches a pattern with no `name` or `contentName`", ->
|
||||||
it "creates tokens without adding a new scope", ->
|
it "creates tokens without adding a new scope", ->
|
||||||
grammar = syntax.grammarsByFileType["rb"]
|
grammar = syntax.selectGrammar('foo.rb')
|
||||||
{tokens} = grammar.tokenizeLine('%w|oh \\look|')
|
{tokens} = grammar.tokenizeLine('%w|oh \\look|')
|
||||||
expect(tokens.length).toBe 5
|
expect(tokens.length).toBe 5
|
||||||
expect(tokens[0]).toEqual value: '%w|', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby", "punctuation.definition.string.begin.ruby"]
|
expect(tokens[0]).toEqual value: '%w|', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby", "punctuation.definition.string.begin.ruby"]
|
||||||
@ -183,7 +183,7 @@ describe "TextMateGrammar", ->
|
|||||||
|
|
||||||
describe "when the end pattern contains a back reference", ->
|
describe "when the end pattern contains a back reference", ->
|
||||||
it "constructs the end rule based on its back-references to captures in the begin rule", ->
|
it "constructs the end rule based on its back-references to captures in the begin rule", ->
|
||||||
grammar = syntax.grammarsByFileType["rb"]
|
grammar = syntax.selectGrammar('foo.rb')
|
||||||
{tokens} = grammar.tokenizeLine('%w|oh|,')
|
{tokens} = grammar.tokenizeLine('%w|oh|,')
|
||||||
expect(tokens.length).toBe 4
|
expect(tokens.length).toBe 4
|
||||||
expect(tokens[0]).toEqual value: '%w|', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby", "punctuation.definition.string.begin.ruby"]
|
expect(tokens[0]).toEqual value: '%w|', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby", "punctuation.definition.string.begin.ruby"]
|
||||||
@ -192,7 +192,7 @@ describe "TextMateGrammar", ->
|
|||||||
expect(tokens[3]).toEqual value: ',', scopes: ["source.ruby", "punctuation.separator.object.ruby"]
|
expect(tokens[3]).toEqual value: ',', scopes: ["source.ruby", "punctuation.separator.object.ruby"]
|
||||||
|
|
||||||
it "allows the rule containing that end pattern to be pushed to the stack multiple times", ->
|
it "allows the rule containing that end pattern to be pushed to the stack multiple times", ->
|
||||||
grammar = syntax.grammarsByFileType["rb"]
|
grammar = syntax.selectGrammar('foo.rb')
|
||||||
{tokens} = grammar.tokenizeLine('%Q+matz had some #{%Q-crazy ideas-} for ruby syntax+ # damn.')
|
{tokens} = grammar.tokenizeLine('%Q+matz had some #{%Q-crazy ideas-} for ruby syntax+ # damn.')
|
||||||
expect(tokens[0]).toEqual value: '%Q+', scopes: ["source.ruby","string.quoted.other.literal.upper.ruby","punctuation.definition.string.begin.ruby"]
|
expect(tokens[0]).toEqual value: '%Q+', scopes: ["source.ruby","string.quoted.other.literal.upper.ruby","punctuation.definition.string.begin.ruby"]
|
||||||
expect(tokens[1]).toEqual value: 'matz had some ', scopes: ["source.ruby","string.quoted.other.literal.upper.ruby"]
|
expect(tokens[1]).toEqual value: 'matz had some ', scopes: ["source.ruby","string.quoted.other.literal.upper.ruby"]
|
||||||
@ -212,7 +212,7 @@ describe "TextMateGrammar", ->
|
|||||||
atom.activatePackage('html.tmbundle', sync: true)
|
atom.activatePackage('html.tmbundle', sync: true)
|
||||||
atom.activatePackage('ruby-on-rails-tmbundle', sync: true)
|
atom.activatePackage('ruby-on-rails-tmbundle', sync: true)
|
||||||
|
|
||||||
grammar = syntax.grammarsByFileType["html.erb"]
|
grammar = syntax.selectGrammar('foo.html.erb')
|
||||||
{tokens} = grammar.tokenizeLine("<div class='name'><%= User.find(2).full_name %></div>")
|
{tokens} = grammar.tokenizeLine("<div class='name'><%= User.find(2).full_name %></div>")
|
||||||
|
|
||||||
expect(tokens[0]).toEqual value: '<', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.begin.html"]
|
expect(tokens[0]).toEqual value: '<', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.begin.html"]
|
||||||
|
@ -18,7 +18,6 @@ class Syntax
|
|||||||
constructor: ->
|
constructor: ->
|
||||||
@nullGrammar = new NullGrammar
|
@nullGrammar = new NullGrammar
|
||||||
@grammars = [@nullGrammar]
|
@grammars = [@nullGrammar]
|
||||||
@grammarsByFileType = {}
|
|
||||||
@grammarsByScopeName = {}
|
@grammarsByScopeName = {}
|
||||||
@grammarOverridesByPath = {}
|
@grammarOverridesByPath = {}
|
||||||
@scopedPropertiesIndex = 0
|
@scopedPropertiesIndex = 0
|
||||||
@ -29,14 +28,11 @@ class Syntax
|
|||||||
|
|
||||||
addGrammar: (grammar) ->
|
addGrammar: (grammar) ->
|
||||||
@grammars.push(grammar)
|
@grammars.push(grammar)
|
||||||
@grammarsByFileType[fileType] = grammar for fileType in grammar.fileTypes
|
|
||||||
@grammarsByScopeName[grammar.scopeName] = grammar
|
@grammarsByScopeName[grammar.scopeName] = grammar
|
||||||
|
|
||||||
removeGrammar: (grammar) ->
|
removeGrammar: (grammar) ->
|
||||||
if _.include(@grammars, grammar)
|
_.remove(@grammars, grammar)
|
||||||
_.remove(@grammars, grammar)
|
delete @grammarsByScopeName[grammar.scopeName]
|
||||||
delete @grammarsByFileType[fileType] for fileType in grammar.fileTypes
|
|
||||||
delete @grammarsByScopeName[grammar.scopeName]
|
|
||||||
|
|
||||||
setGrammarOverrideForPath: (path, scopeName) ->
|
setGrammarOverrideForPath: (path, scopeName) ->
|
||||||
@grammarOverridesByPath[path] = scopeName
|
@grammarOverridesByPath[path] = scopeName
|
||||||
|
Loading…
Reference in New Issue
Block a user