-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMusiclexer.mll
78 lines (73 loc) · 1.96 KB
/
Musiclexer.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
{ (*header*)
open Lexing
open Musicparser
let keyword_al = [
("priority",PRIORITY);
("Chord", CHORD);
("op",OP);
("root",ROOT);
("spec",SPEC);
("then",THEN);
("hasAbsNote",HASABSNOTE);
("hasRelNote",HASRELNOTE);
("end",END);
("sort",SORT);
("sorts",SORTS);
("pred",PRED);
("op",OPS);
("preds",PREDS);
("logic",LOGIC);
("not",NOT);
("suc",SUC);
("generated",GENERATED);
("generated",FREE)
]
}
let digit = ['0'-'9']
let letter = ['?' 'A'-'Z' '_' 'a'-'z']
let alphanum = digit | letter
let ident = letter alphanum*
let newline = ('\010' | '\013' | "\013\010")
rule token = parse
| [' ' '\n' '\t'] { token lexbuf }
| "x1" {INT(11)}
| ['0'-'9' 'x']+ as s { if s="x" then INT(10) else INT(int_of_string s) }
| "%%" {comment lexbuf;token lexbuf}
| "%(" {priority lexbuf;token lexbuf}
| "op" {rem lexbuf;token lexbuf}
| "pred" {rem lexbuf;token lexbuf}
| "ops" {rem lexbuf;token lexbuf}
| "preds" {rem lexbuf;token lexbuf}
| "forall" {logic lexbuf;token lexbuf}
| "generated" {logic lexbuf;token lexbuf}
| "free" {logic lexbuf;token lexbuf}
| "logic" {rem lexbuf;token lexbuf}
| "sorts" {rem lexbuf;token lexbuf}
| "sort" {rem lexbuf;token lexbuf}
| '=' {EQUALS}
| '(' { OPEN }
| ')' { CLOSE }
| ':' { COLON }
| ',' { COMMA }
| '%' { PERCENT }
| '.' { DOT }
| eof { EOF }
| ident {let s = Lexing.lexeme lexbuf in
try List.assoc s keyword_al
with Not_found -> IDENT(s)}
and comment = parse
| "%%" {comment lexbuf}
| newline {}
| eof {}
| _ {comment lexbuf}
and priority = parse
| "%(" {priority lexbuf}
| ")%" {}
| _ {priority lexbuf}
and rem = parse
| newline {}
| _ {rem lexbuf}
and logic = parse
| "%(" {comment lexbuf}
| _ {logic lexbuf}
{}