blob: 6559d8e94e2e0f2edeb38ceb9294930b8e35bcb8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
(***********************************************************************)
(* *)
(* MLTk, Tcl/Tk interface of OCaml *)
(* *)
(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *)
(* projet Cristal, INRIA Rocquencourt *)
(* Jacques Garrigue, Kyoto University RIMS *)
(* *)
(* Copyright 2002 Institut National de Recherche en Informatique et *)
(* en Automatique and Kyoto University. All rights reserved. *)
(* This file is distributed under the terms of the GNU Library *)
(* General Public License, with the special exception on linking *)
(* described in file ../../../LICENSE. *)
(* *)
(***********************************************************************)
{
open Ppyac
exception Error of string
let linenum = ref 1
}
let blank = [' ' '\013' '\009' '\012']
let identchar =
['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9']
let lowercase = ['a'-'z' '\223'-'\246' '\248'-'\255' '_']
let uppercase = ['A'-'Z' '\192'-'\214' '\216'-'\222']
rule token = parse
blank + { token lexbuf }
| "##" [' ' '\t']* { directive lexbuf }
| ("#")? [^ '#' '\n']* '\n'? {
begin
let str = Lexing.lexeme lexbuf in
if String.length str <> 0 && str.[String.length str - 1] = '\n' then
begin
incr linenum
end;
OTHER (str)
end
}
| eof { EOF }
and directive = parse
| "ifdef" [' ' '\t']+ { IFDEF (ident lexbuf)}
| "ifndef" [' ' '\t']+ { IFNDEF (ident lexbuf)}
| "else" { ELSE }
| "endif" { ENDIF }
| "define" [' ' '\t']+* { DEFINE (ident lexbuf)}
| "undef" [' ' '\t']+ { UNDEF (ident lexbuf)}
| _ { raise (Error (Printf.sprintf "unknown directive at line %d" !linenum))}
and ident = parse
| lowercase identchar* | uppercase identchar*
{ Lexing.lexeme lexbuf }
| _ { raise (Error (Printf.sprintf "illegal identifier at line %d" !linenum)) }
|