-
Notifications
You must be signed in to change notification settings - Fork 25
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
Keep track of locations in the AST #21
Conversation
Thanks for reminding me about #18. I've merged it so you can now rebase. At first glance, your patch looks alright but the way you've added locs looks a bit clumsy to me. Why not have a type like @Drup you're a loc expert, could you please comment about the above? |
Rebased. About locations, I'm not sure to understand what you mean. Do you want to have locations separate from the mustache AST? I'm not sure how to do that, given each node of the AST is supposed to be annotated with a location. |
Ah yes, you're right. Shouldn't have commented in haste. It's a been annoying to have to impose locations on people who won't necessarily Will have a closer look at this in the next couple of days. In-Reply-To: rgrinberg/ocaml-mustache/pull/21/[email protected] On 08/19, Armael wrote:
|
I would have done something like:
It simplifies things a bit, and avoid repetitions. |
Also, it may be a good idea to have two datatypes, one AST with loc (and that could be much more precise), and one that is just the (simplified) datatype, appropriate for manipulation in OCaml. |
Would that mean duplicating the parser? An other option is to have a function that takes an annotated AST and produces a simplified AST, by removing locations (and the parser would produce annotated ASTs). |
The second solution, of course. |
I'm sorry it took me so long to get back to this. Existing tests pass; I did not add tests checking locations at the moment. |
I added a test doing a roundtrip add_dummy_locs -> erase_locs. |
I thought a tuple for the loc would be more natural. But it doesn't matter so much. @Drup Would you mind taking a look? It looks good to me but it would be good to have your opinion here. |
I adapted my mustache-ppx to the new module One nice (future ?) addition would to raise/return a better error when parsing fails, including the location of the failure. |
Probably future addition If I was implementing it. I have no idea how to accomplish this without rewriting the parser by hand. |
Thanks @Armael |
This is WIP for keeping track of locations in the AST.
The motivation for this is ocsigen/tyxml#128 .
The core feature itself is implemented, namely producing an AST whose nodes are annotated by locations. What remains is polishing the API & tooling, and for that I thought I'd ask before implementing something potentially unsatisfactory.
Remarks/questions:
Mustache.t
type; I guess make Mustache.t non abstract #18 should be merged first, then this PR rebased on top of it;Mustache
module ignore locations, and put a dummy value when one is needed. I'm not sure what would be a nicer API for these (which would probably be incompatible with the current one);Mustache
insert dummy locations, which do not match the actual locations provided by the parser. One solution I see would be to directly hand-write the AST (tedious), or improve these helper functions (equally or less tedious depending on how they are improved, I guess).