-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfthegrammar.tt
203 lines (174 loc) · 3.55 KB
/
sfthegrammar.tt
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
require "rubygems"
require "treetop"
grammar SFTheList
# root node
rule list
(show)*
{
def content
elements.map do |e|
e.content
end
end
}
end
# helper for whitespaces
rule whitespace
[\s]+ {
def content
[:whitespace]
end
}
end
rule show
date (weekday whitespace)? bands_and_venue_prefix? venue whitespace age_restriction notes "\n"?
{
def content
elements.map do |e|
if (defined? e.content )
e.content
else
e.text_value
end
end
end
}
end
# jul 4-6
# jun 30-jul 3
rule date
#month whitespace days (("-" / "/") (month whitespace)? days)?
(month / whitespace / days / [-/])*
{
def content
[:date, text_value]
end
}
end
rule month
("jan" / "feb" / "mar" / "apr" / "may" / "jun" / "jul" / "aug" / "sep" / "oct" / "nov" / "dec") {
def content
[:month, text_value]
end
}
end
# 7
# 7/8
# 4-6
rule days
[0-9]+
{
def content
[:days, text_value]
end
}
end
rule weekday
("sun" / "mon" / "tue" / "wed" / "thr" / "fri" / "sat")
{
def content
[:weekday, text_value]
end
}
end
rule bands_and_venue_prefix
bands venue_prefix
{
def content
# only return the bands
return elements[0].content
# elements.map {|e| e.content}
end
}
end
rule bands
(!venue_prefix .)*
{
def content
[:bands, text_value]
end
}
end
rule venue_prefix
(" at the " / " at ")
{
def content
[:venue_prefix, text_value]
end
}
end
rule venue
(!(whitespace age_restriction) .)*
{
def content
[:venue, text_value]
end
}
end
# ('a/a' / [\d]+ "+")
rule age_restriction
(([\d]+ "+") / "a/a")
{
def content
[:age_restriction, text_value]
end
}
end
rule notes
(!("\n" month) .)*
{
def content
[:notes, text_value]
end
}
end
# Used to parse the date again to just get the 1st day so the Time.parse() does not get confused with crazy dates
rule first_day
month whitespace days
end
# Try to parse the price
# $14
# free
# $12/$14
# $65-$250
rule price
(("$" [$\d\./-]+) / "free" )
end
# 7:30pm/8pm
# 7pm/7:30pm
# 9pm
# 5pm til 7:30pm
# 7pm/8pm
rule time
hour (("/" / " and " / " til ") time)? # not very strict
end
rule hour
([\d:]+ [apm]{2} / "noon" / "midnight")
end
# * recommendable Shows a/a all ages
# $ will probably sell out @ pit warning
# ^ under 21 must pay more # no ins/outs
rule annotations
[*$^@#\s]+
end
####################################################################################################################################
# Below is a set of rules I ended up not using in the grammar because their strict nature was hard to deal with the list's ambiguity
####################################################################################################################################
#
#
# # (Benefit for Mo's Kitchen & Glide programs)
# # (also dec 29/30)
# rule comments
# "(" (!")" .)* ")"
# end
#
# rule band_token
# [^,\s]+ {
# def content
# [:band_token, text_value]
# end
# }
# end
#
#
end