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: Matching start of input in lexer created with ocamllex
Hi,

I'd like to match the beginning of input (or beginning of line) in my
lexer.  Is there an easy way to do that?

I have a lexer that looks something like this (simplified):

rule initial = parse
  | '!' [' ' '\t']* "for" { FOR (current_loc ()) }
  | ident as id { IDENT (id, current_loc ()) }
  | '!' { BANG (current_loc ()) }

The !for token should only be matched at the beginning of a
line/input.  However, in the above lexer, there's nothing that
prevents !for from being matched in the middle of an input string.
This causes a problem: An input string containing !forbidXyz will be
lexed FOR, IDENT "bidXyz".  I'd like to lex it as BANG, IDENT
"forbidXyz".

Thank you for your help!

Janne