config/lang: escaping interpolations with double dollar signs

This commit is contained in:
Mitchell Hashimoto 2015-01-12 10:59:43 -08:00
parent c15c17dfe9
commit c05d7a6acd
2 changed files with 23 additions and 3 deletions

View File

@ -299,11 +299,21 @@ func (x *parserLex) lexString(yylval *parserSymType, quoted bool) (int, bool) {
// If we hit a dollar sign, then check if we're starting
// another interpolation. If so, then we're done.
if c == '$' && x.peek() == '{' {
if c == '$' {
n := x.peek()
// If it is '{', then we're starting another interpolation
if n == '{' {
x.backup()
break
}
// If it is '$', then we're escaping a dollar sign
if n == '$' {
x.next()
}
}
if _, err := b.WriteRune(c); err != nil {
x.Error(err.Error())
return lexEOF, false

View File

@ -25,6 +25,16 @@ func TestLex(t *testing.T) {
[]int{STRING, PROGRAM_BRACKET_LEFT, IDENTIFIER, PROGRAM_BRACKET_RIGHT, lexEOF},
},
{
"foo $${bar}",
[]int{STRING, lexEOF},
},
{
"foo $$$${bar}",
[]int{STRING, lexEOF},
},
{
"foo ${\"bar\"}",
[]int{STRING, PROGRAM_BRACKET_LEFT, STRING, PROGRAM_BRACKET_RIGHT, lexEOF},