hcl/scanner: scan interpolations properly

This commit is contained in:
Mitchell Hashimoto 2015-11-06 17:55:07 -08:00
parent 96291d2dbe
commit 22bdcc2db1
2 changed files with 14 additions and 1 deletions

View File

@ -375,6 +375,7 @@ func (s *Scanner) scanExponent(ch rune) rune {
// scanString scans a quoted string
func (s *Scanner) scanString() {
braces := 0
for {
// '"' opening already consumed
// read character after quote
@ -385,10 +386,21 @@ func (s *Scanner) scanString() {
return
}
if ch == '"' {
if ch == '"' && braces == 0 {
break
}
// If we're going into a ${} then we can ignore quotes for awhile
if braces == 0 && ch == '$' && s.peek() == '{' {
braces++
s.next()
} else if braces > 0 && ch == '{' {
braces++
}
if braces > 0 && ch == '}' {
braces--
}
if ch == '\\' {
s.scanEscape()
}

View File

@ -74,6 +74,7 @@ var tokenLists = map[string][]tokenPair{
{token.STRING, `" "`},
{token.STRING, `"a"`},
{token.STRING, `"本"`},
{token.STRING, `"${file("foo")}"`},
{token.STRING, `"\a"`},
{token.STRING, `"\b"`},
{token.STRING, `"\f"`},