[
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: | Damien Pous <Damien.Pous@e...> |
| Subject: | Re: [Caml-list] Calling parser from inside a parser rule |
hi,
why don't you recurse before the parser level ?
lexer.mll:
<<
{ type token = [`Print | `Arf | `Eof] }
let blank = [' ' '\r' '\t' '\n']*
let word = [ 'a'-'z' '.' ]*
rule token = parse
| blank { token lexbuf }
| "#include" blank '"' (word as s) '"' { `Include s }
| "print" { `Print }
| "arf" { `Arf }
(* ... *)
| eof { `Eof }
>>
reclexer.mll
<<
let token lexbuf: unit -> Lexer.token =
let acc = ref [lexbuf] in
let rec aux () = match !acc with
| [] -> `Eof
| (x::q) as l ->
match Lexer.token x with
| `Include s -> acc := (Lexing.from_channel (open_in s))::l; aux()
| `Eof -> acc := q; aux()
| #Lexer.token as t -> t
in aux
>>
let t = token (Lexing.from_channel (open_in "toto"));;
t();;
t();;
...
of course you have to handle cyclic includes...
damien
On Sun, 19 Sep 2004 08:50:42 -0700
James Lamanna <jamesl@appliedminds.com> wrote:
> Essentially.
> I want to be able to recurse into my parser.
-------------------
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