BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
587 stars 165 forks source link

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

Closed JoAllg closed 3 years ago

JoAllg commented 3 years ago

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 commented 3 years ago

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

andreasabel commented 3 years ago

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

JoAllg commented 3 years ago

@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 commented 3 years ago

@JoAllg: It seems that the column is computed wrongly in: https://github.com/BNFC/bnfc/blob/fb4606b069fff8761fcfec26df636fd64f3e71ba/source/src/BNFC/Backend/OCaml/CFtoOCamlTest.hs#L76-L77 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 commented 3 years ago

@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 commented 3 years ago

@andreasabel works like a charm now :-)