cue/parser: allow omitting commas in lists
CUE already allows struct field commas to be
omitted at end-of-line via automatic comma
insertion (scanner sets insertEOL=true after
`]`, identifiers, literals, etc.). Lists
required explicit commas between elements.
This removes that restriction for language
version v0.17.0 and later: a newline after a
list element now acts as a comma, consistent
with struct fields.
The parser's synthetic-comma guard in
parseListElement (which raised "missing ','
before newline in list literal") is retained
for files with a language version below
v0.17.0, preserving backwards compatibility.
A new versionAtLeast helper reads the file
version via p.experiments.LanguageVersion()
and compares with semver, matching the
pattern already used by compile.go.
The spec's exception note ("the parser will
require explicit commas between two list
elements") and its TODO comment are removed;
a versioned note is kept in an HTML comment.
Fixes a latent bug where [expr\nfor x in xs
{z}] silently dropped the comprehension (the
old guard returned ok=false when it saw FOR
after the synthetic comma, breaking the parse
loop before the comprehension was reached).
Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: If6ed8764449547482a1f9848099c5ef9f30a16b9
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1235981
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>