caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Le Normand <rathereasy@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] lexer errors
Date: Fri, 22 Jun 2012 18:14:43 -0700	[thread overview]
Message-ID: <CAK0y-35xUbr6p_k8jd1kEZoTz-NTOROori--DYYMQ3u8w8daBg@mail.gmail.com> (raw)

How can I get some decent lexer error reporting?

Here's my program:


{
  open Lexing
}

rule lex = parse
  | "foo" {()}
  | "\n" {lex lexbuf}

{
  let main () =
    let lexbuf = from_channel stdin in
      try
	let rec loop () =
	  let x = lex lexbuf in
	    loop x
	in
	  loop ()
      with
	| _ ->
	    let x = lexbuf.Lexing.lex_curr_p in
	      Printf.printf
		"line %d, character %d\n"
		x.pos_lnum (x.pos_cnum - x.pos_bol)

  let _ = main ()
}

running:

	ocamlc -I ~/ocaml/ ~/ocaml/test_lexer2.ml -o ~/ocaml/test.o
	echo foo > ~/temp.txt
	echo bar >> ~/temp.txt
	~/ocaml/test.o < ~/temp.txt

outputs the incorrect line:

       line 1, character 4

(Should be line 2, character 1)

             reply	other threads:[~2012-06-23  1:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-23  1:14 Jacques Le Normand [this message]
2012-06-23  6:57 ` Mehdi Dogguy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAK0y-35xUbr6p_k8jd1kEZoTz-NTOROori--DYYMQ3u8w8daBg@mail.gmail.com \
    --to=rathereasy@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).