cue/scanner: reject __# as an invalid identifier
The fuzzer found that "__#" was accepted as a single identifier token,
but the spec grammar only allows "#" or "_#" as identifier prefixes:
identifier = [ "#" | "_#" ] letter { letter | unicode_digit } .
"__#foobar" does not match this grammar: the "#" cannot appear after "__"
since it is only valid at the start as part of the "#" or "_#" prefix.
The root cause was scanFieldIdentifier consuming an optional "_" before
an optional "#", allowing both to be consumed together. This created
the "__#" pattern when combined with the initial "_" from the caller.
Fix by removing the separate "_" consumption in scanFieldIdentifier,
since "_" is already handled by the main identifier character loop.
The scanner now reports "__#..." as an illegal token, matching how
"_|" without a trailing "_" is already reported as illegal.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I935bf67f58ef40d3977bc8c79ba3e8cd1d0236e1
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1234633
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Matthew Sackman <matthew@cue.works>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>