Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005068OCamlOCaml generalpublic2010-06-08 12:272013-11-20 00:36
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
parent of 0005770resolvedfrisch Syntax error messages involving unclosed parens are sometimes incorrect 
parent of 0003772acknowledged That #%$! syntax error two functions down 
parent of 0006061acknowledged Confusing error message when parentheses enclose an invalid expression 
parent of 0005270acknowledged Ocaml parser error are not meaningfull most of the time 
parent of 0006162acknowledged Confusing error message when the user name a variable as an existing alphabetic infix operator 
has duplicate 0006244closedgasche "Syntax Error" messages should be more descriptive 
Not all the children of this issue are yet resolved or closed.

-  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?
(0009675)
gasche (developer)
2013-07-02 16:32

I recently became interested in the question of error messages as well -- partly because of Daniel B├╝nzli's feedback on http://gallium.inria.fr/blog/making-it-easier-for-beginners-to-learn-ocaml/ [^] .

If nobody objects, I'm considering using this bug as a parent issue for sub-issues about confusing error messages. We could keep this one for discussion of general approaches to improve the situation, and report and handle specific issues on a case-by-case basis.

Given that the main parser (using by ocamlc/ocamlopt etc.) and Camlp{4,5} use completely different parser technology (L(AL)R for the compiler, LL(k) for Camlp4), the situation is very different -- in particular this is why Camlp{4,5} do a better job for now. I'm personally more interested in focusing on the compiler part, as it is what most users will see.
(0010159)
nicolas_boulay (reporter)
2013-08-12 14:42

http://gallium.inria.fr/blog/making-it-easier-for-beginners-to-learn-ocaml/ [^] give nice advice on ocaml tool.

I would add that a "endif" keyword will be great if related always to the inner most if-clause, in case of composed if-clause, it could be hard to read without a lot of parenthesis.

A build-in efficient hash will be great. List are nice, but not suffisant for large data set. Map functor make complex looking code.

- 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
2013-07-02 16:22 gasche Relationship added parent of 0005770
2013-07-02 16:22 gasche Relationship added parent of 0003772
2013-07-02 16:28 gasche Relationship added parent of 0006061
2013-07-02 16:32 gasche Note Added: 0009675
2013-07-29 08:05 gasche Relationship added parent of 0005270
2013-08-12 14:42 nicolas_boulay Note Added: 0010159
2013-09-05 17:43 gasche Relationship added parent of 0006162
2013-11-20 00:36 gasche Relationship added has duplicate 0006244


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker