Version française
Home     About     Download     Resources     Contact us    
Browse thread
camlp4 stream parser syntax
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joel Reymont <joelr1@g...>
Subject: Re: camlp4 stream parser syntax
> Where can I read up on the syntax of the following in a camlp4  
> stream parser?
>
>  | [<' INT n >] -> Int n
>
> For example, where are [< ... >] described and why is the ' needed  
> in between?


To be more precise, I'm using camlp4 to parse a language into a non- 
OCaml AST.

I'm trying to figure out the meaning of [<, >], [[ and ]]

My ocamllex lexer is wrapped to make it look like a stream lexer  
(below) and I'm returning a tuple of (tok, loc) because I don't see  
another way of making token location available to the parser.

Still, I'm how to integrate the reporting of error location into ?? in  
something like this

  | [< 'Token.Kwd '('; e=parse_expr; 'Token.Kwd ')' ?? "expected ')'"  
 >] -> e

Would someone kindly shed light on this?

	Thanks in advance, Joel

P.S. ocamllex wrapper to return a' Stream.t

{
let from_lexbuf tab lb =
   let next _ =
     let tok = token tab lb in
     let loc = Loc.of_lexbuf lb in
     Some (tok, loc)
   in Stream.from next

let setup_loc lb loc =
   let start_pos = Loc.start_pos loc in
   lb.lex_abs_pos <- start_pos.pos_cnum;
   lb.lex_curr_p  <- start_pos

let from_string loc tab str =
   let lb = Lexing.from_string str in
   setup_loc lb loc;
   from_lexbuf tab lb

}

---
http://tinyco.de
Mac, C++, OCaml