zclsyntax: don't allow quoted strings as attribute names
This will be allowed for object literals, but attributes are treated differently to reinforce the fact that they have a predefined structure.
This commit is contained in:
parent
954939b49f
commit
cf3cd7f86d
@ -31,7 +31,7 @@ Token:
|
|||||||
case TokenNewline:
|
case TokenNewline:
|
||||||
p.Read()
|
p.Read()
|
||||||
continue
|
continue
|
||||||
case TokenIdent, TokenOQuote:
|
case TokenIdent:
|
||||||
item, itemDiags := p.ParseBodyItem()
|
item, itemDiags := p.ParseBodyItem()
|
||||||
diags = append(diags, itemDiags...)
|
diags = append(diags, itemDiags...)
|
||||||
switch titem := item.(type) {
|
switch titem := item.(type) {
|
||||||
@ -64,12 +64,21 @@ Token:
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
bad := p.Read()
|
bad := p.Read()
|
||||||
|
if bad.Type == TokenOQuote {
|
||||||
|
diags = append(diags, &zcl.Diagnostic{
|
||||||
|
Severity: zcl.DiagError,
|
||||||
|
Summary: "Invalid attribute name",
|
||||||
|
Detail: "Attribute names must not be quoted.",
|
||||||
|
Subject: &bad.Range,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
diags = append(diags, &zcl.Diagnostic{
|
diags = append(diags, &zcl.Diagnostic{
|
||||||
Severity: zcl.DiagError,
|
Severity: zcl.DiagError,
|
||||||
Summary: "Attribute or block definition required",
|
Summary: "Attribute or block definition required",
|
||||||
Detail: "An attribute or block definition is required here.",
|
Detail: "An attribute or block definition is required here.",
|
||||||
Subject: &bad.Range,
|
Subject: &bad.Range,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
endRange = p.NextRange() // arbitrary, but somewhere inside the body means better diagnostics
|
endRange = p.NextRange() // arbitrary, but somewhere inside the body means better diagnostics
|
||||||
|
|
||||||
p.recover(end) // attempt to recover to the token after the end of this body
|
p.recover(end) // attempt to recover to the token after the end of this body
|
||||||
|
Loading…
x
Reference in New Issue
Block a user