mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Support packages with CSON grammars
This commit is contained in:
parent
4619e1847f
commit
75a9bce848
@ -1,4 +1,5 @@
|
||||
TextMateGrammar = require 'text-mate-grammar'
|
||||
TextMatePackage = require 'text-mate-package'
|
||||
plist = require 'plist'
|
||||
fs = require 'fs'
|
||||
_ = require 'underscore'
|
||||
@ -257,3 +258,14 @@ describe "TextMateGrammar", ->
|
||||
{tokens, ruleStack} = grammar.tokenizeLine("if(1){if(1){m()}}")
|
||||
expect(tokens[5]).toEqual value: "if", scopes: ["source.c", "meta.block.c", "keyword.control.c"]
|
||||
expect(tokens[10]).toEqual value: "m", scopes: ["source.c", "meta.block.c", "meta.block.c", "meta.function-call.c", "support.function.any-method.c"]
|
||||
|
||||
describe "when the grammar is CSON", ->
|
||||
it "loads the grammar and correctly parses a keyword", ->
|
||||
spyOn(syntax, 'addGrammar')
|
||||
pack = new TextMatePackage(fixturesProject.resolve("packages/package-with-a-cson-grammar.tmbundle"))
|
||||
pack.load()
|
||||
grammar = pack.grammars[0]
|
||||
expect(grammar).toBeTruthy()
|
||||
expect(grammar.scopeName).toBe "source.alot"
|
||||
{tokens, ruleStack} = grammar.tokenizeLine("this is alot of code")
|
||||
expect(tokens[1]).toEqual value: "alot", scopes: ["source.alot", "keyword.alot"]
|
||||
|
11
spec/fixtures/packages/package-with-a-cson-grammar.tmbundle/Syntaxes/alot.cson
vendored
Normal file
11
spec/fixtures/packages/package-with-a-cson-grammar.tmbundle/Syntaxes/alot.cson
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
'fileTypes': ['alot']
|
||||
'name': 'Alot'
|
||||
'scopeName': 'source.alot'
|
||||
'patterns': [
|
||||
{
|
||||
'captures':
|
||||
'0':
|
||||
'name': 'keyword.alot'
|
||||
'match': 'alot'
|
||||
}
|
||||
]
|
@ -9,9 +9,12 @@ module.exports =
|
||||
class TextMateGrammar
|
||||
@readFromPath: (path) ->
|
||||
grammarContent = null
|
||||
plist.parseString fs.read(path), (e, data) ->
|
||||
throw new Error(e) if e
|
||||
grammarContent = data[0]
|
||||
if fs.extension(path) is '.cson'
|
||||
grammarContent = fs.readObject(path)
|
||||
else
|
||||
plist.parseString fs.read(path), (e, data) ->
|
||||
throw new Error(e) if e
|
||||
grammarContent = data[0]
|
||||
throw new Error("Failed to load grammar at path `#{path}`") unless grammarContent
|
||||
grammarContent
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user