Coccinelle release 0.2.5-rc9
[bpt/coccinelle.git] / parsing_cocci / lexer_script.mll
CommitLineData
34e49164
C
1{
2open Parser_cocci_menhir
3module D = Data
4module Ast = Ast_cocci
5exception Lexical of string
6let tok = Lexing.lexeme
aa721442 7let inc_line _ = Lexer_cocci.line := !Lexer_cocci.line + 1
34e49164
C
8}
9(* ---------------------------------------------------------------------- *)
10(* tokens *)
11
190f1acf
C
12let oct = ['0'-'7']
13let hex = ['0'-'9' 'a'-'f' 'A'-'F']
14
15let myrule = [^'\'''"''@''/''\n''\r''\011''\012']+
34e49164
C
16
17rule token = parse
aa721442
C
18 | myrule { TScriptData (tok lexbuf) }
19 | ['\n' '\r' '\011' '\012'] { inc_line(); TScriptData (tok lexbuf) }
34e49164
C
20 | "@@" { TArobArob }
21 | "@" { TArob }
aa721442 22 | "/" { TScriptData (tok lexbuf) }
002099fc
C
23 | "//" [^ '\n']* { token lexbuf } (* skip SmPL comments *)
24 | '"' { TScriptData (Printf.sprintf "\"%s\"" (string lexbuf)) }
190f1acf 25 | "'" { TScriptData (Printf.sprintf "'%s'" (char lexbuf)) }
34e49164
C
26 | eof { EOF }
27 | _ { raise (Lexical ("unrecognised symbol, in token rule:"^tok lexbuf)) }
28
002099fc
C
29(* These are C strings. Perhaps they require some adjustment. *)
30and string = parse
31 | '"' { "" }
32 | (_ as x) { Common.string_of_char x ^ string lexbuf }
33 | ("\\" _) as x { x ^ string lexbuf }
190f1acf
C
34
35and char = parse
36 | (_ as x) "'" { String.make 1 x }
37 | (("\\" (oct | oct oct | oct oct oct)) as x "'") { x }
38 | (("\\x" (hex | hex hex)) as x "'") { x }
39 | (("\\" _ ) as x "'") { x }