Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] backslashes in ocamllex
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] backslashes in ocamllex

Rafael 'Dido' Sevilla writes:
 > Now I'm stuck again.  I'm revising the lexical analyzer for my compiler
 > to enable it to recognize escaped strings, with conventions different
 > from OCaml's.  Currently, I'm using this regex:
 > 
 > '\'' ("\\\\"|"\\'"|[^'\''])* '\''
 > 
 > in an attempt to recognize strings that begin and end with single
 > quotes, but may possibly include sequences like \' that represent
 > escaped quotes, and '\\' that represent escaped backslashes.  Of course,
 > this doesn't work, as I lately realized, because this string:
 > 
 > '\\' '\\'
 > 
 > looks like I'm escaping the second quote, so I wind up with an empty
 > token.  Any hints on how I'd go about doing this sort of thing?

This should work:

	'\'' ([^'\'' '\\'] | '\\' _)* '\''

i.e.  any backslash  in the  string must  be followed  by  a character
(whatever  its  interpretation  is).   You  can  be  more  precise  if
backslashes must  be followed  by \  or ' and  nothing else.  Then the
regexp is

	'\'' ([^'\'' '\\'] | '\\' ('\\' | '\''))* '\''

(For instance  ocaml strings conform to  the former, but  a warning is
emitted  whenever   the  character  following  \   has  no  particular
interpretation).

-- 
Jean-Christophe

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners