Hi all. I cannot find any way to get my ocamlyacc parsers to print the
line number on which a parse error occurs. The message is always just
"syntax error", which is pretty useless.
You can define your own parse_error function, but that doesn't seem to
allow anything too useful. It's type is string -> unit, and the string
argument sent by the generated parser is always "syntax error". So I
don't see how redefining this function could allow a more informative
message. It seems this function should also take in a Lexing.position
argument (I believe the analogous function in SML's version of yacc
does just this.)
Other posts I have read [1], discuss how you can get position
information within a semantic action. That is fine if you want to
print out an error based on a check that you do within that action.
However, the question is how to print position information when the
generated parser encounters an error. Any ideas? Thank you.
[1] http://tech.groups.yahoo.com/group/ocaml_beginners/message/7355
.