config/lang: don't see * as part of var name [GH-2046]

This commit is contained in:
Mitchell Hashimoto 2015-06-25 19:52:50 -07:00
parent a76105b0f1
commit 97d2c4a6de
3 changed files with 49 additions and 0 deletions

View File

@ -41,3 +41,7 @@ func (n *Call) Type(s Scope) (Type, error) {
return f.ReturnType, nil
}
func (n *Call) GoString() string {
return fmt.Sprintf("*%#v", *n)
}

View File

@ -192,12 +192,20 @@ func (x *parserLex) lexModeInterpolation(yylval *parserSymType) int {
func (x *parserLex) lexId(yylval *parserSymType) int {
var b bytes.Buffer
var last rune
for {
c := x.next()
if c == lexEOF {
break
}
// We only allow * after a '.' for resource splast: type.name.*.id
// Otherwise, its probably multiplication.
if c == '*' && last != '.' {
x.backup()
break
}
// If this isn't a character we want in an ID, return out.
// One day we should make this a regexp.
if c != '_' &&
@ -214,6 +222,8 @@ func (x *parserLex) lexId(yylval *parserSymType) int {
x.Error(err.Error())
return lexEOF
}
last = c
}
yylval.token = &parserToken{Value: b.String()}

View File

@ -183,6 +183,41 @@ func TestParse(t *testing.T) {
},
},
{
"foo ${var.bar*1} baz",
false,
&ast.Concat{
Posx: ast.Pos{Column: 1, Line: 1},
Exprs: []ast.Node{
&ast.LiteralNode{
Value: "foo ",
Typex: ast.TypeString,
Posx: ast.Pos{Column: 1, Line: 1},
},
&ast.Arithmetic{
Op: ast.ArithmeticOpMul,
Exprs: []ast.Node{
&ast.VariableAccess{
Name: "var.bar",
Posx: ast.Pos{Column: 7, Line: 1},
},
&ast.LiteralNode{
Value: 1,
Typex: ast.TypeInt,
Posx: ast.Pos{Column: 15, Line: 1},
},
},
Posx: ast.Pos{Column: 7, Line: 1},
},
&ast.LiteralNode{
Value: " baz",
Typex: ast.TypeString,
Posx: ast.Pos{Column: 17, Line: 1},
},
},
},
},
{
"${foo()}",
false,