Coccinelle release 0.2.5-rc8
[bpt/coccinelle.git] / parsing_cocci / lexer_script.mll
index 1cab41c..d731460 100644 (file)
@@ -1,5 +1,7 @@
 (*
- * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
+ * Copyright 2010, INRIA, University of Copenhagen
+ * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
+ * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
  * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
  * This file is part of Coccinelle.
  *
@@ -31,7 +33,10 @@ let inc_line _ = Lexer_cocci.line := !Lexer_cocci.line + 1
 (* ---------------------------------------------------------------------- *)
 (* tokens *)
 
-let myrule = [^'"''@''/''\n''\r''\011''\012']+
+let oct = ['0'-'7']
+let hex = ['0'-'9' 'a'-'f' 'A'-'F']
+
+let myrule = [^'\'''"''@''/''\n''\r''\011''\012']+
 
 rule token = parse
   | myrule { TScriptData (tok lexbuf) }
@@ -41,6 +46,7 @@ rule token = parse
   | "/"  { TScriptData (tok lexbuf) }
   | "//" [^ '\n']* { token lexbuf } (* skip SmPL comments *)
   | '"'  { TScriptData (Printf.sprintf "\"%s\"" (string lexbuf)) }
+  | "'"  { TScriptData (Printf.sprintf "'%s'" (char lexbuf)) }
   | eof  { EOF }
   | _ { raise (Lexical ("unrecognised symbol, in token rule:"^tok lexbuf)) }
 
@@ -49,3 +55,9 @@ and string  = parse
   | '"'                 { "" }
   | (_ as x)            { Common.string_of_char x ^ string lexbuf }
   | ("\\" _) as x       { x ^ string lexbuf }
+
+and char = parse
+  | (_ as x) "'"                                     { String.make 1 x }
+  | (("\\" (oct | oct oct | oct oct oct)) as x  "'") { x }
+  | (("\\x" (hex | hex hex)) as x  "'")       { x }
+  | (("\\" _ ) as x "'") { x }