racc 1.4.13 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/COPYING +22 -515
- data/README.ja.rdoc +3 -4
- data/README.rdoc +6 -8
- data/Rakefile +30 -53
- data/bin/racc +39 -27
- data/ext/racc/com/headius/racc/Cparse.java +66 -23
- data/ext/racc/{cparse.c → cparse/cparse.c} +78 -47
- data/ext/racc/{extconf.rb → cparse/extconf.rb} +2 -1
- data/lib/racc/compat.rb +5 -4
- data/lib/racc/debugflags.rb +5 -4
- data/lib/racc/exception.rb +5 -4
- data/lib/racc/grammar.rb +25 -22
- data/lib/racc/grammarfileparser.rb +10 -8
- data/lib/racc/info.rb +6 -5
- data/lib/racc/iset.rb +6 -5
- data/lib/racc/logfilegenerator.rb +6 -5
- data/lib/racc/parser-text.rb +23 -24
- data/lib/racc/parser.rb +23 -24
- data/lib/racc/parserfilegenerator.rb +10 -10
- data/lib/racc/sourcetext.rb +5 -4
- data/lib/racc/state.rb +13 -12
- data/lib/racc/statetransitiontable.rb +7 -6
- data/rdoc/ja/command.ja.html +1 -1
- data/sample/array.y +1 -1
- data/sample/array2.y +1 -1
- data/sample/calc-ja.y +2 -2
- data/sample/calc.y +2 -2
- data/sample/conflict.y +1 -1
- data/sample/hash.y +1 -1
- data/sample/lalr.y +1 -1
- data/sample/lists.y +1 -1
- data/sample/syntax.y +1 -1
- data/sample/yyerr.y +1 -1
- data/test/assets/cadenza.y +170 -0
- data/test/assets/cast.y +926 -0
- data/test/assets/csspool.y +729 -0
- data/test/assets/edtf.y +583 -0
- data/test/assets/error_recovery.y +35 -0
- data/test/assets/huia.y +318 -0
- data/test/assets/intp.y +4 -4
- data/test/assets/journey.y +47 -0
- data/test/assets/liquor.y +313 -0
- data/test/assets/machete.y +423 -0
- data/test/assets/macruby.y +2197 -0
- data/test/assets/mailp.y +27 -27
- data/test/assets/mediacloth.y +599 -0
- data/test/assets/mof.y +649 -0
- data/test/assets/namae.y +302 -0
- data/test/assets/nasl.y +626 -0
- data/test/assets/nokogiri-css.y +255 -0
- data/test/assets/nullbug2.y +2 -2
- data/test/assets/opal.y +1807 -0
- data/test/assets/php_serialization.y +98 -0
- data/test/assets/recv.y +20 -20
- data/test/assets/riml.y +665 -0
- data/test/assets/ruby18.y +1943 -0
- data/test/assets/ruby19.y +2174 -0
- data/test/assets/ruby20.y +2350 -0
- data/test/assets/ruby21.y +2359 -0
- data/test/assets/ruby22.y +2381 -0
- data/test/assets/syntax.y +1 -1
- data/test/assets/tp_plus.y +622 -0
- data/test/assets/twowaysql.y +278 -0
- data/test/helper.rb +69 -41
- data/test/regress/cadenza +796 -0
- data/test/regress/cast +3428 -0
- data/test/regress/csspool +2314 -0
- data/test/regress/edtf +1794 -0
- data/test/regress/huia +1392 -0
- data/test/regress/journey +222 -0
- data/test/regress/liquor +885 -0
- data/test/regress/machete +833 -0
- data/test/regress/mediacloth +1463 -0
- data/test/regress/mof +1368 -0
- data/test/regress/namae +634 -0
- data/test/regress/nasl +2058 -0
- data/test/regress/nokogiri-css +836 -0
- data/test/regress/opal +6431 -0
- data/test/regress/php_serialization +336 -0
- data/test/regress/riml +3283 -0
- data/test/regress/ruby18 +6344 -0
- data/test/regress/ruby22 +7460 -0
- data/test/regress/tp_plus +1933 -0
- data/test/regress/twowaysql +556 -0
- data/test/test_chk_y.rb +1 -0
- data/test/test_racc_command.rb +186 -2
- data/test/test_scan_y.rb +1 -0
- data/test/testscanner.rb +1 -1
- metadata +60 -83
- data/DEPENDS +0 -4
- data/Manifest.txt +0 -101
- data/bin/racc2y +0 -195
- data/bin/y2racc +0 -339
- data/ext/racc/depend +0 -1
- data/fastcache/extconf.rb +0 -2
- data/fastcache/fastcache.c +0 -185
- data/misc/dist.sh +0 -31
- data/setup.rb +0 -1587
- data/tasks/doc.rb +0 -12
- data/tasks/email.rb +0 -55
data/test/assets/mailp.y
CHANGED
@@ -35,7 +35,7 @@ rule
|
|
35
35
|
@field.domain = mb.domain
|
36
36
|
}
|
37
37
|
;
|
38
|
-
|
38
|
+
|
39
39
|
datetime : day DIGIT ATOM DIGIT hour zone
|
40
40
|
# 0 1 2 3 4 5
|
41
41
|
# day month year
|
@@ -44,11 +44,11 @@ rule
|
|
44
44
|
result = (t + val[4] - val[5]).localtime
|
45
45
|
}
|
46
46
|
;
|
47
|
-
|
47
|
+
|
48
48
|
day : /* none */
|
49
49
|
| ATOM ','
|
50
50
|
;
|
51
|
-
|
51
|
+
|
52
52
|
hour : DIGIT ':' DIGIT
|
53
53
|
{
|
54
54
|
result = (result.to_i * 60 * 60) + (val[2].to_i * 60)
|
@@ -60,16 +60,16 @@ rule
|
|
60
60
|
+ val[4].to_i
|
61
61
|
}
|
62
62
|
;
|
63
|
-
|
63
|
+
|
64
64
|
zone : ATOM
|
65
65
|
{
|
66
66
|
result = ::TMail.zonestr2i( val[0] ) * 60
|
67
67
|
}
|
68
68
|
;
|
69
|
-
|
69
|
+
|
70
70
|
received : from by via with id for recvdatetime
|
71
71
|
;
|
72
|
-
|
72
|
+
|
73
73
|
from : /* none */
|
74
74
|
| FROM domain
|
75
75
|
{
|
@@ -84,28 +84,28 @@ rule
|
|
84
84
|
@field.from = Address.join( val[1] )
|
85
85
|
}
|
86
86
|
;
|
87
|
-
|
87
|
+
|
88
88
|
by : /* none */
|
89
89
|
| BY domain
|
90
90
|
{
|
91
91
|
@field.by = Address.join( val[1] )
|
92
92
|
}
|
93
93
|
;
|
94
|
-
|
94
|
+
|
95
95
|
via : /* none */
|
96
96
|
| VIA ATOM
|
97
97
|
{
|
98
98
|
@field.via = val[1]
|
99
99
|
}
|
100
100
|
;
|
101
|
-
|
101
|
+
|
102
102
|
with : /* none */
|
103
103
|
| WITH ATOM
|
104
104
|
{
|
105
105
|
@field.with.push val[1]
|
106
106
|
}
|
107
107
|
;
|
108
|
-
|
108
|
+
|
109
109
|
id : /* none */
|
110
110
|
| ID msgid
|
111
111
|
{
|
@@ -116,14 +116,14 @@ rule
|
|
116
116
|
@field.msgid = val[1]
|
117
117
|
}
|
118
118
|
;
|
119
|
-
|
119
|
+
|
120
120
|
for : /* none */
|
121
121
|
| FOR addr
|
122
122
|
{
|
123
123
|
@field.for_ = val[1].address
|
124
124
|
}
|
125
125
|
;
|
126
|
-
|
126
|
+
|
127
127
|
recvdatetime
|
128
128
|
: /* none */
|
129
129
|
| ';' datetime
|
@@ -131,7 +131,7 @@ rule
|
|
131
131
|
@field.date = val[1]
|
132
132
|
}
|
133
133
|
;
|
134
|
-
|
134
|
+
|
135
135
|
returnpath: '<' '>'
|
136
136
|
| routeaddr
|
137
137
|
{
|
@@ -173,7 +173,7 @@ rule
|
|
173
173
|
}
|
174
174
|
# | phrase ':' ';' { result = AddressGroup.new( result ) }
|
175
175
|
;
|
176
|
-
|
176
|
+
|
177
177
|
routeaddr : '<' route spec '>'
|
178
178
|
{
|
179
179
|
result = val[2]
|
@@ -184,22 +184,22 @@ rule
|
|
184
184
|
result = val[1]
|
185
185
|
}
|
186
186
|
;
|
187
|
-
|
187
|
+
|
188
188
|
route : at_domains ':'
|
189
189
|
;
|
190
|
-
|
190
|
+
|
191
191
|
at_domains: '@' domain { result = [ val[1] ] }
|
192
192
|
| at_domains ',' '@' domain { result.push val[3] }
|
193
193
|
;
|
194
|
-
|
194
|
+
|
195
195
|
spec : local '@' domain { result = Address.new( val[0], val[2] ) }
|
196
196
|
| local { result = Address.new( result, nil ) }
|
197
197
|
;
|
198
|
-
|
198
|
+
|
199
199
|
local : word { result = val }
|
200
200
|
| local '.' word { result.push val[2] }
|
201
201
|
;
|
202
|
-
|
202
|
+
|
203
203
|
domain : domword { result = val }
|
204
204
|
| domain '.' domword { result.push val[2] }
|
205
205
|
;
|
@@ -215,11 +215,11 @@ rule
|
|
215
215
|
result = val.join('')
|
216
216
|
}
|
217
217
|
;
|
218
|
-
|
218
|
+
|
219
219
|
phrase : word
|
220
220
|
| phrase word { result << ' ' << val[1] }
|
221
221
|
;
|
222
|
-
|
222
|
+
|
223
223
|
word : atom
|
224
224
|
| QUOTED
|
225
225
|
| DIGIT
|
@@ -228,7 +228,7 @@ rule
|
|
228
228
|
keys : phrase
|
229
229
|
| keys ',' phrase
|
230
230
|
;
|
231
|
-
|
231
|
+
|
232
232
|
enc : word
|
233
233
|
{
|
234
234
|
@field.encrypter = val[0]
|
@@ -258,7 +258,7 @@ rule
|
|
258
258
|
@field.sub = ''
|
259
259
|
}
|
260
260
|
;
|
261
|
-
|
261
|
+
|
262
262
|
params : /* none */
|
263
263
|
| params ';' TOKEN '=' value
|
264
264
|
{
|
@@ -281,7 +281,7 @@ rule
|
|
281
281
|
@field.disposition = val[0]
|
282
282
|
}
|
283
283
|
;
|
284
|
-
|
284
|
+
|
285
285
|
disp_params
|
286
286
|
: /* none */
|
287
287
|
| disp_params ';' disp_param
|
@@ -293,7 +293,7 @@ rule
|
|
293
293
|
@field.params[ val[0].downcase ] = val[2]
|
294
294
|
}
|
295
295
|
;
|
296
|
-
|
296
|
+
|
297
297
|
atom : ATOM
|
298
298
|
| FROM
|
299
299
|
| BY
|
@@ -302,7 +302,7 @@ rule
|
|
302
302
|
| ID
|
303
303
|
| FOR
|
304
304
|
;
|
305
|
-
|
305
|
+
|
306
306
|
end
|
307
307
|
|
308
308
|
|
@@ -382,7 +382,7 @@ module TMail
|
|
382
382
|
@scanner.scan @pass_array
|
383
383
|
end
|
384
384
|
end
|
385
|
-
|
385
|
+
|
386
386
|
def on_error( tok, val, vstack )
|
387
387
|
raise ParseError,
|
388
388
|
"\nparse error in '#{@field.name}' header, on token #{val.inspect}"
|
@@ -0,0 +1,599 @@
|
|
1
|
+
# Copyright (c) 2006 Pluron Inc.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# The parser for the MediaWiki language.
|
23
|
+
#
|
24
|
+
# Usage together with a lexer:
|
25
|
+
# inputFile = File.new("data/input1", "r")
|
26
|
+
# input = inputFile.read
|
27
|
+
# parser = MediaWikiParser.new
|
28
|
+
# parser.lexer = MediaWikiLexer.new
|
29
|
+
# parser.parse(input)
|
30
|
+
|
31
|
+
class MediaWikiParser
|
32
|
+
|
33
|
+
token TEXT BOLD_START BOLD_END ITALIC_START ITALIC_END LINK_START LINK_END LINKSEP
|
34
|
+
INTLINK_START INTLINK_END INTLINKSEP RESOURCESEP CHAR_ENT
|
35
|
+
PRE_START PRE_END PREINDENT_START PREINDENT_END
|
36
|
+
SECTION_START SECTION_END HLINE SIGNATURE_NAME SIGNATURE_DATE SIGNATURE_FULL
|
37
|
+
PARA_START PARA_END UL_START UL_END OL_START OL_END LI_START LI_END
|
38
|
+
DL_START DL_END DT_START DT_END DD_START DD_END TAG_START TAG_END ATTR_NAME ATTR_VALUE
|
39
|
+
TABLE_START TABLE_END ROW_START ROW_END HEAD_START HEAD_END CELL_START CELL_END
|
40
|
+
KEYWORD TEMPLATE_START TEMPLATE_END CATEGORY PASTE_START PASTE_END
|
41
|
+
|
42
|
+
|
43
|
+
rule
|
44
|
+
|
45
|
+
wiki:
|
46
|
+
repeated_contents
|
47
|
+
{
|
48
|
+
@nodes.push WikiAST.new(0, @wiki_ast_length)
|
49
|
+
#@nodes.last.children.insert(0, val[0])
|
50
|
+
#puts val[0]
|
51
|
+
@nodes.last.children += val[0]
|
52
|
+
}
|
53
|
+
;
|
54
|
+
|
55
|
+
contents:
|
56
|
+
text
|
57
|
+
{
|
58
|
+
result = val[0]
|
59
|
+
}
|
60
|
+
| bulleted_list
|
61
|
+
{
|
62
|
+
result = val[0]
|
63
|
+
}
|
64
|
+
| numbered_list
|
65
|
+
{
|
66
|
+
result = val[0]
|
67
|
+
}
|
68
|
+
| dictionary_list
|
69
|
+
{
|
70
|
+
list = ListAST.new(@ast_index, @ast_length)
|
71
|
+
list.list_type = :Dictionary
|
72
|
+
list.children = val[0]
|
73
|
+
result = list
|
74
|
+
}
|
75
|
+
| preformatted
|
76
|
+
{
|
77
|
+
result = val[0]
|
78
|
+
}
|
79
|
+
| section
|
80
|
+
{
|
81
|
+
result = val[0]
|
82
|
+
}
|
83
|
+
| tag
|
84
|
+
{
|
85
|
+
result = val[0]
|
86
|
+
}
|
87
|
+
| template
|
88
|
+
{
|
89
|
+
result = val[0]
|
90
|
+
}
|
91
|
+
| KEYWORD
|
92
|
+
{
|
93
|
+
k = KeywordAST.new(@ast_index, @ast_length)
|
94
|
+
k.text = val[0]
|
95
|
+
result = k
|
96
|
+
}
|
97
|
+
| PARA_START para_contents PARA_END
|
98
|
+
{
|
99
|
+
p = ParagraphAST.new(@ast_index, @ast_length)
|
100
|
+
p.children = val[1]
|
101
|
+
result = p
|
102
|
+
}
|
103
|
+
| LINK_START link_contents LINK_END
|
104
|
+
{
|
105
|
+
l = LinkAST.new(@ast_index, @ast_length)
|
106
|
+
l.link_type = val[0]
|
107
|
+
l.url = val[1][0]
|
108
|
+
l.children += val[1][1..-1] if val[1].length > 1
|
109
|
+
result = l
|
110
|
+
}
|
111
|
+
| PASTE_START para_contents PASTE_END
|
112
|
+
{
|
113
|
+
p = PasteAST.new(@ast_index, @ast_length)
|
114
|
+
p.children = val[1]
|
115
|
+
result = p
|
116
|
+
}
|
117
|
+
| INTLINK_START TEXT RESOURCESEP TEXT reslink_repeated_contents INTLINK_END
|
118
|
+
{
|
119
|
+
l = ResourceLinkAST.new(@ast_index, @ast_length)
|
120
|
+
l.prefix = val[1]
|
121
|
+
l.locator = val[3]
|
122
|
+
l.children = val[4] unless val[4].nil? or val[4].empty?
|
123
|
+
result = l
|
124
|
+
}
|
125
|
+
| INTLINK_START TEXT intlink_repeated_contents INTLINK_END
|
126
|
+
{
|
127
|
+
l = InternalLinkAST.new(@ast_index, @ast_length)
|
128
|
+
l.locator = val[1]
|
129
|
+
l.children = val[2] unless val[2].nil? or val[2].empty?
|
130
|
+
result = l
|
131
|
+
}
|
132
|
+
| INTLINK_START CATEGORY TEXT cat_sort_contents INTLINK_END
|
133
|
+
{
|
134
|
+
l = CategoryAST.new(@ast_index, @ast_length)
|
135
|
+
l.locator = val[2]
|
136
|
+
l.sort_as = val[3]
|
137
|
+
result = l
|
138
|
+
}
|
139
|
+
| INTLINK_START RESOURCESEP CATEGORY TEXT intlink_repeated_contents INTLINK_END
|
140
|
+
{
|
141
|
+
l = CategoryLinkAST.new(@ast_index, @ast_length)
|
142
|
+
l.locator = val[3]
|
143
|
+
l.children = val[4] unless val[4].nil? or val[4].empty?
|
144
|
+
result = l
|
145
|
+
}
|
146
|
+
| table
|
147
|
+
;
|
148
|
+
|
149
|
+
para_contents:
|
150
|
+
{
|
151
|
+
result = nil
|
152
|
+
}
|
153
|
+
| repeated_contents
|
154
|
+
{
|
155
|
+
result = val[0]
|
156
|
+
}
|
157
|
+
;
|
158
|
+
|
159
|
+
tag:
|
160
|
+
TAG_START tag_attributes TAG_END
|
161
|
+
{
|
162
|
+
if val[0] != val[2]
|
163
|
+
raise Racc::ParseError.new("XHTML end tag #{val[2]} does not match start tag #{val[0]}")
|
164
|
+
end
|
165
|
+
elem = ElementAST.new(@ast_index, @ast_length)
|
166
|
+
elem.name = val[0]
|
167
|
+
elem.attributes = val[1]
|
168
|
+
result = elem
|
169
|
+
}
|
170
|
+
| TAG_START tag_attributes repeated_contents TAG_END
|
171
|
+
{
|
172
|
+
if val[0] != val[3]
|
173
|
+
raise Racc::ParseError.new("XHTML end tag #{val[3]} does not match start tag #{val[0]}")
|
174
|
+
end
|
175
|
+
elem = ElementAST.new(@ast_index, @ast_length)
|
176
|
+
elem.name = val[0]
|
177
|
+
elem.attributes = val[1]
|
178
|
+
elem.children += val[2]
|
179
|
+
result = elem
|
180
|
+
}
|
181
|
+
;
|
182
|
+
|
183
|
+
tag_attributes:
|
184
|
+
{
|
185
|
+
result = nil
|
186
|
+
}
|
187
|
+
| ATTR_NAME tag_attributes
|
188
|
+
{
|
189
|
+
attr_map = val[2] ? val[2] : {}
|
190
|
+
attr_map[val[0]] = true
|
191
|
+
result = attr_map
|
192
|
+
}
|
193
|
+
| ATTR_NAME ATTR_VALUE tag_attributes
|
194
|
+
{
|
195
|
+
attr_map = val[2] ? val[2] : {}
|
196
|
+
attr_map[val[0]] = val[1]
|
197
|
+
result = attr_map
|
198
|
+
}
|
199
|
+
;
|
200
|
+
|
201
|
+
|
202
|
+
link_contents:
|
203
|
+
TEXT
|
204
|
+
{
|
205
|
+
result = val
|
206
|
+
}
|
207
|
+
| TEXT LINKSEP link_repeated_contents
|
208
|
+
{
|
209
|
+
result = [val[0]]
|
210
|
+
result += val[2]
|
211
|
+
}
|
212
|
+
;
|
213
|
+
|
214
|
+
|
215
|
+
link_repeated_contents:
|
216
|
+
repeated_contents
|
217
|
+
{
|
218
|
+
result = val[0]
|
219
|
+
}
|
220
|
+
| repeated_contents LINKSEP link_repeated_contents
|
221
|
+
{
|
222
|
+
result = val[0]
|
223
|
+
result += val[2] if val[2]
|
224
|
+
}
|
225
|
+
;
|
226
|
+
|
227
|
+
|
228
|
+
intlink_repeated_contents:
|
229
|
+
{
|
230
|
+
result = nil
|
231
|
+
}
|
232
|
+
| INTLINKSEP repeated_contents
|
233
|
+
{
|
234
|
+
result = val[1]
|
235
|
+
}
|
236
|
+
;
|
237
|
+
|
238
|
+
cat_sort_contents:
|
239
|
+
{
|
240
|
+
result = nil
|
241
|
+
}
|
242
|
+
| INTLINKSEP TEXT
|
243
|
+
{
|
244
|
+
result = val[1]
|
245
|
+
}
|
246
|
+
;
|
247
|
+
|
248
|
+
reslink_repeated_contents:
|
249
|
+
{
|
250
|
+
result = nil
|
251
|
+
}
|
252
|
+
| INTLINKSEP reslink_repeated_contents
|
253
|
+
{
|
254
|
+
result = val[1]
|
255
|
+
}
|
256
|
+
| INTLINKSEP repeated_contents reslink_repeated_contents
|
257
|
+
{
|
258
|
+
i = InternalLinkItemAST.new(@ast_index, @ast_length)
|
259
|
+
i.children = val[1]
|
260
|
+
result = [i]
|
261
|
+
result += val[2] if val[2]
|
262
|
+
}
|
263
|
+
;
|
264
|
+
|
265
|
+
repeated_contents: contents
|
266
|
+
{
|
267
|
+
result = []
|
268
|
+
result << val[0]
|
269
|
+
}
|
270
|
+
| repeated_contents contents
|
271
|
+
{
|
272
|
+
result = []
|
273
|
+
result += val[0]
|
274
|
+
result << val[1]
|
275
|
+
}
|
276
|
+
;
|
277
|
+
|
278
|
+
text: element
|
279
|
+
{
|
280
|
+
p = TextAST.new(@ast_index, @ast_length)
|
281
|
+
p.formatting = val[0][0]
|
282
|
+
p.contents = val[0][1]
|
283
|
+
result = p
|
284
|
+
}
|
285
|
+
| formatted_element
|
286
|
+
{
|
287
|
+
result = val[0]
|
288
|
+
}
|
289
|
+
;
|
290
|
+
|
291
|
+
table:
|
292
|
+
TABLE_START table_contents TABLE_END
|
293
|
+
{
|
294
|
+
table = TableAST.new(@ast_index, @ast_length)
|
295
|
+
table.children = val[1] unless val[1].nil? or val[1].empty?
|
296
|
+
result = table
|
297
|
+
}
|
298
|
+
| TABLE_START TEXT table_contents TABLE_END
|
299
|
+
{
|
300
|
+
table = TableAST.new(@ast_index, @ast_length)
|
301
|
+
table.options = val[1]
|
302
|
+
table.children = val[2] unless val[2].nil? or val[2].empty?
|
303
|
+
result = table
|
304
|
+
}
|
305
|
+
|
306
|
+
table_contents:
|
307
|
+
{
|
308
|
+
result = nil
|
309
|
+
}
|
310
|
+
| ROW_START row_contents ROW_END table_contents
|
311
|
+
{
|
312
|
+
row = TableRowAST.new(@ast_index, @ast_length)
|
313
|
+
row.children = val[1] unless val[1].nil? or val[1].empty?
|
314
|
+
result = [row]
|
315
|
+
result += val[3] unless val[3].nil? or val[3].empty?
|
316
|
+
}
|
317
|
+
| ROW_START TEXT row_contents ROW_END table_contents
|
318
|
+
{
|
319
|
+
row = TableRowAST.new(@ast_index, @ast_length)
|
320
|
+
row.children = val[2] unless val[2].nil? or val[2].empty?
|
321
|
+
row.options = val[1]
|
322
|
+
result = [row]
|
323
|
+
result += val[4] unless val[4].nil? or val[4].empty?
|
324
|
+
}
|
325
|
+
|
326
|
+
row_contents:
|
327
|
+
{
|
328
|
+
result = nil
|
329
|
+
}
|
330
|
+
| HEAD_START HEAD_END row_contents
|
331
|
+
{
|
332
|
+
cell = TableCellAST.new(@ast_index, @ast_length)
|
333
|
+
cell.type = :head
|
334
|
+
result = [cell]
|
335
|
+
result += val[2] unless val[2].nil? or val[2].empty?
|
336
|
+
}
|
337
|
+
| HEAD_START repeated_contents HEAD_END row_contents
|
338
|
+
{
|
339
|
+
cell = TableCellAST.new(@ast_index, @ast_length)
|
340
|
+
cell.children = val[1] unless val[1].nil? or val[1].empty?
|
341
|
+
cell.type = :head
|
342
|
+
result = [cell]
|
343
|
+
result += val[3] unless val[3].nil? or val[3].empty?
|
344
|
+
}
|
345
|
+
| CELL_START CELL_END row_contents
|
346
|
+
{
|
347
|
+
cell = TableCellAST.new(@ast_index, @ast_length)
|
348
|
+
cell.type = :body
|
349
|
+
result = [cell]
|
350
|
+
result += val[2] unless val[2].nil? or val[2].empty?
|
351
|
+
}
|
352
|
+
| CELL_START repeated_contents CELL_END row_contents
|
353
|
+
{
|
354
|
+
if val[2] == 'attributes'
|
355
|
+
result = []
|
356
|
+
else
|
357
|
+
cell = TableCellAST.new(@ast_index, @ast_length)
|
358
|
+
cell.children = val[1] unless val[1].nil? or val[1].empty?
|
359
|
+
cell.type = :body
|
360
|
+
result = [cell]
|
361
|
+
end
|
362
|
+
result += val[3] unless val[3].nil? or val[3].empty?
|
363
|
+
if val[2] == 'attributes' and val[3] and val[3].first.class == TableCellAST
|
364
|
+
val[3].first.attributes = val[1]
|
365
|
+
end
|
366
|
+
result
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
element:
|
371
|
+
TEXT
|
372
|
+
{ return [:None, val[0]] }
|
373
|
+
| HLINE
|
374
|
+
{ return [:HLine, val[0]] }
|
375
|
+
| CHAR_ENT
|
376
|
+
{ return [:CharacterEntity, val[0]] }
|
377
|
+
| SIGNATURE_DATE
|
378
|
+
{ return [:SignatureDate, val[0]] }
|
379
|
+
| SIGNATURE_NAME
|
380
|
+
{ return [:SignatureName, val[0]] }
|
381
|
+
| SIGNATURE_FULL
|
382
|
+
{ return [:SignatureFull, val[0]] }
|
383
|
+
;
|
384
|
+
|
385
|
+
formatted_element:
|
386
|
+
BOLD_START BOLD_END
|
387
|
+
{
|
388
|
+
result = FormattedAST.new(@ast_index, @ast_length)
|
389
|
+
result.formatting = :Bold
|
390
|
+
result
|
391
|
+
}
|
392
|
+
| ITALIC_START ITALIC_END
|
393
|
+
{
|
394
|
+
result = FormattedAST.new(@ast_index, @ast_length)
|
395
|
+
result.formatting = :Italic
|
396
|
+
result
|
397
|
+
}
|
398
|
+
| BOLD_START repeated_contents BOLD_END
|
399
|
+
{
|
400
|
+
p = FormattedAST.new(@ast_index, @ast_length)
|
401
|
+
p.formatting = :Bold
|
402
|
+
p.children += val[1]
|
403
|
+
result = p
|
404
|
+
}
|
405
|
+
| ITALIC_START repeated_contents ITALIC_END
|
406
|
+
{
|
407
|
+
p = FormattedAST.new(@ast_index, @ast_length)
|
408
|
+
p.formatting = :Italic
|
409
|
+
p.children += val[1]
|
410
|
+
result = p
|
411
|
+
}
|
412
|
+
;
|
413
|
+
|
414
|
+
bulleted_list: UL_START list_item list_contents UL_END
|
415
|
+
{
|
416
|
+
list = ListAST.new(@ast_index, @ast_length)
|
417
|
+
list.list_type = :Bulleted
|
418
|
+
list.children << val[1]
|
419
|
+
list.children += val[2]
|
420
|
+
result = list
|
421
|
+
}
|
422
|
+
;
|
423
|
+
|
424
|
+
numbered_list: OL_START list_item list_contents OL_END
|
425
|
+
{
|
426
|
+
list = ListAST.new(@ast_index, @ast_length)
|
427
|
+
list.list_type = :Numbered
|
428
|
+
list.children << val[1]
|
429
|
+
list.children += val[2]
|
430
|
+
result = list
|
431
|
+
}
|
432
|
+
;
|
433
|
+
|
434
|
+
list_contents:
|
435
|
+
{ result = [] }
|
436
|
+
list_item list_contents
|
437
|
+
{
|
438
|
+
result << val[1]
|
439
|
+
result += val[2]
|
440
|
+
}
|
441
|
+
|
|
442
|
+
{ result = [] }
|
443
|
+
;
|
444
|
+
|
445
|
+
list_item:
|
446
|
+
LI_START LI_END
|
447
|
+
{
|
448
|
+
result = ListItemAST.new(@ast_index, @ast_length)
|
449
|
+
}
|
450
|
+
| LI_START repeated_contents LI_END
|
451
|
+
{
|
452
|
+
li = ListItemAST.new(@ast_index, @ast_length)
|
453
|
+
li.children += val[1]
|
454
|
+
result = li
|
455
|
+
}
|
456
|
+
;
|
457
|
+
|
458
|
+
dictionary_list:
|
459
|
+
DL_START dictionary_term dictionary_contents DL_END
|
460
|
+
{
|
461
|
+
result = [val[1]]
|
462
|
+
result += val[2]
|
463
|
+
}
|
464
|
+
| DL_START dictionary_contents DL_END
|
465
|
+
{
|
466
|
+
result = val[1]
|
467
|
+
}
|
468
|
+
;
|
469
|
+
|
470
|
+
dictionary_term:
|
471
|
+
DT_START DT_END
|
472
|
+
{
|
473
|
+
result = ListTermAST.new(@ast_index, @ast_length)
|
474
|
+
}
|
475
|
+
| DT_START repeated_contents DT_END
|
476
|
+
{
|
477
|
+
term = ListTermAST.new(@ast_index, @ast_length)
|
478
|
+
term.children += val[1]
|
479
|
+
result = term
|
480
|
+
}
|
481
|
+
|
482
|
+
dictionary_contents:
|
483
|
+
dictionary_definition dictionary_contents
|
484
|
+
{
|
485
|
+
result = [val[0]]
|
486
|
+
result += val[1] if val[1]
|
487
|
+
}
|
488
|
+
|
|
489
|
+
{
|
490
|
+
result = []
|
491
|
+
}
|
492
|
+
|
493
|
+
dictionary_definition:
|
494
|
+
DD_START DD_END
|
495
|
+
{
|
496
|
+
result = ListDefinitionAST.new(@ast_index, @ast_length)
|
497
|
+
}
|
498
|
+
| DD_START repeated_contents DD_END
|
499
|
+
{
|
500
|
+
term = ListDefinitionAST.new(@ast_index, @ast_length)
|
501
|
+
term.children += val[1]
|
502
|
+
result = term
|
503
|
+
}
|
504
|
+
|
505
|
+
preformatted: PRE_START repeated_contents PRE_END
|
506
|
+
{
|
507
|
+
p = PreformattedAST.new(@ast_index, @ast_length)
|
508
|
+
p.children += val[1]
|
509
|
+
result = p
|
510
|
+
}
|
511
|
+
| PREINDENT_START repeated_contents PREINDENT_END
|
512
|
+
{
|
513
|
+
p = PreformattedAST.new(@ast_index, @ast_length)
|
514
|
+
p.indented = true
|
515
|
+
p.children += val[1]
|
516
|
+
result = p
|
517
|
+
}
|
518
|
+
;
|
519
|
+
|
520
|
+
section: SECTION_START repeated_contents SECTION_END
|
521
|
+
{ result = [val[1], val[0].length]
|
522
|
+
s = SectionAST.new(@ast_index, @ast_length)
|
523
|
+
s.children = val[1]
|
524
|
+
s.level = val[0].length
|
525
|
+
result = s
|
526
|
+
}
|
527
|
+
;
|
528
|
+
|
529
|
+
template: TEMPLATE_START TEXT template_parameters TEMPLATE_END
|
530
|
+
{
|
531
|
+
t = TemplateAST.new(@ast_index, @ast_length)
|
532
|
+
t.template_name = val[1]
|
533
|
+
t.children = val[2] unless val[2].nil? or val[2].empty?
|
534
|
+
result = t
|
535
|
+
}
|
536
|
+
;
|
537
|
+
|
538
|
+
template_parameters:
|
539
|
+
{
|
540
|
+
result = nil
|
541
|
+
}
|
542
|
+
| INTLINKSEP TEXT template_parameters
|
543
|
+
{
|
544
|
+
p = TemplateParameterAST.new(@ast_index, @ast_length)
|
545
|
+
p.parameter_value = val[1]
|
546
|
+
result = [p]
|
547
|
+
result += val[2] if val[2]
|
548
|
+
}
|
549
|
+
| INTLINKSEP template template_parameters
|
550
|
+
{
|
551
|
+
p = TemplateParameterAST.new(@ast_index, @ast_length)
|
552
|
+
p.children << val[1]
|
553
|
+
result = [p]
|
554
|
+
result += val[2] if val[2]
|
555
|
+
}
|
556
|
+
;
|
557
|
+
|
558
|
+
end
|
559
|
+
|
560
|
+
---- header ----
|
561
|
+
require 'mediacloth/mediawikiast'
|
562
|
+
|
563
|
+
---- inner ----
|
564
|
+
|
565
|
+
attr_accessor :lexer
|
566
|
+
|
567
|
+
def initialize
|
568
|
+
@nodes = []
|
569
|
+
@context = []
|
570
|
+
@wiki_ast_length = 0
|
571
|
+
super
|
572
|
+
end
|
573
|
+
|
574
|
+
#Tokenizes input string and parses it.
|
575
|
+
def parse(input)
|
576
|
+
@yydebug=true
|
577
|
+
lexer.tokenize(input)
|
578
|
+
do_parse
|
579
|
+
return @nodes.last
|
580
|
+
end
|
581
|
+
|
582
|
+
#Asks the lexer to return the next token.
|
583
|
+
def next_token
|
584
|
+
token = @lexer.lex
|
585
|
+
if token[0].to_s.upcase.include? "_START"
|
586
|
+
@context << token[2..3]
|
587
|
+
elsif token[0].to_s.upcase.include? "_END"
|
588
|
+
@ast_index = @context.last[0]
|
589
|
+
@ast_length = token[2] + token[3] - @context.last[0]
|
590
|
+
@context.pop
|
591
|
+
else
|
592
|
+
@ast_index = token[2]
|
593
|
+
@ast_length = token[3]
|
594
|
+
end
|
595
|
+
|
596
|
+
@wiki_ast_length += token[3]
|
597
|
+
|
598
|
+
return token[0..1]
|
599
|
+
end
|