-
Notifications
You must be signed in to change notification settings - Fork 13
/
glob_parser.mly
46 lines (36 loc) · 900 Bytes
/
glob_parser.mly
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
%parameter<Semantics : sig
type glob
val star: glob
val atom: string -> glob
val range: int -> int -> glob
val slash: string -> glob -> glob
val alt: glob list -> glob
type selector
val slash_select: string -> selector -> selector
val selectors: (bool * glob) list -> selector
end>
%start<Semantics.selector> main
%{
open Semantics
%}
%%
main:
| exprs EOF { $1 }
exprs:
| e = expr es = list( COMMA expr { $2 }) { selectors (e :: es) }
| xs = list( ATOM SLASH { $1 }) LBRACE g = exprs RBRACE
{
List.fold_right slash_select xs g
}
expr:
| PLUS g = glob { true, g }
| MINUS g = glob { false, g }
glob:
| STAR { star }
| x = ATOM { atom x }
| r = NUM_RANGE { range (fst r) (snd r) }
| LBRACE gs = globList RBRACE { alt gs }
| x = ATOM SLASH g = glob { slash x g }
globList:
| g = glob { [g] }
| g = glob COMMA gs = globList { g :: gs }