Browse thread
[Caml-list] Lexing.lexeme_start_p broken?
- Scott Duckworth
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Scott Duckworth <duckwos@c...> |
| Subject: | [Caml-list] Lexing.lexeme_start_p broken? |
I can't seem to get the function Lexing.lexeme_start_p to return a
position with correct information in it. Here is my code (test.mll):
{ open Lexing }
rule scan = parse
eof { raise End_of_file }
| _ as x
{
let pos = lexeme_start_p lexbuf in
Printf.printf "ASCII %d at line %d col %d\n" (int_of_char x)
pos.pos_lnum pos.pos_bol;
scan lexbuf
}
{ try scan (from_channel stdin) with End_of_file -> () }
I do the following, but I always get incorrect output:
[duckwos@chef]$ ocamllex test.mll
3 states, 257 transitions, table size 1046 bytes
[duckwos@chef]$ ocamlc -o test test.ml
[duckwos@chef]$ ./test << EOF
> position
> does not
> change
> EOF
ASCII 112 at line 1 col 0
ASCII 111 at line 1 col 0
ASCII 115 at line 1 col 0
ASCII 105 at line 1 col 0
ASCII 116 at line 1 col 0
ASCII 105 at line 1 col 0
ASCII 111 at line 1 col 0
ASCII 110 at line 1 col 0
ASCII 10 at line 1 col 0
ASCII 100 at line 1 col 0
ASCII 111 at line 1 col 0
ASCII 101 at line 1 col 0
ASCII 115 at line 1 col 0
ASCII 32 at line 1 col 0
ASCII 110 at line 1 col 0
ASCII 111 at line 1 col 0
ASCII 116 at line 1 col 0
ASCII 10 at line 1 col 0
ASCII 99 at line 1 col 0
ASCII 104 at line 1 col 0
ASCII 97 at line 1 col 0
ASCII 110 at line 1 col 0
ASCII 103 at line 1 col 0
ASCII 101 at line 1 col 0
ASCII 10 at line 1 col 0
[duckwos@chef]$
Any ideas why this is happening? I get the same results even if I am
reading from an actual file opened with Lexing.from_file (open_in
"filename").
One more thing. How does the pos_fname field in the position type get
it's value if there is no way for the Lexing module to know the file
name? Am I missing something here?
Thanks in advance!
--
Scott Duckworth
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners