diff --git a/src/packages/snippets/snippets.pegjs b/src/packages/snippets/snippets.pegjs index aeda595bc..72ec9be48 100644 --- a/src/packages/snippets/snippets.pegjs +++ b/src/packages/snippets/snippets.pegjs @@ -1,10 +1,15 @@ -body = content:(tabStop / bodyText)* { return content; } -bodyText = text:bodyChar+ { return text.join(''); } -bodyChar = !tabStop char:. { return char; } +bodyContent = content:(tabStop / bodyContentText)* { return content; } +bodyContentText = text:bodyContentChar+ { return text.join(''); } +bodyContentChar = !tabStop char:. { return char; } + +placeholderContent = content:(tabStop / placeholderContentText)* { return content; } +placeholderContentText = text:placeholderContentChar+ { return text.join(''); } +placeholderContentChar = !tabStop char:[^}] { return char; } + tabStop = simpleTabStop / tabStopWithPlaceholder simpleTabStop = '$' index:[0-9]+ { return { index: parseInt(index), content: [] }; } -tabStopWithPlaceholder = '${' index:[0-9]+ ':' content:[^}]* '}' { - return { index: parseInt(index), content: [content.join('')] }; +tabStopWithPlaceholder = '${' index:[0-9]+ ':' content:placeholderContent '}' { + return { index: parseInt(index), content: content }; } diff --git a/src/packages/snippets/spec/snippets-spec.coffee b/src/packages/snippets/spec/snippets-spec.coffee index b8223599f..53598e1fe 100644 --- a/src/packages/snippets/spec/snippets-spec.coffee +++ b/src/packages/snippets/spec/snippets-spec.coffee @@ -216,16 +216,23 @@ describe "Snippets extension", -> describe "Snippets parser", -> it "breaks a snippet body into lines, with each line containing tab stops at the appropriate position", -> bodyTree = Snippets.parser.parse """ - go here next:($2) and finally go here:(${3:here!}) - go here first:($1) + the quick brown $1fox ${2:jumped ${3:over} + }the ${4:lazy} dog """ expect(bodyTree).toEqual [ - "go here next:(", - { index: 2, content: [] }, - ") and finally go here:(", - { index: 3, content: ["here!"] }, - ")\ngo here first:(", + "the quick brown ", { index: 1, content: [] }, - ")" + "fox ", + { + index: 2, + content: [ + "jumped ", + { index: 3, content: ["over"]}, + "\n" + ], + } + "the " + { index: 4, content: ["lazy"] }, + " dog" ]