-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.mll
More file actions
115 lines (105 loc) · 4.03 KB
/
lexer.mll
File metadata and controls
115 lines (105 loc) · 4.03 KB
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
{
open Parser
open Errs
exception Eof
exception Ex
}
rule
token = parse
("\n# " ((['0' - '9']+) as line_no) " " (('"' [^ '"']* '"') as s) (([^ '\n']* ) )) as z
{
Lexing.new_line(lexbuf);
if String.length(s) > 5 && (String.sub s (String.length(s) - 5) 4) = "ppml" then
let _ = end_line := (lexbuf.Lexing.lex_curr_p).Lexing.pos_lnum - int_of_string(line_no) + 2 in
let _ = h_file := s in
WHITESPACE(z)
else
WHITESPACE(z ^ (String.concat "" ((until_preprocml lexbuf)) ))
}
| ("# " ((['0' - '9']+) as line_no) " " (('"' [^ '"']* '"') as s) (([^ '\n']* ) )) as z
{
if String.length(s) > 5 && (String.sub s (String.length(s) - 5) 4) = "ppml" then
let _ = end_line := (lexbuf.Lexing.lex_curr_p).Lexing.pos_lnum - int_of_string(line_no) + 2 in
let _ = h_file := s in
WHITESPACE(z)
else
WHITESPACE(z ^ (String.concat "" ((until_preprocml lexbuf)) ))
}
| "\n" { Lexing.new_line(lexbuf); WHITESPACE("\n") }
| [' ' '\t']+ as s { WHITESPACE(s) }
| "@type" { TYPE }
| "@match" { MATCH }
| "typename" { TYPENAME }
| "public" { PUBLIC }
| "private" { PRIVATE }
| "namespace" { NAMESPACE }
| "template" { TEMPLATE }
| "class" { CLASS }
| "const" { CONST }
| "with" { WITH }
| "and" { AND }
| "as" { AS }
| "of" { OF }
| "/*" as s { WHITESPACE(s ^ comment lexbuf) }
| "//" ([^ '\n'])* "\n" as s { Lexing.new_line(lexbuf); WHITESPACE(s) }
| ('#' [^ '\n']* "\n") as s { Lexing.new_line(lexbuf);
WHITESPACE(s) }
| ('#' [^ '\n']*) as s { WHITESPACE(s) }
| '"' ([^ '"' '\\'] | ('\\' _))* '"' as s { TOKEN(s) }
| '\'' ([^ '\''] | "\\\'")* '\'' as s { TOKEN(s) }
| (['a'-'z' 'A'-'Z' '_']+ ['A'-'Z' 'a'-'z' '0'-'9' '_' ]*) as s { IDENT(s) }
| ('-')? ['0'-'9']+ as s { TOKEN(s) }
| "->>" { MATCH_BECOMES }
| "-|" { MINUSPIPE }
| ("<<=" | ">>=" | "++=" | "--=" | "&&=" | "||=") as s { TOKEN(s) }
| ("!=" | "<=" | "==" | ">=" | "+=" | "-=" | "&=" | "|=" | "/=" | "*=" | "%=" | "^=" ) as s { TOKEN(s) }
| ("<<" | ">>" | "++" | "--" | "&&" | "||") as s { TOKEN(s) }
| "::" { SCOPE }
| "=" { EQ }
| "*" { STAR }
| "&" { AMP }
| ("<") { LT }
| (">") { GT }
| ("!" | "~" | "\\" | "|" | "." | "*" | "/" | "-" | "+" | "^" | "&" | "%" | "?" | "???????") as s { TOKEN(s) }
| ':' { COLON }
| ',' { COMMA }
| ';' { SEMI }
| '(' { LPAREN }
| ')' { RPAREN }
| '{' { LBRACE }
| '}' { RBRACE }
| '[' { LBRACK }
| ']' { RBRACK }
| eof { EOF }
| _ {disp_error (unrecog_char1); raise Ex} (* '$' symbols, etc *)
and
comment = parse
"*/" as s { s }
| _ [^ '*' '/' '\n']* as s { s ^ comment lexbuf }
| '\n' { Lexing.new_line(lexbuf); "\n" ^ comment lexbuf }
| eof { disp_error (unterm_cmt);raise End_of_file (*print_string("reached end of file in comment!\n"); raise End_of_file*)}
and
until_preprocml = parse
("\n# " ((['0' - '9']+) as line_no) ' ' (('"' [^ '"']* '"') as s) (([^ '\n']* ) )) as z
{
Lexing.new_line (lexbuf);
if String.length(s) > 5 && (String.sub s (String.length(s) - 5) 4) = "ppml" then
let _ = end_line := (lexbuf.Lexing.lex_curr_p).Lexing.pos_lnum - int_of_string(line_no) + 2 in
let _ = h_file := s in
z :: []
else
z :: until_preprocml lexbuf
}
| ("# " ((['0' - '9']+) as line_no) ' ' (('"' [^ '"']* '"') as s) (([^ '\n']* ) )) as z
{
if String.length(s) > 5 && (String.sub s (String.length(s) - 5) 4) = "ppml" then
let _ = end_line := (lexbuf.Lexing.lex_curr_p).Lexing.pos_lnum - int_of_string(line_no) + 2 in
let _ = h_file := s in
z :: []
else
z :: until_preprocml lexbuf
}
| ("\n" [^ '\n']* ) as s
{ Lexing.new_line (lexbuf);
s :: until_preprocml lexbuf }
| eof { [] }