List Info

Thread: "ocaml_beginners"::[] matching a character at the beginning of a line in mll file




"ocaml_beginners"::[] matching a character at the beginning of a line in mll file
user name
2006-11-24 17:37:32

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 ?

Thanks
François Colonna

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] matching a character at the beginning of a line in mll file
user name
2006-11-24 21:57:07

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 ":&quot; 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 ":&quot;.
You can then reparse them with ocamllex if you think it's appropriate.

Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )