Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005068OCamlOCaml generalpublic2010-06-08 12:272012-09-27 18:04
Reporteredwin 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version3.11.2 
Target VersionlaterFixed in Version 
Summary0005068: ocamlc/camlp4 should give better error messages for syntax errors
Descriptionocamlc often just gives a "Syntax error", and even though it prints line/column range it is not immediately obvious what is wrong.
It would be useful if a more descriptive error message was given instead of a generic "Syntax error".

The ocaml toplevel, and camlp4 is better sometimes when it comes to syntax errors, however their messages aren't very user friendly either.

Here is an example:
module foo = struct
 type t = int
end;;

$ ocamlc test.ml
File "test.ml", line 1, characters 7-10:
Error: Syntax error

An experienced ocaml programmer might know its due to the lowercase identifier, for others its not so clear what is wrong.

camlp4 is slightly better, at least it gives more detail about what is wrong,
however one can't ascertain that it is the lowercase first letter just from the message. The error location is wrong for camlp4 also:
$ camlp4o test.ml
File "test.ml", line 1, characters 0-6:
Parse error: "rec" or "type" or [a_UIDENT] expected after "module" (in [str_item]
Additional InformationIt would be nice if ocamlc/camlp4 could give a message like:
File "test.ml", line1, characters 7-10:
Parse error: "rec" or "type" or identifier with uppercase first letter expected after "module"
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0005570)
edwin (reporter)
2010-06-23 10:31

Here is an interesting idea on how to give better syntax errors, without having to edit the grammar parser (or its tables):
http://research.swtch.com/2010/01/generating-good-syntax-errors.html [^]

Basically you give it an example of a syntax error and the message, and it determines which state your parser would reach for that syntax error, and use your error message there instead of the default "Syntax Error".

Perhaps this could be adapted to OCaml's parsers?

- Issue History
Date Modified Username Field Change
2010-06-08 12:27 edwin New Issue
2010-06-23 10:31 edwin Note Added: 0005570
2011-06-01 23:31 doligez Status new => acknowledged
2012-07-10 20:20 doligez Target Version => 4.01.0+dev
2012-07-31 13:36 doligez Target Version 4.01.0+dev => 4.00.1+dev
2012-09-18 13:26 doligez Target Version 4.00.1+dev => later
2012-09-27 18:04 doligez Category Incoming => OCaml general


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker