caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Matching start of input in lexer created with ocamllex
@ 2007-04-05 14:37 Janne Hellsten
  2007-04-05 19:55 ` [Caml-list] " skaller
  0 siblings, 1 reply; 5+ messages in thread
From: Janne Hellsten @ 2007-04-05 14:37 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-04-06 20:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20070405205804.90509BC76@yquem.inria.fr>
2007-04-06  7:40 ` [Caml-list] Matching start of input in lexer created with ocamllex David Allsopp
2007-04-06 20:14   ` Janne Hellsten
2007-04-05 14:37 Janne Hellsten
2007-04-05 19:55 ` [Caml-list] " skaller
2007-04-05 20:58   ` Janne Hellsten
2007-04-06  5:52     ` skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).