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

wrong parse-error line/column numbers at ocaml-menhir backend #380

Closed
JoAllg opened this issue Sep 15, 2021 · 6 comments
Closed

wrong parse-error line/column numbers at ocaml-menhir backend #380

JoAllg opened this issue Sep 15, 2021 · 6 comments
Assignees
Labels
bug Ocaml/Menhir parser Issues concerning parser generating position Concerning position information in parsed AST test Concerning the generated test program
Milestone

Comments

@JoAllg
Copy link

JoAllg commented Sep 15, 2021

the Test*.ml created by the ocaml-menhir backend does not report parse errors with correct line/column numbers. The error is always
Parse error at 0.-1-0.-1

This can for example be checked with this erroneus grammar test.cf :

`token Nat digit+ ;
token Int '-'? digit+ ;

entrypoints Prog ;
Code. Prog ::= Instr ";" [Instr] ;

separator Instr ";" ;
_.      Instr ::= Instr ";" ;
IPUSH.  Instr  ::= "PUSH" CType Data ;
IADD.   Instr  ::= "DROP" ;

DInt.   Data         ::= Int ;
CInt.   CType        ::= "int" ;

and testfile test_contract.tz:

DROP;
ADD;
DROP;
PUSH int -5;
PUSH int 1;

and execution with

bnfc --ocaml-menhir -m -o test test.cf && make -C test
`./ocaml_backend/TestMichelson test_contract.tz
@andreasabel
Copy link
Member

I can confirm that this is a problem in --ocaml-menhir but not in --ocaml.

@andreasabel andreasabel added bug Ocaml/Menhir parser Issues concerning parser generating position Concerning position information in parsed AST labels Sep 16, 2021
@andreasabel andreasabel added this to the 2.9.3 milestone Sep 16, 2021
@andreasabel andreasabel self-assigned this Sep 16, 2021
@andreasabel
Copy link
Member

@JoAllg: Thanks for the bug report! I pushed a fix, could you please check that it works for you?

@JoAllg
Copy link
Author

JoAllg commented Sep 16, 2021

@andreasabel thanks for the quick fix! It does work! Though both column numbers are offset by one char, should be +1 char to the right

@andreasabel andreasabel added the test Concerning the generated test program label Sep 16, 2021
@andreasabel
Copy link
Member

@JoAllg: It seems that the column is computed wrongly in:

[ "start_pos.pos_lnum (start_pos.pos_cnum - start_pos.pos_bol)"
, "end_pos.pos_lnum (end_pos.pos_cnum - end_pos.pos_bol);" ]

Looking at e.g.
https://github.com/let-def/ocamllex/blob/e5c8421f8fe56017e9b4e58c3496356631843802/lexer.mll#L54
it seems like a +1 is missing here.
I'll push a fix. Thanks for the alert!

@andreasabel
Copy link
Member

@JoAllg: I pushed a fix for the column, so that it is now counted from 1 (and not from 0). Welcome to test again!

@JoAllg
Copy link
Author

JoAllg commented Sep 17, 2021

@andreasabel works like a charm now :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Ocaml/Menhir parser Issues concerning parser generating position Concerning position information in parsed AST test Concerning the generated test program
Projects
None yet
Development

No branches or pull requests

2 participants