Skip to content
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

lexbuf.lex_start_p.pos_lnum and pos_bol are incorrect in exceptions thrown by ocaml grammar parse #5409

Closed
vicuna opened this issue Nov 25, 2011 · 4 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Nov 25, 2011

Original bug ID: 5409
Reporter: nb
Assigned to: @protz
Status: closed (set by @xavierleroy on 2015-12-11T18:04:25Z)
Resolution: not a bug
Priority: normal
Severity: minor
Version: 3.12.0
Category: ~DO NOT USE (was: OCaml general)
Monitored by: nb

Bug description

Issue similar to 0002954 but in ocaml parser.

When a parse_error exception is thrown during parsing the grammar with ocaml (caml-toplevel), lexbuf.lex_start_p returns the position. In the returned value pos_lnum and pos_bol are incorrect while pos_cnum represents the real position in the file where exception was thrown.

File attachments

@vicuna
Copy link
Author

vicuna commented Mar 26, 2012

Comment author: @lefessan

Could you please provide us an example ?

@vicuna
Copy link
Author

vicuna commented Mar 26, 2012

Comment author: nb

Please find the attached project. It is large enough but the issue-related code is contained in the file use.ml . Run make, then parse any text file in order to have a parsing error. Currently use.ml contains the line

Printf.printf "Wrong character %s at position %i." (Lexing.lexeme lexbuf) (errorPosition.pos_cnum)

If change errorPosition.pos_cnum to errorPosition.pos_lnum, the printed string will look like "Wrong character ... at position 0."

@vicuna
Copy link
Author

vicuna commented Mar 29, 2012

Comment author: @protz

I'm not sure there's an issue here. I did not read your grammar through but you seem to have a parsing error at the very beginning of the file (I would suggest compiling and running your parser with menhir --trace to see what's happening).

  • pos_lnum is 1 : the line number is indeed 1
  • pos_cnum is 0 : since the error is at the very beginning of the file, this is column 0 (columns always start with 0)
  • pos_bol is 0 : we're still at offset 0, i.e. the beginning of the file.

Tested with OCaml version 4.01.0+dev0 (2012-03-12)

@vicuna
Copy link
Author

vicuna commented Mar 29, 2012

Comment author: @protz

I'm closing since there doesn't seem to be anything wrong here.

@vicuna vicuna closed this as completed Dec 11, 2015
@vicuna vicuna added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant