Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions parse/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
itemColonEquals // colon-equals (':=')
itemColonDash // colon-dash(':-')
itemColonPlus // colon-plus(':+')
itemIgnored // double dollar ('$$') variable should be ignored
itemVariable // variable starting with '$', such as '$hello' or '$1'
itemLeftDelim // left action delimiter '${'
itemRightDelim // right action delimiter '}'
Expand Down Expand Up @@ -194,6 +195,9 @@ func lexVariable(l *lexer) stateFn {
var r rune
for {
r = l.next()
if r == '$' {
l.emit(itemIgnored)
}
if !isAlphaNumeric(r) {
l.backup()
break
Expand Down
9 changes: 9 additions & 0 deletions parse/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ var lexTests = []lexTest{
{itemVariable, 0, "$world"},
tEOF,
}},
{"ignored var", "$$hello", []item{
{itemIgnored, 0, "$$hello"},
tEOF,
}},
{"2 ignored vars", "$$hello$$world", []item{
{itemIgnored, 0, "$$hello"},
{itemIgnored, 0, "$$world"},
tEOF,
}},
{"substitution-1", "bar ${BAR}", []item{
{itemText, 0, "bar "},
tLeft,
Expand Down
3 changes: 3 additions & 0 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ Loop:
continue
}
fallthrough
case itemIgnored:
textNode := NewText(strings.TrimPrefix(t.val, "$"))
p.nodes = append(p.nodes, textNode)
default:
textNode := NewText(t.val)
p.nodes = append(p.nodes, textNode)
Expand Down
2 changes: 2 additions & 0 deletions parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ var parseTests = []parseTest{
{"with text", "$BAR baz", "bar baz", errNone},
{"concatenated", "$BAR$FOO", "barfoo", errNone},
{"2 env var", "$BAR - $FOO", "bar - foo", errNone},
{"ignored var", "$$BAR - $$FOO", "$BAR - $FOO", errNone},
{"2 ignored vars", "$BAR - $FOO", "$BAR - $FOO", errNone},
{"invalid var", "$_ bar", "$_ bar", errNone},
{"invalid subst var", "${_} bar", "${_} bar", errNone},
{"value of $var", "${BAR}baz", "barbaz", errNone},
Expand Down