This repository has been archived by the owner on Jun 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idllexer.mll
118 lines (115 loc) · 3.39 KB
/
idllexer.mll
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{
open Lexing
open Idlparser
let next_line lexbuf = Lexing.new_line lexbuf
}
let decdigit=['0'-'9']
let hexdigit=['0'-'9' 'A' - 'F' 'a' - 'F']
let octdigit=['0'-'7']
let decint = '-'? ['1'-'9'] decdigit*
let hexint = '-'? '0' ['X' 'x'] hexdigit+
let octint = '0' octdigit*
let int = decint | hexint | octint
let float_no_exp = decdigit+ '.' decdigit* | '.' decdigit+
let float_exp_part = ['E' 'e'] ['+' '-']? decdigit+
let float = '-'? (float_no_exp float_exp_part? | decdigit+ float_exp_part)
let identifier = ['A'-'Z' 'a'-'z' '_'] ['0'-'9' 'A'-'Z' 'a'-'z' '_']*
let whitespace = ['\t''\r'' ']+
rule read = parse
| '#' identifier { skip_to_eol lexbuf }
| '\n' { next_line lexbuf; read lexbuf }
| whitespace { read lexbuf }
| '/' '*' { skip_comment lexbuf }
| '/' '/' { skip_to_eol lexbuf }
| "void" { Void }
| "valuetype" { Valuetype }
| "unsigned" { Unsigned }
| "unrestricted" { Unrestricted }
| "typedef" { Typedef }
| "true" { True }
| "stringifier" { Stringifier }
| '"' { read_string (Buffer.create 17) lexbuf }
| "static" { Static }
| "short" { Short }
| "setter" { Setter }
| "setraises" { SetRaises }
| "sequence" { Sequence }
| ";" { Semicolon }
| "readonly" { ReadOnly }
| "raises" { Raises }
| ")" { RPar }
| "]" { RBracket }
| "}" { RBrace }
| "?" { Question }
| "partial" { Partial }
| "optional" { Optional }
| "omittable" { Omittable }
| "octet" { Octet }
| "object" { Object }
| "or" { OR }
| "null" { Null }
| "NaN" { NaN }
| "module" { Module }
| "-" { Minus }
| "<" { Lt }
| "long" { Long }
| "legacycaller" { LegacyCaller }
| "(" { LPar }
| "[" { LBracket }
| "{" { LBrace }
| "interface" { Interface }
| "inherits" { Inherits }
| "inherit" { Inherit }
| "Infinity" { Infinity }
| "in" { In }
| "inout" { InOut }
| "implements" { Implements }
| ">" { Gt }
| "getter" { Getter }
| "getraises" { GetRaises }
| "float" { Float }
| "false" { False }
| "exception" { Exception }
| "=" { Equals }
| "enum" { Enum }
| "..." { Ellipsis }
| "::" { DoubleColon }
| "double" { Double }
| "dictionary" { Dictionary }
| "deleter" { Deleter }
| "Date" { Date }
| "DOMString" { DOMString }
| "creator" { Creator }
| "const" { Const }
| "," { Comma }
| ":" { Colon }
| "callback" { Callback }
| "byte" { Byte }
| "boolean" { Boolean }
| "attribute" { Attribute }
| "any" { Any }
| float { FloatValue (float_of_string (Lexing.lexeme lexbuf)) }
| int { IntegerValue (int_of_string (Lexing.lexeme lexbuf)) }
| identifier { Identifier (Lexing.lexeme lexbuf) }
| eof { EOF }
| _ as c {
Format.eprintf "%a: Unexpected character `%c'@."
Misc.pp_position (Lexing.lexeme_start_p lexbuf) c;
exit 1
}
and read_string buf = parse
| '\n' { next_line lexbuf; Buffer.add_char buf '\n'; read_string buf lexbuf }
| '"' { String (Buffer.contents buf) }
| [^'"''\n']* { Buffer.add_string buf (Lexing.lexeme lexbuf); read_string buf lexbuf }
| eof { failwith "Unterminated string" }
and skip_comment = parse
| '\n' { next_line lexbuf; skip_comment lexbuf }
| "*/" { read lexbuf }
| '*' [^'/''\n'] { skip_comment lexbuf }
| '*' '\n' { next_line lexbuf; skip_comment lexbuf }
| [^'*''\n']* { skip_comment lexbuf }
| eof { failwith "Unterminated comment" }
and skip_to_eol = parse
| '\n' { next_line lexbuf; read lexbuf }
| eof { EOF }
| [^'\n']* { skip_to_eol lexbuf }