List Info

Thread: "ocaml_beginners"::[] printing line numbers in ocamlyacc generated parsers




"ocaml_beginners"::[] printing line numbers in ocamlyacc generated parsers
country flaguser name
United States
2007-07-23 17:04:23

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

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] printing line numbers in ocamlyacc generated parsers
country flaguser name
United Kingdom
2007-07-23 17:40:52

On Monday 23 July 2007 23:04:23 Ashish Agarwal wrote:
> 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.

With ocamlyacc the easiest way is to count newlines in the lexer. However, you
might be interested in the new camlp4 parser which introduces "scrap your
boilerplate" from the Haskell world to OCaml, injecting line and character
count information into every action in the parser.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )