Skip to content

Commit

Permalink
Simplify literal rule
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav committed Apr 4, 2017
1 parent f11439b commit d43392f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
36 changes: 18 additions & 18 deletions internal/interpolate/parse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions internal/interpolate/parse.rl
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,25 @@ func Parse(data string) (out String, _ error) {
var_default
= (any - '}')* >start @{ v.Default = data[idx:fpc+1] };

var = '${' var_name (':' @{ v.HasDefault = true } var_default)? '}';
# Reference to a variable with an optional default value.
var = '${' var_name (':' @{ v.HasDefault = true } var_default)? '}'
;

# Anything followed by a '\' is used as-is.
escaped_lit = '\\' any @{ l = literal(data[fpc:fpc+1]) };

# Anything followed by a '$' that is not a '{'.
dollar_lit = '$' (any - '{') @{ l = literal(data[fpc-1:fpc+1]) };

lit = ('\\' any @{ l = literal(data[fpc:fpc+1]) })
| ('$' (any - '{') @{ l = literal(data[fpc-1:fpc+1]) })
| ((any - [\$\\])+ >start @{ l = literal(data[idx:fpc + 1]) })
# Literal strings that don't contain '$' or '\'.
simple_lit
= (any - '$' - '\\')+
>start
@{ l = literal(data[idx:fpc + 1]) }
;

lit = escaped_lit | dollar_lit | simple_lit;

term = (var @{ t = v }) | (lit @{ t = l });

main := (term %{ out = append(out, t) })**;
Expand Down

0 comments on commit d43392f

Please sign in to comment.