Skip to content

ocamlc/camlp4 should give better error messages for syntax errors #5068

@vicuna

Description

@vicuna

Original bug ID: 5068
Reporter: @edwintorok
Status: acknowledged (set by @damiendoligez on 2011-06-01T21:31:56Z)
Resolution: open
Priority: normal
Severity: feature
Version: 3.11.2
Target version: later
Category: lexing and parsing
Has duplicate: #6244
Parent of: #3772 #5270 #5770 #6061 #6162 #6400 #6629 #7097 #7148
Monitored by: @hcarty

Bug description

ocamlc 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 information

It 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"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions