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
wrong location after directive #5127
Comments
Comment author: @diml Unfortunately it is going to be very difficult to fix. The only simple fix i have in mind is going to degrade performances a lot. By the way note that locations are correct after directives when you use the toplevel. And since directives are for the toplevel, I don't think it is a big problem. So you should avoid using them in programs. As a replacement you can use camlp4.macro: INCLUDE "x.ml" With this syntax there is no problem. |
Comment author: Hendrik Tews May I suggest to add a note to the documentation? |
Comment author: @diml Sure. But i don't know where it should go... |
Comment author: Hendrik Tews I would suggest to put it as ocamldoc comment into module Loc in file camlp4/Camlp4/Sig.ml. That's at least where I look when I want to know something about camlp4 locations. |
Comment author: Hendrik Tews After looking again at the problem I noticed that we might have a let directive_handler x = Some x The problem is obviously that value stopped_at _loc = in camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml does not move |
Comment author: @bobzhang I was bitten by this bug too. |
Comment author: @bobzhang I defined my own add hoc syntax extension to work around this problem. I used syntax extension only for ad hoc usage. |
Comment author: @diml
That's what i understood.
It is a more complicated problem; the parser used by camlp4 for an implementation/interface file has type: Loc.t -> char Stream.t -> Ast.(str_item/sig_item) * Loc.t option Where Loc.t option is the the location after the current directive if any. This parser internally creates a lexer, token stream, ... for this character stream, and when it stops after a directive, pending characters in the lexer or pending tokens in the token streams or any other stuff in internal data structures are just lost, so there is no way to tell what will be the next location. Here is for example another bug with directives and camlp4: $ cat > foo.ml The "let" keyword has been dropped. One way to fix this would be to change the API to use parsers that takes token streams but it will break programs. If you really want to use directives you can have a look at the optcomp project, it handles them at the token level (before the parser) so it does not have this problem. |
Comment author: @diml Not if you don't use directives. |
Comment author: @bobzhang FYI, this problem disappeared in my branch after I changed stopped_at, just pass the same position |
Comment author: @damiendoligez Transferred to camlp4/camlp4#72 |
Original bug ID: 5127
Reporter: Hendrik Tews
Assigned to: @diml
Status: closed (set by @damiendoligez on 2015-01-09T18:59:44Z)
Resolution: suspended
Priority: normal
Severity: minor
Version: 3.12.0
Target version: undecided
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues
Bug description
The locations in the Camlp4 ast are completely wrong for the
material that follows a directive. For a two line file
#use "y.ml";;
let a = 5
the location in the StVal node for line 2 has
start_line = 3 (should be 2)
start_bol = 1 (should be 14)
start_off = 1 (should be 14)
the stop location is also wrong.
The text was updated successfully, but these errors were encountered: