Version française
Home     About     Download     Resources     Contact us    
Browse thread
camlp4 stream parser and reporting error location
[ 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: camlp4 stream parser and reporting error location
Assuming a simple Camlp4 parser that uses a ocamllex lexer wrapped in  
a stream,

let rec parse_primary = parser

   | [< 'INT n >] -> Int n
   | [< 'FLOAT n >] -> Float n
   | [< 'STRING n >] -> Str n
   | [< 'TRUE >] -> Bool true
   | [< 'FALSE >] -> Bool false

   | [< >] -> raise (Stream.Error "unknown token when expecting an  
expression.")

How do I report the error location?

Do I need to pass loc in with every token?

Then what happens in the error case where there's no token available?

	Thanks, Joel

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