coccinelle release 0.2.5
[bpt/coccinelle.git] / parsing_cocci / lexer_script.mll
index 5ed42f9..d731460 100644 (file)
@@ -1,3 +1,27 @@
+(*
+ * 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.
+ *
+ * Coccinelle is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, according to version 2 of the License.
+ *
+ * Coccinelle is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Coccinelle.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The authors reserve the right to distribute this or future versions of
+ * Coccinelle under other licenses.
+ *)
+
+
 {
 open Parser_cocci_menhir
 module D = Data
@@ -9,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) }
@@ -19,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)) }
 
@@ -27,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 }