Release coccinelle-0.2.2
[bpt/coccinelle.git] / parsing_cocci / lexer_script.mll
CommitLineData
9f8e26f4 1(*
ae4735db 2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
9f8e26f4
C
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
5 *
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
9 *
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
20 *)
21
22
34e49164
C
23{
24open Parser_cocci_menhir
25module D = Data
26module Ast = Ast_cocci
27exception Lexical of string
28let tok = Lexing.lexeme
aa721442 29let inc_line _ = Lexer_cocci.line := !Lexer_cocci.line + 1
34e49164
C
30}
31(* ---------------------------------------------------------------------- *)
32(* tokens *)
33
aa721442 34let myrule = [^'"''@''/''\n''\r''\011''\012']+
34e49164
C
35
36rule token = parse
aa721442
C
37 | myrule { TScriptData (tok lexbuf) }
38 | ['\n' '\r' '\011' '\012'] { inc_line(); TScriptData (tok lexbuf) }
34e49164
C
39 | "@@" { TArobArob }
40 | "@" { TArob }
aa721442 41 | "/" { TScriptData (tok lexbuf) }
002099fc
C
42 | "//" [^ '\n']* { token lexbuf } (* skip SmPL comments *)
43 | '"' { TScriptData (Printf.sprintf "\"%s\"" (string lexbuf)) }
34e49164
C
44 | eof { EOF }
45 | _ { raise (Lexical ("unrecognised symbol, in token rule:"^tok lexbuf)) }
46
002099fc
C
47(* These are C strings. Perhaps they require some adjustment. *)
48and string = parse
49 | '"' { "" }
50 | (_ as x) { Common.string_of_char x ^ string lexbuf }
51 | ("\\" _) as x { x ^ string lexbuf }