Parse multiple snippets and allow any characters in snippet body

This commit is contained in:
David Graham & Nathan Sobo
2012-06-19 17:56:03 -06:00
parent 5b8cc8a6b6
commit e4409be95a
2 changed files with 18 additions and 10 deletions

View File

@@ -29,15 +29,23 @@ fdescribe "Snippets extension", ->
expect(editor.getCursorScreenPosition()).toEqual [0, 14]
describe "Snippets parser", ->
it "can parse a snippet", ->
it "can parse multiple snippets", ->
snippets = Snippets.snippetsParser.parse """
snippet te "Test snippet description"
this is a test
snippet t1 "Test snippet 1"
this is a test 1
endsnippet
snippet t2 "Test snippet 2"
this is a test 2
endsnippet
"""
expect(_.keys(snippets).length).toBe 2
snippet = snippets['t1']
expect(snippet.prefix).toBe 't1'
expect(snippet.description).toBe "Test snippet 1"
expect(snippet.body).toBe "this is a test 1"
expect(_.keys(snippets).length).toBe 1
snippet = snippets['te']
expect(snippet.prefix).toBe 'te'
expect(snippet.description).toBe "Test snippet description"
expect(snippet.body).toBe "this is a test"
snippet = snippets['t2']
expect(snippet.prefix).toBe 't2'
expect(snippet.description).toBe "Test snippet 2"
expect(snippet.body).toBe "this is a test 2"

View File

@@ -6,7 +6,7 @@ snippets = snippets:snippet+ {
return snippetsByPrefix;
}
snippet = start ws prefix:prefix ws description:string separator body:body end {
snippet = ws? start ws prefix:prefix ws description:string separator body:body end {
return { prefix: prefix, description: description, body: body };
}
@@ -14,7 +14,7 @@ separator = [ ]* '\n'
start = 'snippet'
prefix = prefix:[A-Za-z0-9_]+ { return prefix.join(''); }
body = body:bodyCharacter* { return body.join(''); }
bodyCharacter = !end char:[a-z ] { return char; }
bodyCharacter = !end char:. { return char; }
end = '\nendsnippet'
string
= ['] body:[^']* ['] { return body.join(''); }