racc 1.5.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.ja.rdoc +0 -1
- data/README.rdoc +6 -7
- data/{rdoc → doc}/en/NEWS.en.rdoc +0 -0
- data/{rdoc → doc}/en/grammar.en.rdoc +27 -31
- data/doc/en/grammar2.en.rdoc +219 -0
- data/{rdoc → doc}/ja/NEWS.ja.rdoc +0 -0
- data/{rdoc → doc}/ja/command.ja.html +0 -0
- data/{rdoc → doc}/ja/debug.ja.rdoc +0 -0
- data/{rdoc → doc}/ja/grammar.ja.rdoc +0 -0
- data/{rdoc → doc}/ja/index.ja.html +0 -0
- data/{rdoc → doc}/ja/parser.ja.rdoc +0 -0
- data/{rdoc → doc}/ja/usage.ja.html +0 -0
- data/ext/racc/cparse/cparse.c +1 -1
- data/ext/racc/cparse/extconf.rb +1 -0
- data/lib/racc/info.rb +1 -1
- data/lib/racc/parser-text.rb +1 -1
- data/lib/racc/parser.rb +1 -1
- data/lib/racc/parserfilegenerator.rb +0 -44
- data/lib/racc/statetransitiontable.rb +2 -8
- metadata +15 -121
- data/Rakefile +0 -79
- data/ext/racc/com/headius/racc/Cparse.java +0 -849
- data/lib/racc/pre-setup +0 -13
- data/sample/array.y +0 -67
- data/sample/array2.y +0 -59
- data/sample/calc-ja.y +0 -66
- data/sample/calc.y +0 -65
- data/sample/conflict.y +0 -15
- data/sample/hash.y +0 -60
- data/sample/lalr.y +0 -17
- data/sample/lists.y +0 -57
- data/sample/syntax.y +0 -46
- data/sample/yyerr.y +0 -46
- data/test/assets/cadenza.y +0 -170
- data/test/assets/cast.y +0 -926
- data/test/assets/chk.y +0 -126
- data/test/assets/conf.y +0 -16
- data/test/assets/csspool.y +0 -729
- data/test/assets/digraph.y +0 -29
- data/test/assets/echk.y +0 -118
- data/test/assets/edtf.y +0 -583
- data/test/assets/err.y +0 -60
- data/test/assets/error_recovery.y +0 -35
- data/test/assets/expect.y +0 -7
- data/test/assets/firstline.y +0 -4
- data/test/assets/huia.y +0 -318
- data/test/assets/ichk.y +0 -102
- data/test/assets/intp.y +0 -546
- data/test/assets/journey.y +0 -47
- data/test/assets/liquor.y +0 -313
- data/test/assets/machete.y +0 -423
- data/test/assets/macruby.y +0 -2197
- data/test/assets/mailp.y +0 -437
- data/test/assets/mediacloth.y +0 -599
- data/test/assets/mof.y +0 -649
- data/test/assets/namae.y +0 -302
- data/test/assets/nasl.y +0 -626
- data/test/assets/newsyn.y +0 -25
- data/test/assets/noend.y +0 -4
- data/test/assets/nokogiri-css.y +0 -255
- data/test/assets/nonass.y +0 -41
- data/test/assets/normal.y +0 -27
- data/test/assets/norule.y +0 -4
- data/test/assets/nullbug1.y +0 -25
- data/test/assets/nullbug2.y +0 -15
- data/test/assets/opal.y +0 -1807
- data/test/assets/opt.y +0 -123
- data/test/assets/percent.y +0 -35
- data/test/assets/php_serialization.y +0 -98
- data/test/assets/recv.y +0 -97
- data/test/assets/riml.y +0 -665
- data/test/assets/rrconf.y +0 -14
- data/test/assets/ruby18.y +0 -1943
- data/test/assets/ruby19.y +0 -2174
- data/test/assets/ruby20.y +0 -2350
- data/test/assets/ruby21.y +0 -2359
- data/test/assets/ruby22.y +0 -2381
- data/test/assets/scan.y +0 -72
- data/test/assets/syntax.y +0 -50
- data/test/assets/tp_plus.y +0 -622
- data/test/assets/twowaysql.y +0 -278
- data/test/assets/unterm.y +0 -5
- data/test/assets/useless.y +0 -12
- data/test/assets/yyerr.y +0 -46
- data/test/bench.y +0 -36
- data/test/helper.rb +0 -115
- data/test/infini.y +0 -8
- data/test/regress/cadenza +0 -796
- data/test/regress/cast +0 -3428
- data/test/regress/csspool +0 -2314
- data/test/regress/edtf +0 -1794
- data/test/regress/huia +0 -1392
- data/test/regress/journey +0 -222
- data/test/regress/liquor +0 -885
- data/test/regress/machete +0 -833
- data/test/regress/mediacloth +0 -1463
- data/test/regress/mof +0 -1368
- data/test/regress/namae +0 -634
- data/test/regress/nasl +0 -2058
- data/test/regress/nokogiri-css +0 -836
- data/test/regress/opal +0 -6431
- data/test/regress/php_serialization +0 -336
- data/test/regress/riml +0 -3283
- data/test/regress/ruby18 +0 -6344
- data/test/regress/ruby22 +0 -7460
- data/test/regress/tp_plus +0 -1933
- data/test/regress/twowaysql +0 -556
- data/test/scandata/brace +0 -7
- data/test/scandata/gvar +0 -1
- data/test/scandata/normal +0 -4
- data/test/scandata/percent +0 -18
- data/test/scandata/slash +0 -10
- data/test/src.intp +0 -34
- data/test/start.y +0 -20
- data/test/test_chk_y.rb +0 -52
- data/test/test_grammar_file_parser.rb +0 -15
- data/test/test_racc_command.rb +0 -339
- data/test/test_scan_y.rb +0 -52
- data/test/testscanner.rb +0 -51
- data/web/racc.en.rhtml +0 -42
- data/web/racc.ja.rhtml +0 -51
data/test/assets/mediacloth.y
DELETED
@@ -1,599 +0,0 @@
|
|
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
|