Skip to content

Commit

Permalink
parse: fix issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Nov 21, 2017
1 parent 006f26d commit 9163442
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion parse/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func lexSubstitution(l *lexer) stateFn {
case '+':
l.emit(itemColonPlus)
default:
return l.errorf("expected '-', '=' or '+' after ':'")
l.emit(itemText)
}
default:
l.emit(itemText)
Expand Down
12 changes: 9 additions & 3 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@ Loop:
defaultNode = NewVariable(strings.TrimPrefix(t.val, "$"), p.Env)
case itemText:
n := NewText(t.val)
// patch to accept all kind of chars
for p.peek().typ != itemRightDelim {
n.Text += p.next().val
Text:
for {
switch p.peek().typ {
case itemRightDelim, itemError, itemEOF:
break Text
default:
// patch to accept all kind of chars
n.Text += p.next().val
}
}
defaultNode = n
default:
Expand Down
2 changes: 1 addition & 1 deletion parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var parseTests = []parseTest{
{"multi line string", "hello $BAR\nhello ${EMPTY:=$FOO}", "hello bar\nhello foo", errNone},
{"issue #1", "${hello:=wo_rld} ${foo:=bar_baz}", "wo_rld bar_baz", errNone},
{"issue #2", "name: ${NAME:=foo_qux}, key: ${EMPTY:=baz_bar}", "name: foo_qux, key: baz_bar", errNone},
{"gh-issue-8", "prop=${HOME_URL-http://localhost:8080}", "prop=http://localhost:8080", errNone},
// bad substitution
{"closing brace expected", "hello ${", "", errAll},

Expand Down Expand Up @@ -95,7 +96,6 @@ var parseTests = []parseTest{
{"$var and $DEFAULT empty :=", "${EMPTY:=$ALSO_EMPTY}", "", errEmpty},
{"$var and $OTHER empty +", "${EMPTY+$ALSO_EMPTY}", "", errEmpty},
{"$var and $OTHER empty :+", "${EMPTY:+$ALSO_EMPTY}", "", errEmpty},
//
}

func TestParse(t *testing.T) {
Expand Down

0 comments on commit 9163442

Please sign in to comment.