@@ -59,15 +59,16 @@ type stateFn func(*lexer) stateFn
5959
6060// lexer holds the state of the scanner
6161type lexer struct {
62- input string // the string being lexed
63- state stateFn // the next lexing function to enter
64- pos Pos // current position in the input
65- start Pos // start position of this item
66- width Pos // width of last rune read from input
67- lastPos Pos // position of most recent item returned by nextItem
68- items chan item // channel of lexed items
69- subsDepth int // depth of substitution
70- noDigit bool // if the lexer skips variables that start with a digit
62+ input string // the string being lexed
63+ state stateFn // the next lexing function to enter
64+ pos Pos // current position in the input
65+ start Pos // start position of this item
66+ width Pos // width of last rune read from input
67+ lastPos Pos // position of most recent item returned by nextItem
68+ items chan item // channel of lexed items
69+ subsDepth int // depth of substitution
70+ braceDepth int // depth of braces within default value
71+ noDigit bool // if the lexer skips variables that start with a digit
7172}
7273
7374// next returns the next rune in the input.
@@ -242,10 +243,18 @@ func lexSubstitutionOperator(l *lexer) stateFn {
242243// lexSubstitution scans the elements inside substitution delimiters.
243244func lexSubstitution (l * lexer ) stateFn {
244245 switch r := l .next (); {
246+ case r == '{' :
247+ l .braceDepth ++
248+ l .emit (itemText )
245249 case r == '}' :
246- l .subsDepth --
247- l .emit (itemRightDelim )
248- return lexText
250+ if l .braceDepth > 0 {
251+ l .braceDepth --
252+ l .emit (itemText )
253+ } else {
254+ l .subsDepth --
255+ l .emit (itemRightDelim )
256+ return lexText
257+ }
249258 case r == eof || isEndOfLine (r ):
250259 return l .errorf ("closing brace expected" )
251260 case isAlphaNumeric (r ) && strings .HasPrefix (l .input [l .lastPos :], "${" ):
0 commit comments