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

Gramlib syntax error messages are less precise, sometimes wrong #4329

Closed
vicuna opened this issue Jun 25, 2007 · 1 comment
Closed

Gramlib syntax error messages are less precise, sometimes wrong #4329

vicuna opened this issue Jun 25, 2007 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Jun 25, 2007

Original bug ID: 4329
Reporter: brunodefraine
Status: closed (set by @damiendoligez on 2015-01-09T17:52:47Z)
Resolution: suspended
Priority: normal
Severity: minor
Version: 3.10.0
Target version: undecided
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues

Bug description

camlp4 grammars in 3.10 seem to give less precise syntax errors then they used to do: in a sequence of symbols, it complains about the beginning when the 2nd, 3rd, etc. symbol is wrong. When there are multiple possible sequences that start the same way, this can become very confusing.

For example, consider the following dummy grammar definition:

open Camlp4.PreCast ;

value ab_eoi = Gram.Entry.mk "ab_eoi" ;
value a_or_ab = Gram.Entry.mk "a_or_ab" ;
value a_or_ab_eoi = Gram.Entry.mk "a_or_ab_eoi" ;
value c_a_or_ab_eoi = Gram.Entry.mk "c_a_or_ab_eoi" ;

EXTEND Gram
ab_eoi: [[ "a"; "b"; EOI -> () ]]; a_or_ab: [[ "a" -> () | "a"; "b" -> () ]]; a_or_ab_eoi: [[ a_or_ab; EOI -> () ]];
c_a_or_ab_eoi: [[ "c"; a_or_ab; `EOI -> () ]];
END ;

And the following function to report errors:

value parse_string entry s =
try
Gram.parse_string entry (Loc.mk "") s
with [ Loc.Exc_located loc exn ->
begin
print_endline (Loc.to_string loc);
print_endline (Printexc.to_string exn);
failwith "Syntax Error"
end ] ;

Consider the following syntax errors:

parse_string ab_eoi "a c" ;

File "", line 1, characters 2-3
Stream.Error("illegal begin of ab_eoi")
Exception: Failure "Syntax Error".
--> "Illegal begin": at least the first symbol was correct
--> nevertheless, the reported position is correct
--> The message used to be: "b" then EOI expected after "a" in [ab_eoi]

parse_string a_or_ab_eoi "a c" ;

File "", line 1, characters 0-1
Stream.Error("illegal begin of a_or_ab_eoi")
Exception: Failure "Syntax Error".
--> "Illegal begin": at least the first non-terminal was correct
--> the reported position is weird
--> I think the message used to be either: "b" expected after "a" in [a_or_ab]
or: EOI expected after [a_or_ab] in [a_or_ab_eoi]

parse_string c_a_or_ab_eoi "c a c" ;

File "", line 1, characters 2-3
Stream.Error("[a_or_ab] expected after "c" (in [c_a_or_ab_eoi])")
Exception: Failure "Syntax Error".
--> "[a_or_ab] expected": this is very confusing: there is a valid a_or_ab there, namely "a"

Additional information

Tested with Ocaml 3.10.0 from Fink unstable under MacOS X.

Strangely enough camlp4 parsing of Ocaml code still gives very precise error messages:

$ ocaml camlp4rf.cma
Objective Caml version 3.10.0

    Camlp4 Parsing version 3.10.0

1 + ;

Parse error: [expr] expected after [infix operator (level 2) (start with '+', '-')] (in [expr])

value foo = 1 and ;

Parse error: [binding] expected after "and" (in [binding])

value foo = 1 and bar ;

Parse error: [fun_binding] expected after [ipatt] (in [let_binding])

value foo = 1 and bar = ;

Parse error: [expr] expected after "=" (in [fun_binding])

File attachments

@vicuna
Copy link
Author

vicuna commented Jan 9, 2015

Comment author: @damiendoligez

PR transferred to the camlp4's github tracker:
camlp4/camlp4#62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant