diff --git a/node/scalar/t_encapsed_test.go b/node/scalar/t_encapsed_test.go index 5fb3745..b4500db 100644 --- a/node/scalar/t_encapsed_test.go +++ b/node/scalar/t_encapsed_test.go @@ -36,6 +36,29 @@ func TestSimpleVar(t *testing.T) { assertEqual(t, expected, actual) } +func TestSimpleVarOneChar(t *testing.T) { + src := `bar()";` diff --git a/scanner/scanner.go b/scanner/scanner.go index 7e8ed25..32be3b4 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -31,6 +31,10 @@ const ( var heredocLabel []lex.Char +func isValidFirstVarNameRune(r rune) bool { + return r >= 'A' && r <= 'Z' || r == '_' || r >= 'a' && r <= 'z' || r >= '\u007f' && r <= 'ÿ' +} + func (l *Lexer) Lex(lval Lval) int { l.Comments = nil c := l.Enter() @@ -8627,7 +8631,7 @@ yyrule149: // .|[ \t\n\r] switch l.Prev.Rune { case '$': c = l.Next() - if l.Prev.Rune == '{' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ' { + if l.Prev.Rune == '{' || isValidFirstVarNameRune(l.Prev.Rune) { l.ungetChars(2) tb := l.Token() lval.Token(l.newToken(tb[:len(tb)-2])) diff --git a/scanner/scanner.l b/scanner/scanner.l index 855b85a..8666d72 100644 --- a/scanner/scanner.l +++ b/scanner/scanner.l @@ -30,6 +30,10 @@ const ( var heredocLabel []lex.Char +func isValidFirstVarNameRune(r rune) bool { + return r >= 'A' && r <= 'Z' || r == '_' || r >= 'a' && r <= 'z' || r >= '\u007f' && r <= 'ÿ' +} + func (l *Lexer) Lex(lval Lval) int { l.Comments = nil c := l.Enter() @@ -451,7 +455,7 @@ NEW_LINE (\r|\n|\r\n) switch l.Prev.Rune { case '$': c = l.Next(); - if l.Prev.Rune == '{' || c >= 'A' && c <= 'Z' || c == '_' || c >= 'a' && c <= 'z' || c >= '\u007f' && c <= 'ÿ' { + if l.Prev.Rune == '{' || isValidFirstVarNameRune(l.Prev.Rune) { l.ungetChars(2) tb := l.Token() lval.Token(l.newToken(tb[:len(tb)-2])); diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index 51b3e0d..bf9acd2 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -427,6 +427,10 @@ func TestTokens(t *testing.T) { func TestTeplateStringTokens(t *testing.T) { src := `