-
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
Open
roboz0r
wants to merge
1
commit into
fsharp:main
Choose a base branch
from
roboz0r:op-colon
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 regularop-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.
Uh oh!
There was an error while loading. Please reload this page.
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.The other note in the spec about
?
seems to just be incorrect too.This code compiles fine:
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 beforetoken reserved-symbolic-op
.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.fsThere 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.
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).