-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathpattern.treetop
61 lines (55 loc) · 845 Bytes
/
pattern.treetop
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
grammar Pattern
rule choose
first:concatenate_or_empty '|' rest:choose {
def to_ast
Choose.new(first.to_ast, rest.to_ast)
end
}
/
concatenate_or_empty
end
rule concatenate_or_empty
concatenate / empty
end
rule concatenate
first:repeat rest:concatenate {
def to_ast
Concatenate.new(first.to_ast, rest.to_ast)
end
}
/
repeat
end
rule empty
'' {
def to_ast
Empty.new
end
}
end
rule repeat
brackets '*' {
def to_ast
Repeat.new(brackets.to_ast)
end
}
/
brackets
end
rule brackets
'(' choose ')' {
def to_ast
choose.to_ast
end
}
/
literal
end
rule literal
[a-z] {
def to_ast
Literal.new(text_value)
end
}
end
end