Version française
Home     About     Download     Resources     Contact us    
Browse thread
Matching start of input in lexer created with ocamllex
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Janne Hellsten <jjhellst@g...>
Subject: Re: [Caml-list] Matching start of input in lexer created with ocamllex
> let table = ["for", FOR; "while", WHILE]
> ..
> | space-not-newline + { WHITE }
> | newline { NEWLINE }
> | ident as id { try assoc id table with Not_found -> IDENT id }
>
> An alternative to the WHITE and NEWLINE tokens is a tail
> recursive call to the lexer:
>
> | space + { initial lexbuf }
>
> which just skips over the spaces.

I do have the latter construct in my lexer.  How does the above help
me match the beginning of line in the rule

  | '!' [' ' '\t']* "for" { FOR (current_loc ()) }

I'd like it to look like this:

  | "^!for" { FOR }

where ^ would denote the start of input.  To simplify my question, we
can assume there are no new line chars in my input.  This regexp:

'!' [' ' '\t']* "for"

could actually be simplified to

| "!for"

and I would still need to match the "beginning of input" somehow.

I must've missed your point.

Janne