On Fri, 24 Nov 2006, Francois Colonna wrote:
> Hello
>
> in camllex (.mll file)
> could somebody give me an example of a regular expression
> matching at the beginning of a line a ':' followed by a string ?
Unfortunately, beginning-of-line assertions are not available in
ocamllex. You have to consume the 'n' characters, and make a special case
for the first line of the file. That's not very natural.
If your file is a sequence of blocks that start by this pattern, you may
want to use a first pass where you split the file into blocks, and a second
pass where you parse each block, using ocamllex or anything that you see
fit.
Personally, I would use micmatch for the first step:
RE string = '"' ([^'"'] | "\"")* '"'
let separate_blocks = SPLIT bol ":" blank* < string >
let blocks_of_file file = separate_blocks (Micmatch.Text.file_contents file)
blocks_of_file returns a list of strings that include the string but not
the starting ":".
You can then reparse them with ocamllex if you think it's appropriate.
Martin
--
Martin Jambon, PhD
http://martin.jambon.free.fr
.