zclsyntax: parsing of boolean/null literals and root variable references
This commit is contained in:
parent
76d29e4031
commit
7f27d7b324
@ -36,6 +36,30 @@ func TestExpressionParseAndValue(t *testing.T) {
|
|||||||
cty.NumberIntVal(1),
|
cty.NumberIntVal(1),
|
||||||
1, // Unbalanced parentheses
|
1, // Unbalanced parentheses
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`true`,
|
||||||
|
nil,
|
||||||
|
cty.True,
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`false`,
|
||||||
|
nil,
|
||||||
|
cty.False,
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`null`,
|
||||||
|
nil,
|
||||||
|
cty.NullVal(cty.DynamicPseudoType),
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`true true`,
|
||||||
|
nil,
|
||||||
|
cty.True,
|
||||||
|
1, // extra characters after expression
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
@ -453,6 +453,38 @@ func (p *parser) parseExpressionTerm() (Expression, zcl.Diagnostics) {
|
|||||||
SrcRange: tok.Range,
|
SrcRange: tok.Range,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
|
case TokenIdent:
|
||||||
|
tok := p.Read() // eat identifier token
|
||||||
|
|
||||||
|
name := string(tok.Bytes)
|
||||||
|
switch name {
|
||||||
|
case "true":
|
||||||
|
return &LiteralValueExpr{
|
||||||
|
Val: cty.True,
|
||||||
|
SrcRange: tok.Range,
|
||||||
|
}, nil
|
||||||
|
case "false":
|
||||||
|
return &LiteralValueExpr{
|
||||||
|
Val: cty.False,
|
||||||
|
SrcRange: tok.Range,
|
||||||
|
}, nil
|
||||||
|
case "null":
|
||||||
|
return &LiteralValueExpr{
|
||||||
|
Val: cty.NullVal(cty.DynamicPseudoType),
|
||||||
|
SrcRange: tok.Range,
|
||||||
|
}, nil
|
||||||
|
default:
|
||||||
|
return &ScopeTraversalExpr{
|
||||||
|
Traversal: zcl.Traversal{
|
||||||
|
zcl.TraverseRoot{
|
||||||
|
Name: name,
|
||||||
|
SrcRange: tok.Range,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
SrcRange: tok.Range,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
var diags zcl.Diagnostics
|
var diags zcl.Diagnostics
|
||||||
if !p.recovery {
|
if !p.recovery {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user