Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Handle escaped characters in tab-stop placeholder content #123

Merged
merged 2 commits into from
Apr 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/snippet-body.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bodyContent = content:(tabStop / bodyContentText)* { return content; }
bodyContentText = text:bodyContentChar+ { return text.join(''); }
bodyContentChar = escaped / !tabStop char:. { return char; }

escaped = '\\' char:[$\\] { return char; }
escaped = '\\' char:. { return char; }
tabStop = simpleTabStop / tabStopWithoutPlaceholder / tabStopWithPlaceholder
simpleTabStop = '$' index:[0-9]+ {
return { index: parseInt(index.join("")), content: [] };
Expand All @@ -15,7 +15,7 @@ tabStopWithPlaceholder = '${' index:[0-9]+ ':' content:placeholderContent '}' {
}
placeholderContent = content:(tabStop / variable / placeholderContentText)* { return content; }
placeholderContentText = text:placeholderContentChar+ { return text.join(''); }
placeholderContentChar = !tabStop !variable char:[^}] { return char; }
placeholderContentChar = escaped / !tabStop !variable char:[^}] { return char; }

variable = '${' variableContent '}' {
return ''; // we eat variables and do nothing with them for now
Expand Down
13 changes: 13 additions & 0 deletions spec/body-parser-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,16 @@ describe "Snippet Body Parser", ->
content: []
}
]

it "includes escaped right-braces", ->
bodyTree = BodyParser.parse """
snippet ${1:{\\}}
"""

expect(bodyTree).toEqual [
"snippet ",
{
index: 1,
content: ["{}"]
}
]