Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004329OCamlCamlp4public2007-06-25 10:002013-07-29 15:19
Reporterbrunodefraine 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version3.10.0 
Target Version4.01.1+devFixed in Version 
Summary0004329: Gramlib syntax error messages are less precise, sometimes wrong
Descriptioncamlp4 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 "<string>") 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 "<string>", 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 "<string>", 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 "<string>", 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 InformationTested 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])
TagsNo tags attached.
Attached Files? file icon gram_msg.ml [^] (629 bytes) 2007-06-25 10:00 [Show Content]

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2007-06-25 10:00 brunodefraine New Issue
2007-06-25 10:00 brunodefraine File Added: gram_msg.ml
2007-11-10 15:12 xleroy Status new => assigned
2007-11-10 15:12 xleroy Assigned To => ertai
2012-07-11 16:07 doligez Target Version => 4.01.0+dev
2012-07-12 11:26 doligez Assigned To ertai =>
2012-07-31 13:37 doligez Target Version 4.01.0+dev => 4.00.1+dev
2012-09-15 00:03 doligez Status assigned => acknowledged
2012-09-15 00:03 doligez Target Version 4.00.1+dev => 4.01.0+dev
2013-07-29 15:19 doligez Target Version 4.01.0+dev => 4.01.1+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker