Conversation
|
|
||
| type lid = Longident.t loc | ||
| type str = string loc | ||
| type 'a with_loc = 'a Location.loc |
There was a problem hiding this comment.
Does this suggest that 'a Location.loc would be better named 'a Location.with_loc? (but changing that now may be not worth the hassle..)
parsing/pprintast.mli
Outdated
| val structure: Format.formatter -> Parsetree.structure -> unit | ||
| val string_of_structure: Parsetree.structure -> string | ||
|
|
||
| val longident : Format.formatter -> Longident.t -> unit |
There was a problem hiding this comment.
I think that longident could be at the top rather than the bottom of the interface since it prints simpler items.
There was a problem hiding this comment.
Will do -- the order in the other declarations is not the one you suggest, so I will reorder everything.
parsing/longident.mli
Outdated
| [@@@ocaml.doc{| | ||
| To print a longident, see {!Pprintast.longident}, using | ||
| {!Format.asprintf} to convert to a string. | ||
| |}] |
There was a problem hiding this comment.
Was there a problem with a documentation comment here ((** ... *)) ?
There was a problem hiding this comment.
I wasn't sure that I would get the right comment-by-itself behavior with just newlines, so I thought that this more explicit syntax would be better. Do you think I should change back?
There was a problem hiding this comment.
I think so: I just realized that the right attribute was ocaml.text and not ocaml.doc. A newline should be fine (and checking with -dsource works well).
There was a problem hiding this comment.
Good catch... I just changed it.
parsing/parsetree.mli
Outdated
| [`A of & T1 & .. & Tn] ( true, [T1;...Tn] ) | ||
|
|
||
| - The 2nd field is true if the tag contains a | ||
| - The 3rd field is true if the tag contains a |
There was a problem hiding this comment.
Now it is actually the 2nd field.
| | Psig_extension (x, attrs) -> | ||
| sub.extension sub x; sub.attributes sub attrs | ||
| sub.attributes sub attrs; | ||
| sub.extension sub x |
There was a problem hiding this comment.
I'm not sure if there are consequences to this order change, but it is more consistent with other cases after this change.
There was a problem hiding this comment.
The idea is to have .attributes come right after .location for all AST nodes, so that you can know when you process an attribute the location of its whole attached node (attribute included) by an ugly side-effect. See #1765. This is fragile of course, and would like a better long-term way to do it.
360b867 to
106b048
Compare
106b048 to
256e6e3
Compare
|
(I rebased the PR.) |
| Line 1, characters 25-33: | ||
| let last_ident = L.last (L.lident "foo") | ||
| ^^^^^^^^ | ||
| Error: Unbound value L.lident |
There was a problem hiding this comment.
This error does not seem intentional?
There was a problem hiding this comment.
Indeed, sorry. I just reworked the tests and rebased.
256e6e3 to
a7a0abf
Compare
Octachron
left a comment
There was a problem hiding this comment.
The changes look good to me.
| let parse_complex = L.parse "M.F(M.N).N.foo" | ||
| [%%expect {| | ||
| val parse_complex : L.t = | ||
| L.Ldot (L.Ldot (L.Ldot (L.Ldot (L.Lident "M", "F(M"), "N)"), "N"), "foo") |
There was a problem hiding this comment.
I missed that, but yes Longident.parse only parses the subset of Longident without application.
There was a problem hiding this comment.
Can you (or @gasche) comment on what you think should be done then?
Should we change Longident.parse? Should we remove the test? Add a comment on the test?
Note that a few lines below we're converting back that broken Longident to a string, and everything looks "fine". I don't think we should do that.
There was a problem hiding this comment.
Personally I think that Longident.parse should be fixed to be complete. In fact I hadn't really looked at the test output (otherwise I would have said something here); this continuing experience of surprises makes me half-glad half-sorry that I insisted on writing unit tests for compiler-libs feature.
There was a problem hiding this comment.
Going down this rabit's hole, making Longident.parse complete also means udapting the call in makedepend.ml and typemod.ml to reject applications in -open arguments .
There was a problem hiding this comment.
An intermediate fix would be to make Longident.parse fail upon seeing a parenthesis.
[edit] better yet, make it check that the components are valid identifers.
There was a problem hiding this comment.
I think an option returning version might be better since in the two current use cases of Longident the error handling should be specialized:
- In
Typemod, the compiler should warns that-open F(X)is not valid (should the input be validated earlier?) - in
toplevel/genprintval.ml, the extension printer should abort the search for extensions constructor to handle cases like
module F(X:sig end) = struct type t = .. type t+= A end
module E = struct end
let x : F(E).t = let module M = F(E) in M.A;;val x : F(E).t = <extension>
( currently, the printer searches for a module Lident F(E) and fails)
There was a problem hiding this comment.
In Typemod, the compiler should warns that -open F(X) is not valid
That won't stay true for very long: I'm about to send a refreshed version of the "extended open" PR which allows this.
There was a problem hiding this comment.
I'm about to send a refreshed version of the "extended open" PR which allows this.
I think that's only true for .mli files, for .ml files you probably still need a warning.
There was a problem hiding this comment.
In this case, would it not be simpler to expose the corresponding parser rule (module_expr?) from the parser and use constr_longident for the extension printer?
f9c67fe to
eef31c5
Compare
This is a continuation of #1918 (Longident.to_string) with a different implementation approach suggested by @Octachron and @jberdine.
(I haven't updated the Changes yet, but a review would still be welcome.)