-
Notifications
You must be signed in to change notification settings - Fork 1.2k
-dsource: \#mod is not an operator in type context #13604
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
-dsource: \#mod is not an operator in type context #13604
Conversation
Fix ocaml#13603 by not adding parentheses around (mod) when it is neither a pattern nor an expression.
parsing/pprintast.ml
Outdated
| type longindent_kind = | ||
| | Constr (* [true] and [false] *) | ||
| | Type (* [mod] *) | ||
| | Other |
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 feel that I understand almost everything in this PR, except for this type declaration and its documentation.
- I don't know what the comment ("Classify ...") means.
- The documentation is specifically talking about raw identifiers, but I think that the meaning of this "kind" is independent from raw identifiers. (It's some information that we need to track because of raw identifier printing needs, but which is independent from it.)
- My reverse-engineering guess is that this is pretty-printing context information, that carries information on the grammatical context in which the printed value will be used. Another way to view it is that we are specifying the grammatical category of what is being printed. (For a notion of grammar that is finer-grained than just "longident", obviously.) It seems to be related to (a coarser-grained version of) the type
Out_type.namespace.
I think that if the documentation of this type (and maybe the type name?) was changed to better reflect my reverse-engineered guess, then the PR would look very nice to me.
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.
Yes, this is too distilled comments on the fact that Longident is a too coarse grammatical category to allow unparsing: the grammar rules for constructor, module, type and value longidents are different. Before the introduction of raw identifiers, we could recover just enough information to print them correctly by recognizing special case in each category (true and false for constructors, operators for values).
Raw identifiers makes this context-less reconstruction impossible by making it possible for those special case to appear escaped in other kind of longidents. For instance mod might be either an operator name in a value longident, or a raw identifier in a type longident. Similarly, true might be a normal constructor or a raw identifier in a value longident.
Thus this PR uses contextual information to recover the information about which form of longidents we are printing and how should we print them according to their specific grammar.
I will amend the comment to be more explicit (next week).
gasche
left a comment
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 new comment went above and beyond what I expected. Thanks! Approved.
-dsource: \#mod is not an operator in type context (cherry picked from commit 75459af)
|
Cherry-picked on 5.3 as 8237eaa . |
This imports upstream patches to pprintast that were done post 5.2 and improves pprintast's handling of raw identifiers. Hopefully that should fix the issue that fstar folks ran into with the 0.36.2 release. Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
This imports upstream patches to pprintast that were done post 5.2 and improves pprintast's handling of raw identifiers. Hopefully that should fix the issue that fstar folks ran into with the 0.36.2 release. Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
This imports upstream patches to pprintast that were done post 5.2 and improves pprintast's handling of raw identifiers. Hopefully that should fix the issue that fstar folks ran into with the 0.36.2 release. Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
This imports upstream patches to pprintast that were done post 5.2 and improves pprintast's handling of raw identifiers. Hopefully that should fix the issue that fstar folks ran into with the 0.36.2 release. Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
This imports upstream patches to pprintast that were done post 5.2 and improves pprintast's handling of raw identifiers. Hopefully that should fix the issue that fstar folks ran into with the 0.36.2 release. Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
This PR fixes #13603 by splitting the longident syntactic category in three inside the implementation of
Pparsetree:trueandfalseare uppercase identifiersmodis not an operator but the lowercase identifier written\#modin the source.modis an operator (which should be printed(mod)) andtrueandfalseare lowercase identifiers introduced with the raw identifier syntax #true and #false.Beyond the specific bug discovered in #13603 this PR also fixes along the way:
true|false|[]|()constructors in presence of argumentsmodule type \#let.