zclsyntax: permit dashes in identifiers

While this does create some ambiguity with arithmetic on variables, like
a-b, this is permitted by HCL and so we'll permit it for zcl too, at the
expense of requiring spaces to be used around minus signs for correct
interpretation.
This commit is contained in:
Martin Atkins 2017-06-24 09:12:24 -07:00
parent cab61b36dc
commit f8561de857
4 changed files with 1504 additions and 1499 deletions

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,7 @@ func scanTokens(data []byte, filename string, start zcl.Pos, mode scanMode) []To
BrokenUTF8 = any - AnyUTF8;
NumberLit = digit (digit|'.'|('e'|'E') ('+'|'-')? digit)*;
Ident = ID_Start ID_Continue*;
Ident = ID_Start (ID_Continue | '-')*;
# Symbols that just represent themselves are handled as a single rule.
SelfToken = "[" | "]" | "(" | ")" | "." | "," | "*" | "/" | "+" | "-" | "=" | "<" | ">" | "!" | "?" | ":" | "\n" | "&" | "|" | "~" | "^" | ";" | "`";

View File

@ -96,7 +96,7 @@ their syntax is defined in terms of the `ID_Start` and `ID_Continue`
character properties as follows:
```ebnf
Identifier = ID_Start ID_Continue*;
Identifier = ID_Start (ID_Continue | '-')*;
```
The Unicode specification provides the normative requirements for identifier
@ -104,6 +104,11 @@ parsing. Non-normatively, the spirit of this specification is that `ID_Start`
consists of Unicode letter and certain unambiguous punctuation tokens, while
`ID_Continue` augments that set with Unicode digits, combining marks, etc.
The dash character `-` is additionally allowed in identifiers, even though
that is not part of the unicode `ID_Continue` definition. This is to allow
attribute names and block type names to contain dashes, although underscores
as word separators are considered the idiomatic usage.
[UAX31]: http://unicode.org/reports/tr31/ "Unicode Identifier and Pattern Syntax"
### Keywords

View File

@ -32,24 +32,24 @@ func TestFormat(t *testing.T) {
`(a + 2)`,
},
{
`( a-2 )`,
`(a - 2)`,
`( a*2 )`,
`(a * 2)`,
},
{
`( a+-2 )`,
`(a + -2)`,
},
{
`( a--2 )`,
`(a - -2)`,
`( a*-2 )`,
`(a * -2)`,
},
{
`(-2+1)`,
`(-2 + 1)`,
},
{
`foo(1, -2,a-b, b,c)`,
`foo(1, -2, a - b, b, c)`,
`foo(1, -2,a*b, b,c)`,
`foo(1, -2, a * b, b, c)`,
},
{
`a="hello ${ name }"`,
@ -80,7 +80,7 @@ hello
foo(
1,
- 2,
a-b,
a*b,
b,
c,
)
@ -89,7 +89,7 @@ c,
foo(
1,
-2,
a - b,
a * b,
b,
c,
)