-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathy_parser.treetop
More file actions
65 lines (53 loc) · 987 Bytes
/
y_parser.treetop
File metadata and controls
65 lines (53 loc) · 987 Bytes
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
grammar Y
rule topmost
expression*
{
def bnf
self.elements.each {
|p|
puts "#{p.rule_name.text_value} : #{p.rewrite_list}"
}
end
}
end
rule expression
white_space? rule_name white_space? ':' rewrite_list ';' space?
end
rule rewrite_list
rule_list:(space? rewrite_name)* space?
{
def to_s
rule_list.elements.collect {|rew| rew.rewrite_name.text_value }.join(" ").gsub("| ", "|\n\t")
end
}
end
rule rule_name
[a-zA-Z] [a-zA-Z0-9_]*
end
rule rewrite_name
identifier / quoted_identifier
end
rule identifier
[%|a-zA-Z] [a-zA-Z0-9_]*
end
rule quoted_identifier
'\'' [^\']* '\''
end
rule space
(white_space / c_block)*
{
def value
nil
end
}
end
rule white_space
[\s]+
end
rule c_block
'{' non_curly (c_block non_curly)* '}'
end
rule non_curly
[^{}]*
end
end