-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Parse unary operators as regular identifiers when backquoted #15198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a useful change. But no need for the isNonBackquotedIdent
abstraction.
My previous observation
ought to have read, "very consistent yet very mistaken expectation". The identifiers taken as prefix operators are already regular identifiers. The proposal is to make them ineligible as prefix operators when backquoted. We will need an answer on StackOverflow for "What are all the uses of backquotes in Scala?" |
bfb6d7d
to
290f4c9
Compare
Thanks for the suggestions. I also added a note to the PrefixOperator line in both syntax.md files. |
290f4c9
to
528d5cb
Compare
@odersky friendly bump on this. |
@@ -254,7 +254,7 @@ InfixExpr ::= PrefixExpr | |||
| InfixExpr MatchClause | |||
MatchClause ::= ‘match’ <<< CaseClauses >>> Match(expr, cases) | |||
PrefixExpr ::= [PrefixOperator] SimpleExpr PrefixOp(expr, op) | |||
PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ | |||
PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ -- unless backquoted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is not necessary, since the lexemes are spelled out. The spec text does say, "one of the identifiers...", so it must add, "which must not be enclosed in backquotes." (Where backquote is allowed, it must be shown in a production.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which spec are you referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And do you think I should remove the comment? I think it's kind of ambiguous without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the spec under scala 2 https://scala-lang.org/files/archive/spec/2.13/06-expressions.html#prefix-operations
Personally, I find it more precise as it is. If it doesn't say you can use
'`' '~' '`'
then you can't, modulo bugs. Backquotes are not some metacharacter with respect to syntax. Or they are not onions, as in, "Would you like onions with that?"
However, there are two groups of consumers for the two syntax pages, so maybe they would say the comment is clarifying. I don't know which group, but hopefully they will voice their preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's so obvious when you put it like that. Until now, the spec text and syntax summary were at odds. I'll update the spec under Scala 2 and backport.
528d5cb
to
cfd2760
Compare
A sheepish attempt at retrying #14299. In that PR, I suggested allowing unaries like
+
to be interpreted as regularApply
nodes when followed by type parameters. @odersky commented that@som-snytt pointed out that
I strongly agree with that last statement -- it makes sense to me that anything in backticks is "just some identifier" and never receives syntactic privilege. This is already the case for keywords and in pattern matching. I was rather surprised to learn that backquotes don't suppress special unary operator parsing as it is.
I suspect this PR will not be accepted because it is technically a breaking change, although I suspect it will affect no one, and I would gladly guard it behind a setting it if that's the path to acceptance. I thought I'd try anyways!
(This can be made non-breaking by allowing
but I suspect that is a non-starter because of the surprise).