Expressions: support ${my var} syntax (#29819)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user