-
Notifications
You must be signed in to change notification settings - Fork 6
Document use of the colon operator #68
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
base: main
Are you sure you want to change the base?
Conversation
`?`. | ||
|
||
Use of `:` in symbolic operators is partially reserved. It may only be used in operators where the first character | ||
is `>` or where the first character after any number of leading `.` is `>` e.g. `>:` or `.>:`. |
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.
This is a weird situation. Given this comment I would have expected :
to become a regular op-char
. I think this deserves a separate language suggestion to rectify it.
But now that it exists we have to deal with it in the spec. I don't think this comment is the best way to do it. The grammar should be the source of truth (and there are no "reserved symbolic operators"). So, I see two options.
a) Adapt the grammar to describe the current situation (we might need to introduce a last-op-char
term).
b) Leave the grammar as is, remove the comment and assume the current behavior is a compiler bug.
I am tending toward b), but am interested in other opinions. Maybe I am overlooking something.
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'm not quite sure how to read .fsl syntax but these seem to be be relevant sections here
https://github.com/roboz0r/fsharp/blob/8d12fd301c5a52649b09f2e31dba2ae0cf757419/src/Compiler/lex.fsl#L238-L240
https://github.com/roboz0r/fsharp/blob/8d12fd301c5a52649b09f2e31dba2ae0cf757419/src/Compiler/lex.fsl#L110-L118
https://github.com/roboz0r/fsharp/blob/8d12fd301c5a52649b09f2e31dba2ae0cf757419/src/Compiler/lex.fsl#L988-L1004
Based on my reading :
, $
and ?
are always lexed to be part of operators but are then tagged with errors.
This construct is deprecated: '$' is not permitted as a character in operator names and is reserved for future use
The other note in the spec about ?
seems to just be incorrect too.
Only the operators ? and ?<- may start with ?.
This code compiles fine:
let (?+) a b = if a then b + 1 else b
true ?+ 7
Trying to come up with some declarative rules for this is a bit tricky but I think this works if token symbolic-op
is always attempted before token reserved-symbolic-op
.
regexp op-char = !%&*+-./<=>?@^|~
regexp ignored-op-char = .?
regexp op-colon = :
regexp op-greater = >
regexp op-dollar = $
token quote-op-left =
| <@ <@@
token quote-op-right =
| @> @@>
token symbolic-op =
| op-char +
| ignored-op-char * op-greater (op-colon | op-char) *
| quote-op-left
| quote-op-right
token reserved-symbolic-op =
| (op-char | op-colon | op-dollar) +
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.
Seems like ?
has been allowed in arbitrary operators at least as far back as 11 years https://github.com/dotnet/fsharp/blame/9e2f161b036cf3d91998d86f966eac532bea1659/src/fsharp/FSharp.Core/Linq.fs
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.
Seems like
?
has been allowed in arbitrary operators at least as far back as 11 years https://github.com/dotnet/fsharp/blame/9e2f161b036cf3d91998d86f966eac532bea1659/src/fsharp/FSharp.Core/Linq.fs
Yeah, the documentation has (always?) been incomplete about this. I meant to try to update it back when I was doing the parentheses analysis, but I never got around to it...
Zero or more leading dots or question marks can be added to any infix operator and have no effect on precedence or associativity with the exception of &
, &&
, and ||
(whose bare forms are treated as special cases).
Thanks for spotting / remembering this! |
I created a language suggestion to simplify the rules surrounding the |
The
:
operator became partially unreserved when dotnet/fsharp#15923 was merged.Also tidies up some minor whitespace errors.