support heredoc identifiers with numbers

fixes https://github.com/hashicorp/terraform/issues/4079
This commit is contained in:
Paul Hinze 2015-12-01 10:22:31 -06:00
parent 8a65681ce2
commit e2c26b8e6f
2 changed files with 4 additions and 3 deletions

View File

@ -389,7 +389,7 @@ func (s *Scanner) scanHeredoc() {
// Scan the identifier
ch := s.next()
for isLetter(ch) {
for isLetter(ch) || isDigit(ch) {
ch = s.next()
}
@ -571,12 +571,12 @@ func isLetter(ch rune) bool {
return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= 0x80 && unicode.IsLetter(ch)
}
// isHexadecimal returns true if the given rune is a decimal digit
// isDigit returns true if the given rune is a decimal digit
func isDigit(ch rune) bool {
return '0' <= ch && ch <= '9' || ch >= 0x80 && unicode.IsDigit(ch)
}
// isHexadecimal returns true if the given rune is a decimal number
// isDecimal returns true if the given rune is a decimal number
func isDecimal(ch rune) bool {
return '0' <= ch && ch <= '9'
}

View File

@ -73,6 +73,7 @@ var tokenLists = map[string][]tokenPair{
},
"heredoc": []tokenPair{
{token.HEREDOC, "<<EOF\nhello\nworld\nEOF"},
{token.HEREDOC, "<<EOF123\nhello\nworld\nEOF123"},
},
"string": []tokenPair{
{token.STRING, `" "`},