Commit | Line | Data |
---|---|---|
34e49164 C |
1 | { |
2 | open Parser_cocci_menhir | |
3 | module D = Data | |
4 | module Ast = Ast_cocci | |
5 | exception Lexical of string | |
6 | let tok = Lexing.lexeme | |
aa721442 | 7 | let inc_line _ = Lexer_cocci.line := !Lexer_cocci.line + 1 |
34e49164 C |
8 | } |
9 | (* ---------------------------------------------------------------------- *) | |
10 | (* tokens *) | |
11 | ||
190f1acf C |
12 | let oct = ['0'-'7'] |
13 | let hex = ['0'-'9' 'a'-'f' 'A'-'F'] | |
14 | ||
15 | let myrule = [^'\'''"''@''/''\n''\r''\011''\012']+ | |
34e49164 C |
16 | |
17 | rule 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. *) |
30 | and string = parse | |
31 | | '"' { "" } | |
32 | | (_ as x) { Common.string_of_char x ^ string lexbuf } | |
33 | | ("\\" _) as x { x ^ string lexbuf } | |
190f1acf C |
34 | |
35 | and 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 } |