261006.1 · a19efdd45dfe91329a7d266efb2ac0a64279a938
Parse `?//` as `?` and `//` outside destructuring patterns (#3593)
The lexer returned a single ALTERNATION token for `?//`, so any `?` followed by `//` was consumed by it, and `.name?//"unknown"` failed to parse even though they read as the optional operator followed by the alternative operator.
Drop the lexer rule and spell the destructuring alternative operator as `'?' "//"` instead. So `x ?// y` now parses as `x? // y`, while `. as [$a] ?// [$b] | ...` keeps its meaning. Note that `?` and `//` may now be separated by whitespaces inside a pattern.
reading declarations
Changes to src/parser.y. All files
@@ -85,7 +85,6 @@ struct lexer_param; %token SETDEFINEDOR "//=" %token LESSEQ "<=" %token GREATEREQ ">="-%token ALTERNATION "?//" %token QQSTRING_START %token <literal> QQSTRING_TEXT@@ -746,16 +745,16 @@ Query { } RepPatterns:-RepPatterns "?//" Pattern {- $$ = BLOCK($1, gen_destructure_alt($3));+RepPatterns '?' "//" Pattern {+ $$ = BLOCK($1, gen_destructure_alt($4)); } | Pattern { $$ = gen_destructure_alt($1); } Patterns:-RepPatterns "?//" Pattern {- $$ = BLOCK($1, $3);+RepPatterns '?' "//" Pattern {+ $$ = BLOCK($1, $4); } | Pattern { $$ = $1;