mirror of
https://github.com/atom/atom.git
synced 2026-02-03 19:25:06 -05:00
Parse nested snippet placeholders
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user