* ocamlyacc and error messages
@ 1999-09-06 12:02 David Mentr'e
1999-09-07 7:00 ` Jean-Christophe Filliatre
0 siblings, 1 reply; 2+ messages in thread
From: David Mentr'e @ 1999-09-06 12:02 UTC (permalink / raw)
To: caml-list
Hello/Bonjour,
[[ Français (résumé) ]]
Comment donner le numéro de ligne et le point d'échec dans une grammaire
d'un parser généré par ocamlyacc ?
[[ English ]]
What is the simplest way to report an error in a parser generated by
ocamlyacc ?
I would like to report :
1. line number in parsed file
2. failing rule number in grammar
The point (1) is essential for me. Right know, I have a 'Fatal error:
uncaught exception Parsing.Parse_error' not very meaningful. :) I would
prefer have a message like 'parse error on line N in source file,
stucked in grammar rule foo:'.
I've looked at FAQs, mailing-list archive, ocaml sources and ocamlyacc
documentation but did not found very useful info :
. nothing in faqs
. mailing-list : an old message related to caml (not *o*caml)
http://caml.inria.fr/caml-list/0061.html
. ocaml parser in too complicated (rich error handling)
. ocamlyacc doc is minimal
Thanks for any pointer,
david
d.
--
David.Mentre@irisa.fr -- http://www.irisa.fr/prive/dmentre/
Opinions expressed here are only mine.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: ocamlyacc and error messages
1999-09-06 12:02 ocamlyacc and error messages David Mentr'e
@ 1999-09-07 7:00 ` Jean-Christophe Filliatre
0 siblings, 0 replies; 2+ messages in thread
From: Jean-Christophe Filliatre @ 1999-09-07 7:00 UTC (permalink / raw)
To: David Mentr'e; +Cc: caml-list
> Comment donner le numéro de ligne et le point d'échec dans une grammaire
> d'un parser généré par ocamlyacc ?
>
> What is the simplest way to report an error in a parser generated by
> ocamlyacc ?
The module Parsing of the ocaml standard library provides two functions
======================================================================
val symbol_start : unit -> int
val symbol_end : unit -> int
======================================================================
to get the start and end positions of the left-hand side of the
grammar rule that matched (with a ocamlyacc grammar). Those positions
are characters count from the beginning of the file. You can store
those informations in your syntax tree, together with the name of the
rule if you want.
Then, if you want to indicate the corresponding line in the file when
an error occurs, one possible solution is to re-scan the file from the
beginning, counting newline characters until the desired position is
found. It is the solution used by the ocaml parser. Have a look in
ocaml sources (directory parsing/) for more informations.
Another solution is to count the lines in your lexer, in a reference,
and to store that information in your syntax tree when building it.
--
Jean-Christophe FILLIATRE
mailto:Jean-Christophe.Filliatre@lri.fr
http://www.lri.fr/~filliatr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-09-07 9:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-06 12:02 ocamlyacc and error messages David Mentr'e
1999-09-07 7:00 ` Jean-Christophe Filliatre
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox