-
Notifications
You must be signed in to change notification settings - Fork 179
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
5.2 support: Raw identifiers #2619
Conversation
The parser doesn't allow raw ident in module names but it does in module type names.
$ fmt_package_type c ctx cnstrs | ||
$ fmt_attributes c attrs ) | ||
| Ptyp_open (lid, typ) -> | ||
hvbox 2 | ||
( hvbox 0 (fmt_longident_loc c lid $ str ".(") | ||
( hvbox 0 (fmt_longident_loc c ~constructor:true lid $ str ".(") |
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.
Why is it ~constructor:true
here ?
We need raw idents to be preserved. if I use #effect in a 5.3 switch, I don't want it to be rewritten in a 5.2 switch. |
Thinking more about it, you could even imagine a mode that would help migrating to newer ocaml version by escaping idents that are becoming keyword. |
Sorry, I should have mentioned it, but I think my PR in the janestreet repo has a bug: escaped operators in types need special treatment. The compiler itself also has this bug, see the report in ocaml/ocaml#13603 and a fix in ocaml/ocaml#13604. I'm in the process of adapting that fix in my ocamlformat pr to our branch. |
I agree that we should preserve the raw identifier marker and not try to add it again later. I'm now investigating passing that information through a table, like we do for comments, as changing the AST for this might brings huge changes to the lexer and parser, making future backports harder.
That should be possible on top of this work. |
Can't you keep the escaping prefix during lexing ? Without touching the ast ? |
If we go with preserving escaped idents, we no longer have special treatments |
Don't we need to update the lexer in parser-standard as well ? |
The upstream OCaml lexer is able to recognize different set of keywords. One can pass |
I'm currently investigating changing the AST to represent how identifiers looked in the source. If that's too much changes in the parser and AST, I'll switch to the table approach.
No, I'll let the parser-standard behave as it does upstream (
This should be plugged to the |
Ok, turns out the standard lexer was already updated in #2512 |
In #2619 (comment), I was suggesting to not change the Ast and just store the escaped ident in the LIDENT token. What do you think ? |
I pushed the Parsetree approach here: #2620 |
That would have been simpler indeed. I'll investigate how that looks. |
The lexer approach is in this PR: #2621 |
This is the last missing piece for 5.2 support.
Thanks to @ccasin who made the work in janestreet#88