English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Question re: camlp4 parser
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-07-26 (00:11)
From: Paul Snively <psnively@m...>
Subject: Question re: camlp4 parser
Hash: SHA1

Hello everyone,

I'm beginning to explore some tasks in earnest. One of them is  
writing a simple .ini file parser. This seems like something that  
would fall easily within the LL(1) capabilities of the camlp4 parser  
keyword, but I'm having a bit of trouble remembering how to structure  

For example, I'd like a parser that matches one or more printable  
ASCII characters. Something that looks like:

let rec printable = parser [< '' '..'~'; x = printable >] -> x

This, of course, has two obvious problems:

1) On test data such as Stream.of_string "Test!\013" it raises  
Stream.Failure, no doubt because it has found the \013 which doesn't  
match the character range, i.e. it is, of course, not doing lookahead.

2) Even if that weren't the case, the resulting "x" would be missing  
the first matching character. What I really need is the accumulation  
of all of the characters.

It's just been too long since I've had to do LL(1), I think. I'm sure  
I'm overlooking something obvious. Or do I just need to go ahead and  
use ulex, even though I can't use it from the toplevel, which really  
annoys me?

Many thanks and best regards,
Paul Snively

Version: GnuPG v1.4.1 (Darwin)