caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Strange result with Lexing
@ 2015-04-02 15:22 Sébastien Dailly
  2015-04-02 15:42 ` Török Edwin
  2015-04-02 15:46 ` hugo
  0 siblings, 2 replies; 4+ messages in thread
From: Sébastien Dailly @ 2015-04-02 15:22 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

Hello,

I've found a strange result when calling Lexing.lexeme_start and 
Lexing.lexeme_end on DOS format file (with \r\n instead of \n).

The value returned by the two functions is wrong when the file is in DOS 
format (the result does not change when I convert the file in UNIX 
format, but this is what I expect).

I there something I misunderstood in the documentation ?

(I've compiled ocaml with opam on cygwin).

Regards,

-- 
Sébastien Dailly

[-- Attachment #2: lexer.mll --]
[-- Type: text/plain, Size: 509 bytes --]

{
  open Lexing
  open Parser

  exception SyntaxError of string * lexbuf
  
  let debug lexbuf =
    let open Lexing in
      Printf.printf "lexeme_start %d\nlexeme_end %d\n" 
        (Lexing.lexeme_start lexbuf)
        (Lexing.lexeme_end lexbuf)
}


let white = [' ' '\t']
let newline = "\n\r" | '\n' | '\r'


rule read = parse
  | white+   { read lexbuf }

  | "obj"   { debug lexbuf; OBJ }

  | newline {  read lexbuf }
  | eof     { EOF }
  | _       { raise (SyntaxError ("Unexpected char", lexbuf)) }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Strange result with Lexing
  2015-04-02 15:22 [Caml-list] Strange result with Lexing Sébastien Dailly
@ 2015-04-02 15:42 ` Török Edwin
  2015-04-02 15:46 ` hugo
  1 sibling, 0 replies; 4+ messages in thread
From: Török Edwin @ 2015-04-02 15:42 UTC (permalink / raw)
  To: caml-list

On 04/02/2015 06:22 PM, Sébastien Dailly wrote:
> Hello,
> 
> I've found a strange result when calling Lexing.lexeme_start and Lexing.lexeme_end on DOS format file (with \r\n instead of \n).
> 
> The value returned by the two functions is wrong when the file is in DOS format (the result does not change when I convert the file in UNIX format, but this is what I expect).
> 
> I there something I misunderstood in the documentation ?
> 
> (I've compiled ocaml with opam on cygwin).
> 

Do you use 'open_in' or 'open_in_bin' to read the file?

--Edwin


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Strange result with Lexing
  2015-04-02 15:22 [Caml-list] Strange result with Lexing Sébastien Dailly
  2015-04-02 15:42 ` Török Edwin
@ 2015-04-02 15:46 ` hugo
  2015-04-03  7:25   ` Sébastien Dailly
  1 sibling, 1 reply; 4+ messages in thread
From: hugo @ 2015-04-02 15:46 UTC (permalink / raw)
  To: Sébastien Dailly; +Cc: caml-list

I guess you're using `Lexing.from_channel` with and `open_in`.
If so, you might want to use `open_in_bin` instead.

http://www.cycle.org/manuals/cygwin/using-textbinary.html

On Thu, Apr 2, 2015 at 11:22 AM, Sébastien Dailly
<sebastien-ocaml@chimrod.com> wrote:
> Hello,
>
> I've found a strange result when calling Lexing.lexeme_start and
> Lexing.lexeme_end on DOS format file (with \r\n instead of \n).
>
> The value returned by the two functions is wrong when the file is in DOS
> format (the result does not change when I convert the file in UNIX format,
> but this is what I expect).
>
> I there something I misunderstood in the documentation ?
>
> (I've compiled ocaml with opam on cygwin).
>
> Regards,
>
> --
> Sébastien Dailly
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Strange result with Lexing
  2015-04-02 15:46 ` hugo
@ 2015-04-03  7:25   ` Sébastien Dailly
  0 siblings, 0 replies; 4+ messages in thread
From: Sébastien Dailly @ 2015-04-03  7:25 UTC (permalink / raw)
  To: hugo; +Cc: caml-list

Le 2015-04-02 17:46, hugo a écrit :
> I guess you're using `Lexing.from_channel` with and `open_in`.
> If so, you might want to use `open_in_bin` instead.
> 
> http://www.cycle.org/manuals/cygwin/using-textbinary.html
> 

Thanks a lot, I was getting crazy with this problem !

-- 
Sébastien Dailly

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-03  7:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-02 15:22 [Caml-list] Strange result with Lexing Sébastien Dailly
2015-04-02 15:42 ` Török Edwin
2015-04-02 15:46 ` hugo
2015-04-03  7:25   ` Sébastien Dailly

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).