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:
Martin Atkins 2017-05-29 19:58:45 -07:00
parent 954939b49f
commit cf3cd7f86d

View File

@ -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()
diags = append(diags, &zcl.Diagnostic{ if bad.Type == TokenOQuote {
Severity: zcl.DiagError, diags = append(diags, &zcl.Diagnostic{
Summary: "Attribute or block definition required", Severity: zcl.DiagError,
Detail: "An attribute or block definition is required here.", Summary: "Invalid attribute name",
Subject: &bad.Range, Detail: "Attribute names must not be quoted.",
}) Subject: &bad.Range,
})
} else {
diags = append(diags, &zcl.Diagnostic{
Severity: zcl.DiagError,
Summary: "Attribute or block definition required",
Detail: "An attribute or block definition is required here.",
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