Expressions: support ${my var} syntax (#29819)

This commit is contained in:
Kyle Brandt
2020-12-14 14:21:16 -05:00
committed by GitHub
parent e7447c5067
commit c6b11a8f90
4 changed files with 38 additions and 7 deletions
+21 -4
View File
@@ -288,9 +288,29 @@ func lexFunc(l *lexer) stateFn {
func lexVar(l *lexer) stateFn {
hasChar := false
if l.peek() == '{' {
_ = l.next()
for {
switch r := l.next(); {
case r == '}':
if !hasChar {
return l.errorf("incomplete variable")
}
l.emit(itemVar)
return lexItem
case r == eof:
return l.errorf("unterminated variable missing closing }")
case isVarchar(r) || isSpace(r):
hasChar = true
default:
return l.errorf("unsupported variable character")
}
}
}
for {
switch r := l.next(); {
case unicode.IsLetter(r):
case isVarchar(r):
hasChar = true
// absorb
default:
@@ -321,9 +341,6 @@ func isSpace(r rune) bool {
return unicode.IsSpace(r)
}
// isVarchar should maybe be used in place of unicode is letter above,
// but do not want to modify it at this time, so adding lint exception.
// nolint:unused,deadcode
func isVarchar(r rune) bool {
return r == '_' || unicode.IsLetter(r) || unicode.IsDigit(r)
}