this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/ast: clarify what is a valid identifier

The spec first says:

Identifiers name entities such as fields and aliases. An identifier
is a sequence of one or more letters (which includes _ and $) and
digits, optionally preceded by # or _#. It may not be _ or $.

Which could lead one to believe that "_" is not a valid identifier.
However, it also says:

Top is represented by the underscore character _,
lexically an identifier.

Moreover, the parser uses an ast.Ident node for top, so our parser
and compiler seem to disagree with the first part of the spec,
working under the assumption that an underscore is a valid identifier.

We're not changing the implementation here, and not even the spec,
even if making "identifier" a separate node from "top" would make sense.
However, making the cue/ast docs less ambiguous is easy and useful.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ic610654ff4408f15647e3b2ea3601e562b1be9a4
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/556986
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+3 -1
+2 -1
cue/ast/ast.go
··· 394 394 expr 395 395 } 396 396 397 - // An Ident node represents an left-hand side identifier. 397 + // An Ident node represents an left-hand side identifier, 398 + // including the underscore "_" identifier to represent top. 398 399 type Ident struct { 399 400 NamePos token.Pos // identifier position 400 401
+1
cue/ast/ident.go
··· 34 34 } 35 35 36 36 // IsValidIdent reports whether str is a valid identifier. 37 + // Note that the underscore "_" string is considered valid, for top. 37 38 func IsValidIdent(ident string) bool { 38 39 if ident == "" { 39 40 return false