daniellansun commented on PR #2944:
URL: https://github.com/apache/groovy/pull/2944#issuecomment-6269318424

   @paulk-asert Thank you for tracing this against the grammar. The false 
positive on division at end of file was real. The fix follows that direction, 
with one narrowing so expression-introducing keywords still accept a slashy 
string.
   
   ## Division after a value
   
   `String.class / 2` and `String.class /2/ 3` are division again, including at 
end of file. Keywords that can end a value and do not introduce an expression 
(`class`, `super`, `var`, `int`, `new`, and the rest of that set in 
`REGEX_CHECK_SET`) are division operands. That also corrects the old two-slash 
mislex of `a.class /2/ b`.
   
   `return`, `assert`, `throw`, `case`, `yield`, `await`, `defer`, `else`, and 
`do` stay out of that set. Putting them in would reject programs that compile 
today: `return /pattern/`, `assert /pattern/`, `'ab' in /a/`, `else /pattern/`, 
and `do /pattern/ while (false)`. After a member selector the same keyword is a 
name, so these are division:
   
   - `obj.return / 2`
   - `obj.<T>return / 2`
   - `obj.<@Ann(x > 1) T>return / 2`
   
   Newlines and comments between the selector and the name are ignored. `<...>` 
in between is part of the member, including a qualified name. `>`, `>>`, and 
`<` inside `()`, `[]`, or `{}` on an annotation do not close that type argument.
   
   `in` is infix when a value precedes it. `'ab' in /a/`, `in in /a/`, `obj.in 
in /a/`, and `for (in in /a/)` stay slashy strings. A member name counts as 
that value. A bare name does not: `in / 2`, `obj.in / 2`, and `return in / 2` 
are division.
   
   `yield`, `await`, and `defer` are not treated as values. `yield in / 2` 
stays division rather than `Unclosed string literal`. The cost is that `for 
(yield in /a/)`, and the same form for `await` and `defer`, is not a slashy. 
Happy to flip that tradeoff if the for-variable form is the one you want to 
keep.
   
   ## Unclosed slashy GString
   
   `/hello $name` with no closing `/` is `SlashyGStringBegin`, not the plain 
EOF alternative. The message stays `Unexpected end of input` at the end of the 
line, not `Unclosed string literal` on the opening `/`. That limitation is now 
in the lexer comment and in `core-grammar.adoc`, and the current text is pinned 
by tests. Unclosed `$/...` is unchanged: an EOF alternative there would reject 
`($/2)`, so it still has none.
   
   ## `requireNonNull`
   
   The `Objects.requireNonNull` around `visitFormalParameters` in 
`transformRecordHeaderToProperties` is removed. `visitFormalParameters` already 
returns `Parameter.EMPTY_ARRAY`, and the check was not part of this diagnostic 
change.
   
   ## `reset()`
   
   `Lexer.setInputStream` still drops lexer state only through `reset()`. The 
new member-name flags are cleared there, so a reused lexer does not keep a 
pending `.` or a previous `class` operand. Worth a separate mention in the 
JIRA, as you suggested. I have not edited the JIRA from here.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to