From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 149F57ED45 for ; Sat, 23 Jun 2012 03:14:45 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkcCAEMX5U/RVdm2mGdsb2JhbABFtV8IIgEBAQEBCAkNBxQngjECExkBGx4DEhBdAREBBQEGEEGHWgEDC5kCgmEJA4wjgnGEZQoZJw1XiHEBBQyOCIMcA4hHjGWOJD6EHg X-IronPort-AV: E=Sophos;i="4.77,461,1336341600"; d="scan'208";a="164105949" Received: from mail-lb0-f182.google.com ([209.85.217.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 Jun 2012 03:14:44 +0200 Received: by lbon10 with SMTP id n10so7308122lbo.27 for ; Fri, 22 Jun 2012 18:14:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=zIuimuMris5gCPPEZ8jK/S5/cp3RxTfyhLUUilHsfUI=; b=NCyueLRBadAdP/f5j5+XsFPPJv2zkTpRM21rgqtNB6xm0x+NavydEnoIb7zgFCfABe kuibW54tYS+nluEuxHQyw9L7awWcRkbHm3fXO4PBvFKHo86RRsbLV4HKv0MSupN49AmG OTRU51+AVsTlgqoOFkZOFg6ixUOTP6PQKNyfYDXgVQh062f3MEeydP9t2ZaNECKf2Hv+ QHpWlm9o7aWsRut5GyUzg9eRo5e68KRKiEso0hmiA8A2nOYU2WZ2FT7v65czIncNXLm6 FVm3NgEx1wGZtcBui0g2ly1L3k9a94pln1Zw/V6V9ABhZ2q8ynraWrOA+pNYy6LYkH0I T4zg== MIME-Version: 1.0 Received: by 10.112.82.197 with SMTP id k5mr2230607lby.98.1340414083646; Fri, 22 Jun 2012 18:14:43 -0700 (PDT) Received: by 10.114.0.169 with HTTP; Fri, 22 Jun 2012 18:14:43 -0700 (PDT) Date: Fri, 22 Jun 2012 18:14:43 -0700 Message-ID: From: Jacques Le Normand To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Subject: [Caml-list] lexer errors 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)