mok-parser 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +42 -0
- data/COPYING +674 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +19 -0
- data/History.rdoc +42 -0
- data/LICENSE.txt +14 -0
- data/README.rdoc +22 -0
- data/RELEASE +1 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/bin/mok-parser +19 -0
- data/lib/mok-parser.rb +10 -0
- data/lib/mokblockparser.output +670 -0
- data/lib/mokblockparser.ry +392 -0
- data/lib/mokblockparser.tab.rb +773 -0
- data/lib/mokelement.rb +266 -0
- data/lib/mokinlineparser.output +1804 -0
- data/lib/mokinlineparser.ry +536 -0
- data/lib/mokinlineparser.tab.rb +1268 -0
- data/lib/parserutility.rb +21 -0
- data/mok-parser.gemspec +21 -0
- data/sample.raf +4 -0
- metadata +110 -0
@@ -0,0 +1,773 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.4.10
|
4
|
+
# from Racc grammer file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser.rb'
|
8
|
+
|
9
|
+
require "parserutility"
|
10
|
+
require "mokinlineparser.tab"
|
11
|
+
require "mokelement"
|
12
|
+
require "erb"
|
13
|
+
|
14
|
+
module Mok
|
15
|
+
|
16
|
+
class BlockParser < Racc::Parser
|
17
|
+
|
18
|
+
module_eval(<<'...end mokblockparser.ry/module_eval...', 'mokblockparser.ry', 128)
|
19
|
+
include ParserUtility
|
20
|
+
|
21
|
+
class Line
|
22
|
+
def initialize(line)
|
23
|
+
@content = line
|
24
|
+
# @indent = get_line_indent(line)
|
25
|
+
# @type = nil
|
26
|
+
end
|
27
|
+
attr_reader :indent, :no
|
28
|
+
attr_accessor :type, :content
|
29
|
+
alias indent_size indent
|
30
|
+
|
31
|
+
def get_line_indent
|
32
|
+
return 0 if @content.nil?
|
33
|
+
@content =~ /(\s*)/
|
34
|
+
$1.size
|
35
|
+
end
|
36
|
+
alias indent get_line_indent
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def initialize(options = {})
|
41
|
+
@inline_parser = InlineParser.new(options)
|
42
|
+
@metadata = {}
|
43
|
+
@inline_index = @inline_parser.index
|
44
|
+
@index = {}
|
45
|
+
@head_index = HeadIndex.new
|
46
|
+
end
|
47
|
+
attr_reader :metadata, :inline_index, :index
|
48
|
+
|
49
|
+
def parse(src)
|
50
|
+
@no = 0
|
51
|
+
# srcをerbで処理
|
52
|
+
src = ERB.new(src.join,4).result(binding.taint).split("\n").map {|s| "#{s}\n"}
|
53
|
+
|
54
|
+
@src = Array(src)
|
55
|
+
@line = Line.new("")
|
56
|
+
@line_pre = @line.dup
|
57
|
+
@indent_stack = []
|
58
|
+
@current_indent = 0
|
59
|
+
@current_type = :header
|
60
|
+
@yydebug = true
|
61
|
+
@view_token_type = false
|
62
|
+
do_parse
|
63
|
+
end
|
64
|
+
|
65
|
+
def on_error(token_id, value, stack)
|
66
|
+
lineno = @src[0..@no].to_s.split("\n").size
|
67
|
+
raise Racc::ParseError,
|
68
|
+
"mokblockpaser: line #{lineno}: syntax error on #{value.inspect}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def next_token
|
72
|
+
@line_pre = @line.dup
|
73
|
+
@line = Line.new(@src[@no])
|
74
|
+
# puts "line: #{@line.content}" if @view_token_type
|
75
|
+
case @line.content
|
76
|
+
when nil
|
77
|
+
@line.content = ""
|
78
|
+
if_current_indent_equal("") do
|
79
|
+
puts "b: false: #{@line.content}" if @view_token_type
|
80
|
+
[false, false]
|
81
|
+
end
|
82
|
+
when /^$/
|
83
|
+
@line.content = ""
|
84
|
+
if_current_indent_equal("") do
|
85
|
+
if @current_type == :preformat
|
86
|
+
puts "b: :PREFORMAT: #{@line.content}" if @view_token_type
|
87
|
+
[:PREFORMAT, "\n"]
|
88
|
+
elsif @current_type == :quote
|
89
|
+
puts "b: :QUOTE: #{@line.content}" if @view_token_type
|
90
|
+
[:QUOTE, "\n"]
|
91
|
+
elsif @current_type == :descline
|
92
|
+
puts "b: DESCLINE: #{@line.content}" if @view_token_type
|
93
|
+
[:DESCLINE, " "]
|
94
|
+
else
|
95
|
+
puts "b: WHITELINE: #{@line.content}" if @view_token_type
|
96
|
+
@current_type = :whiteline
|
97
|
+
[:WHITELINE, :WHITELINE]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
when /^\#(.*)/ # comment line
|
101
|
+
@no += 1
|
102
|
+
if @current_type == :header
|
103
|
+
puts "b: HEADER: #{@line.content}" if @view_token_type
|
104
|
+
[:HEADER, $1.strip]
|
105
|
+
else
|
106
|
+
puts "b: COMMENT(noop): #{@line.content}" if @view_token_type
|
107
|
+
next_token
|
108
|
+
end
|
109
|
+
when /^(={1,4})(?!=)\s*(?=\S)/, /^(\+{1,2})(?!\+)\s*(?=\S)/
|
110
|
+
rest = $' # '
|
111
|
+
rest.strip!
|
112
|
+
mark = $1
|
113
|
+
# if_current_indent_equal("") do
|
114
|
+
if_current_indent_equal(@line.indent) do
|
115
|
+
@current_type = :headline
|
116
|
+
puts "b: HEADLINE: #{@line.content}" if @view_token_type
|
117
|
+
[:HEADLINE, [mark_to_level(mark), rest]]
|
118
|
+
end
|
119
|
+
when /^\s\s+(.*)/ # type == preformat
|
120
|
+
puts "b: 2 WHITE SPACE(#{@current_type}) : #{@line.content}" if @view_token_type
|
121
|
+
case @current_type
|
122
|
+
when :itemlist
|
123
|
+
if @line.content =~ /^(\s*)(\*)(\s+)(.*)/
|
124
|
+
line = $4.strip
|
125
|
+
if line.empty?
|
126
|
+
@no += 1
|
127
|
+
next_token
|
128
|
+
else
|
129
|
+
if_current_indent_equal(@line.indent) do
|
130
|
+
puts "b: ITEMLIST: [#{line}]" if @view_token_type
|
131
|
+
@current_type = :itemlist
|
132
|
+
[:ITEMLIST, line]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
else
|
136
|
+
line = @line.content.strip
|
137
|
+
if line.empty?
|
138
|
+
@no += 1
|
139
|
+
next_token
|
140
|
+
else
|
141
|
+
puts "b: ITEMLISTCONTINUE: [#{line.empty?}] --" if @view_token_type
|
142
|
+
@no += 1
|
143
|
+
@current_type = :itemlist
|
144
|
+
[:ITEMLISTCONTINUE, line]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
when :numlist
|
148
|
+
@line.content =~ /^(\s*)(\(\d+\))(\s+)(.*)/
|
149
|
+
if $4.nil?
|
150
|
+
@line.content =~ /^(\s*)(\d\.)(\s+)(.*)/
|
151
|
+
end
|
152
|
+
line = $4
|
153
|
+
line ||= @line.content.strip
|
154
|
+
if line.empty?
|
155
|
+
@no += 1
|
156
|
+
next_token
|
157
|
+
else
|
158
|
+
if_current_indent_equal(@line.indent) do
|
159
|
+
puts "b: NUMLIST: [#{line}]" if @view_token_type
|
160
|
+
@current_type = :numlist
|
161
|
+
[:NUMLIST, line]
|
162
|
+
end
|
163
|
+
end
|
164
|
+
else
|
165
|
+
@no += 1
|
166
|
+
if @current_type == :descline
|
167
|
+
@current_type = :descline
|
168
|
+
puts "b: DESCLINE: #{@line.content}" if @view_token_type
|
169
|
+
[:DESCLINE, $1 + "\n"]
|
170
|
+
else
|
171
|
+
@current_type = :preformat
|
172
|
+
puts "b: PREFORMAT: #{$1}" if @view_token_type
|
173
|
+
[:PREFORMAT, @line.content.sub(" ","")]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
when /^>\s(.*)/ # type == quote
|
177
|
+
puts "b: 2 WHITE SPACE(#{@current_type}) : #{@line.content}" if @view_token_type
|
178
|
+
@current_type = :quote
|
179
|
+
puts "b: QUOTE: #{$1}" if @view_token_type
|
180
|
+
if_current_indent_equal(@line.indent) do
|
181
|
+
[:QUOTE, @line.content.sub("> ","")]
|
182
|
+
end
|
183
|
+
when /^(\:)(.*)/ # type = desclist
|
184
|
+
if_current_indent_equal(@line.indent) do
|
185
|
+
@current_type = :descline
|
186
|
+
puts "b: DESCLINE_TILTE: #{$2.strip}" if @view_token_type
|
187
|
+
[:DESCLINE_TITLE, $2.strip]
|
188
|
+
end
|
189
|
+
when /^(\s*)(\*)(\s+)(.*)/ # type = itemlist
|
190
|
+
if_current_indent_equal(@line.indent) do
|
191
|
+
puts "b: ITEMLIST: #{@line.content}" if @view_token_type
|
192
|
+
@current_type = :itemlist
|
193
|
+
[:ITEMLIST, $4]
|
194
|
+
end
|
195
|
+
when /^(\s*)(\(\d+\))(\s+)(.*)/
|
196
|
+
if_current_indent_equal(@line.indent) do
|
197
|
+
puts "b: NUMLIST: #{@line.content}" if @view_token_type
|
198
|
+
@current_type = :numlist
|
199
|
+
[:NUMLIST, $4]
|
200
|
+
end
|
201
|
+
when /^(\s*)(\d+\.)(\s+)(.*)/ # type = numlist
|
202
|
+
if_current_indent_equal(@line.indent) do
|
203
|
+
puts "b: NUMLIST: #{@line.content}" if @view_token_type
|
204
|
+
@current_type = :numlist
|
205
|
+
[:NUMLIST, $4]
|
206
|
+
end
|
207
|
+
when /^\|-.*/ # type = table head
|
208
|
+
# テーブル内であればテーブルヘッダとして無視、そうでなければ普通のPLAINとして扱う
|
209
|
+
if @current_type == :table
|
210
|
+
@no += 1
|
211
|
+
next_token
|
212
|
+
else
|
213
|
+
@current_type = :plain
|
214
|
+
if_current_indent_equal(@line.indent) do
|
215
|
+
puts "b: PLAIN: #{@line.content}" if @view_token_type
|
216
|
+
[:PLAIN, @line.content]
|
217
|
+
end
|
218
|
+
end
|
219
|
+
when /^\|.*/ # type = table
|
220
|
+
@no += 1
|
221
|
+
@current_type = :table
|
222
|
+
lines = @line.content.chomp.split("|")
|
223
|
+
lines.shift
|
224
|
+
[:TABLELINE, lines]
|
225
|
+
when /(.*)/ # type == plain
|
226
|
+
@current_type = :plain
|
227
|
+
if_current_indent_equal(@line.indent) do
|
228
|
+
puts "b: PLAIN: #{@line.content}" if @view_token_type
|
229
|
+
[:PLAIN, @line.content]
|
230
|
+
end
|
231
|
+
else
|
232
|
+
puts "raise : #{@line}"
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def if_current_indent_equal(ident)
|
237
|
+
indent_space = 2
|
238
|
+
puts "current: #{@current_indent}, line: #{@line.indent}, stack #{@indent_stack.size}:" if @view_token_type
|
239
|
+
indent_sabun = @current_indent - @line.indent
|
240
|
+
if indent_sabun >= -1 and indent_sabun <= 1
|
241
|
+
@no += 1
|
242
|
+
yield
|
243
|
+
elsif @current_indent < @line.indent
|
244
|
+
((@line.indent - @current_indent) / indent_space).times do
|
245
|
+
@indent_stack.push("")
|
246
|
+
end
|
247
|
+
@current_indent = @line.indent
|
248
|
+
puts "b: INDENT" if @view_token_type
|
249
|
+
[:INDENT, :INDENT]
|
250
|
+
else
|
251
|
+
@indent_stack.pop
|
252
|
+
@current_indent = @line.indent if @line.indent == @indent_stack.size * indent_space
|
253
|
+
puts "b: DEDENT" if @view_token_type
|
254
|
+
[:DEDENT, :DEDENT]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
...end mokblockparser.ry/module_eval...
|
259
|
+
##### State transition tables begin ###
|
260
|
+
|
261
|
+
racc_action_table = [
|
262
|
+
14, 13, 15, 17, 18, 40, 20, 22, 26, 32,
|
263
|
+
28, 52, 32, 34, 14, 13, 15, 17, 18, 40,
|
264
|
+
20, 22, 26, 32, 28, 41, 32, 34, 40, 56,
|
265
|
+
50, 26, 32, 28, 38, 32, 28, 38, 55, 28,
|
266
|
+
38, 51, 28, 28, 53, 43, 45, 54, 44, 35,
|
267
|
+
57 ]
|
268
|
+
|
269
|
+
racc_action_check = [
|
270
|
+
0, 0, 0, 0, 0, 40, 0, 0, 0, 40,
|
271
|
+
0, 33, 0, 0, 2, 2, 2, 2, 2, 9,
|
272
|
+
2, 2, 2, 9, 2, 16, 2, 2, 48, 48,
|
273
|
+
28, 26, 48, 26, 38, 26, 38, 47, 47, 47,
|
274
|
+
8, 30, 8, 24, 35, 18, 21, 42, 19, 1,
|
275
|
+
49 ]
|
276
|
+
|
277
|
+
racc_action_pointer = [
|
278
|
+
-2, 49, 12, nil, nil, nil, nil, nil, 30, 9,
|
279
|
+
nil, nil, nil, nil, nil, nil, 20, nil, 38, 40,
|
280
|
+
nil, 37, nil, nil, 31, nil, 21, nil, 17, nil,
|
281
|
+
27, nil, nil, -4, nil, 44, nil, nil, 24, nil,
|
282
|
+
-5, nil, 40, nil, nil, nil, nil, 27, 18, 37,
|
283
|
+
nil, nil, nil, nil, nil, nil, nil, nil ]
|
284
|
+
|
285
|
+
racc_action_default = [
|
286
|
+
-50, -50, -1, -2, -4, -5, -6, -7, -8, -9,
|
287
|
+
-10, -11, -12, -13, -14, -15, -16, -17, -22, -23,
|
288
|
+
-24, -26, -27, -29, -31, -32, -50, -34, -36, -40,
|
289
|
+
-42, -43, -45, -47, -48, -50, -3, -30, -50, -41,
|
290
|
+
-50, -18, -19, -20, -25, -28, -35, -50, -50, -37,
|
291
|
+
-38, -46, -49, 58, -21, -33, -44, -39 ]
|
292
|
+
|
293
|
+
racc_goto_table = [
|
294
|
+
39, 37, 48, 47, 3, 42, 36, 2, 46, 49,
|
295
|
+
1, nil, nil, nil, nil, 47, 48, nil, nil, nil,
|
296
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
297
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, 39,
|
298
|
+
37 ]
|
299
|
+
|
300
|
+
racc_goto_check = [
|
301
|
+
22, 17, 9, 8, 3, 14, 3, 2, 20, 21,
|
302
|
+
1, nil, nil, nil, nil, 8, 9, nil, nil, nil,
|
303
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
304
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, 22,
|
305
|
+
17 ]
|
306
|
+
|
307
|
+
racc_goto_pointer = [
|
308
|
+
nil, 10, 7, 4, nil, nil, nil, nil, -23, -24,
|
309
|
+
nil, nil, nil, nil, -13, nil, nil, -7, nil, nil,
|
310
|
+
-16, -19, -9, nil, nil, nil ]
|
311
|
+
|
312
|
+
racc_goto_default = [
|
313
|
+
nil, nil, nil, nil, 4, 5, 6, 7, 8, 9,
|
314
|
+
10, 11, 12, 16, nil, 19, 21, 23, 24, 25,
|
315
|
+
27, nil, 29, 30, 31, 33 ]
|
316
|
+
|
317
|
+
racc_reduce_table = [
|
318
|
+
0, 0, :racc_error,
|
319
|
+
1, 18, :_reduce_1,
|
320
|
+
1, 19, :_reduce_2,
|
321
|
+
2, 19, :_reduce_3,
|
322
|
+
1, 20, :_reduce_none,
|
323
|
+
1, 20, :_reduce_5,
|
324
|
+
1, 20, :_reduce_none,
|
325
|
+
1, 20, :_reduce_none,
|
326
|
+
1, 20, :_reduce_8,
|
327
|
+
1, 20, :_reduce_9,
|
328
|
+
1, 20, :_reduce_none,
|
329
|
+
1, 20, :_reduce_none,
|
330
|
+
1, 20, :_reduce_none,
|
331
|
+
1, 20, :_reduce_13,
|
332
|
+
1, 21, :_reduce_14,
|
333
|
+
1, 29, :_reduce_15,
|
334
|
+
1, 22, :_reduce_16,
|
335
|
+
1, 30, :_reduce_17,
|
336
|
+
2, 30, :_reduce_18,
|
337
|
+
2, 27, :_reduce_19,
|
338
|
+
1, 31, :_reduce_20,
|
339
|
+
2, 31, :_reduce_21,
|
340
|
+
0, 31, :_reduce_none,
|
341
|
+
1, 23, :_reduce_23,
|
342
|
+
1, 32, :_reduce_24,
|
343
|
+
2, 32, :_reduce_25,
|
344
|
+
1, 24, :_reduce_26,
|
345
|
+
1, 33, :_reduce_27,
|
346
|
+
2, 33, :_reduce_28,
|
347
|
+
1, 25, :_reduce_29,
|
348
|
+
2, 25, :_reduce_30,
|
349
|
+
1, 34, :_reduce_31,
|
350
|
+
1, 34, :_reduce_32,
|
351
|
+
3, 36, :_reduce_33,
|
352
|
+
1, 35, :_reduce_34,
|
353
|
+
2, 35, :_reduce_35,
|
354
|
+
1, 37, :_reduce_36,
|
355
|
+
2, 37, :_reduce_37,
|
356
|
+
1, 38, :_reduce_38,
|
357
|
+
2, 38, :_reduce_39,
|
358
|
+
1, 26, :_reduce_40,
|
359
|
+
2, 26, :_reduce_41,
|
360
|
+
1, 39, :_reduce_42,
|
361
|
+
1, 39, :_reduce_43,
|
362
|
+
3, 41, :_reduce_44,
|
363
|
+
1, 40, :_reduce_45,
|
364
|
+
2, 40, :_reduce_46,
|
365
|
+
1, 28, :_reduce_47,
|
366
|
+
1, 42, :_reduce_48,
|
367
|
+
2, 42, :_reduce_49 ]
|
368
|
+
|
369
|
+
racc_reduce_n = 50
|
370
|
+
|
371
|
+
racc_shift_n = 58
|
372
|
+
|
373
|
+
racc_token_table = {
|
374
|
+
false => 0,
|
375
|
+
:error => 1,
|
376
|
+
:HEADER => 2,
|
377
|
+
:WHITELINE => 3,
|
378
|
+
:HEADLINE => 4,
|
379
|
+
:PLAIN => 5,
|
380
|
+
:DESCLINE_TITLE => 6,
|
381
|
+
:DESCLINE => 7,
|
382
|
+
:PREFORMAT => 8,
|
383
|
+
:QUOTE => 9,
|
384
|
+
:INDENT => 10,
|
385
|
+
:DEDENT => 11,
|
386
|
+
:ITEMLIST => 12,
|
387
|
+
:ITEMLISTCONTINUE => 13,
|
388
|
+
:NUMLIST => 14,
|
389
|
+
:TABLELINE => 15,
|
390
|
+
:DUMMY => 16 }
|
391
|
+
|
392
|
+
racc_nt_base = 17
|
393
|
+
|
394
|
+
racc_use_result_var = false
|
395
|
+
|
396
|
+
Racc_arg = [
|
397
|
+
racc_action_table,
|
398
|
+
racc_action_check,
|
399
|
+
racc_action_default,
|
400
|
+
racc_action_pointer,
|
401
|
+
racc_goto_table,
|
402
|
+
racc_goto_check,
|
403
|
+
racc_goto_default,
|
404
|
+
racc_goto_pointer,
|
405
|
+
racc_nt_base,
|
406
|
+
racc_reduce_table,
|
407
|
+
racc_token_table,
|
408
|
+
racc_shift_n,
|
409
|
+
racc_reduce_n,
|
410
|
+
racc_use_result_var ]
|
411
|
+
|
412
|
+
Racc_token_to_s_table = [
|
413
|
+
"$end",
|
414
|
+
"error",
|
415
|
+
"HEADER",
|
416
|
+
"WHITELINE",
|
417
|
+
"HEADLINE",
|
418
|
+
"PLAIN",
|
419
|
+
"DESCLINE_TITLE",
|
420
|
+
"DESCLINE",
|
421
|
+
"PREFORMAT",
|
422
|
+
"QUOTE",
|
423
|
+
"INDENT",
|
424
|
+
"DEDENT",
|
425
|
+
"ITEMLIST",
|
426
|
+
"ITEMLISTCONTINUE",
|
427
|
+
"NUMLIST",
|
428
|
+
"TABLELINE",
|
429
|
+
"DUMMY",
|
430
|
+
"$start",
|
431
|
+
"document",
|
432
|
+
"blocks",
|
433
|
+
"block",
|
434
|
+
"header",
|
435
|
+
"paragraph",
|
436
|
+
"preformat_block",
|
437
|
+
"quote_block",
|
438
|
+
"itemlist_blocks",
|
439
|
+
"numlist_blocks",
|
440
|
+
"desc_block",
|
441
|
+
"table_block",
|
442
|
+
"headline",
|
443
|
+
"plain_texts",
|
444
|
+
"desclines",
|
445
|
+
"preformats",
|
446
|
+
"quotes",
|
447
|
+
"itemlist_block",
|
448
|
+
"itemlists",
|
449
|
+
"itemlist_indent_blocks",
|
450
|
+
"itemlistitems",
|
451
|
+
"itemlist_continues",
|
452
|
+
"numlist_block",
|
453
|
+
"numlists",
|
454
|
+
"numlist_indent_blocks",
|
455
|
+
"tablelines" ]
|
456
|
+
|
457
|
+
Racc_debug_parser = false
|
458
|
+
|
459
|
+
##### State transition tables end #####
|
460
|
+
|
461
|
+
# reduce 0 omitted
|
462
|
+
|
463
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 10)
|
464
|
+
def _reduce_1(val, _values)
|
465
|
+
val[0].compact
|
466
|
+
end
|
467
|
+
.,.,
|
468
|
+
|
469
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 12)
|
470
|
+
def _reduce_2(val, _values)
|
471
|
+
val
|
472
|
+
end
|
473
|
+
.,.,
|
474
|
+
|
475
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 13)
|
476
|
+
def _reduce_3(val, _values)
|
477
|
+
[val[0], val[1]].flatten
|
478
|
+
end
|
479
|
+
.,.,
|
480
|
+
|
481
|
+
# reduce 4 omitted
|
482
|
+
|
483
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 16)
|
484
|
+
def _reduce_5(val, _values)
|
485
|
+
val[0]
|
486
|
+
end
|
487
|
+
.,.,
|
488
|
+
|
489
|
+
# reduce 6 omitted
|
490
|
+
|
491
|
+
# reduce 7 omitted
|
492
|
+
|
493
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 19)
|
494
|
+
def _reduce_8(val, _values)
|
495
|
+
ItemList.new(val[0].flatten)
|
496
|
+
end
|
497
|
+
.,.,
|
498
|
+
|
499
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 20)
|
500
|
+
def _reduce_9(val, _values)
|
501
|
+
NumList.new(val[0].flatten)
|
502
|
+
end
|
503
|
+
.,.,
|
504
|
+
|
505
|
+
# reduce 10 omitted
|
506
|
+
|
507
|
+
# reduce 11 omitted
|
508
|
+
|
509
|
+
# reduce 12 omitted
|
510
|
+
|
511
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 24)
|
512
|
+
def _reduce_13(val, _values)
|
513
|
+
WhiteLine.new
|
514
|
+
end
|
515
|
+
.,.,
|
516
|
+
|
517
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 28)
|
518
|
+
def _reduce_14(val, _values)
|
519
|
+
name, val = val[0].split(":",2)
|
520
|
+
if name.nil? or val.nil?
|
521
|
+
else
|
522
|
+
@metadata.update({name.strip.to_sym => val.strip })
|
523
|
+
end
|
524
|
+
nil
|
525
|
+
end
|
526
|
+
.,.,
|
527
|
+
|
528
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 36)
|
529
|
+
def _reduce_15(val, _values)
|
530
|
+
# val[0] is like [level, title, index]
|
531
|
+
title = val[0][1]
|
532
|
+
level = val[0][0]
|
533
|
+
if level == 1
|
534
|
+
@metadata[:subject] ||= title
|
535
|
+
else
|
536
|
+
@head_index.update(level)
|
537
|
+
end
|
538
|
+
|
539
|
+
@index[:head] ||= []
|
540
|
+
@index[:head] << {:title => title, :level => level, :index => @head_index.to_s}
|
541
|
+
HeadLine.new([level, title, @index[:head].size, @head_index.to_s])
|
542
|
+
end
|
543
|
+
.,.,
|
544
|
+
|
545
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 49)
|
546
|
+
def _reduce_16(val, _values)
|
547
|
+
Paragraph.new @inline_parser.parse(val)
|
548
|
+
end
|
549
|
+
.,.,
|
550
|
+
|
551
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 51)
|
552
|
+
def _reduce_17(val, _values)
|
553
|
+
val[0]
|
554
|
+
end
|
555
|
+
.,.,
|
556
|
+
|
557
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 52)
|
558
|
+
def _reduce_18(val, _values)
|
559
|
+
val[0] + val[1]
|
560
|
+
end
|
561
|
+
.,.,
|
562
|
+
|
563
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 56)
|
564
|
+
def _reduce_19(val, _values)
|
565
|
+
if val[1].nil?
|
566
|
+
lines = [Plain.new("")]
|
567
|
+
else
|
568
|
+
lines = @inline_parser.parse(val[1])
|
569
|
+
end
|
570
|
+
Desc.new([val[0], lines])
|
571
|
+
|
572
|
+
end
|
573
|
+
.,.,
|
574
|
+
|
575
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 65)
|
576
|
+
def _reduce_20(val, _values)
|
577
|
+
val[0]
|
578
|
+
end
|
579
|
+
.,.,
|
580
|
+
|
581
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 66)
|
582
|
+
def _reduce_21(val, _values)
|
583
|
+
val[0] + val[1]
|
584
|
+
end
|
585
|
+
.,.,
|
586
|
+
|
587
|
+
# reduce 22 omitted
|
588
|
+
|
589
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 71)
|
590
|
+
def _reduce_23(val, _values)
|
591
|
+
pr = val[0].strip ; Preformat.new([pr]) unless pr.empty?
|
592
|
+
end
|
593
|
+
.,.,
|
594
|
+
|
595
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 73)
|
596
|
+
def _reduce_24(val, _values)
|
597
|
+
val[0]
|
598
|
+
end
|
599
|
+
.,.,
|
600
|
+
|
601
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 74)
|
602
|
+
def _reduce_25(val, _values)
|
603
|
+
val[0] + val[1]
|
604
|
+
end
|
605
|
+
.,.,
|
606
|
+
|
607
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 78)
|
608
|
+
def _reduce_26(val, _values)
|
609
|
+
qu = val[0].strip ; Quote.new(@inline_parser.parse(qu)) unless qu.empty?
|
610
|
+
end
|
611
|
+
.,.,
|
612
|
+
|
613
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 80)
|
614
|
+
def _reduce_27(val, _values)
|
615
|
+
val[0]
|
616
|
+
end
|
617
|
+
.,.,
|
618
|
+
|
619
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 81)
|
620
|
+
def _reduce_28(val, _values)
|
621
|
+
val[0] + val[1]
|
622
|
+
end
|
623
|
+
.,.,
|
624
|
+
|
625
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 85)
|
626
|
+
def _reduce_29(val, _values)
|
627
|
+
val[0]
|
628
|
+
end
|
629
|
+
.,.,
|
630
|
+
|
631
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 86)
|
632
|
+
def _reduce_30(val, _values)
|
633
|
+
val[0] << val[1]
|
634
|
+
end
|
635
|
+
.,.,
|
636
|
+
|
637
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 88)
|
638
|
+
def _reduce_31(val, _values)
|
639
|
+
val[0]
|
640
|
+
end
|
641
|
+
.,.,
|
642
|
+
|
643
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 89)
|
644
|
+
def _reduce_32(val, _values)
|
645
|
+
val[0]
|
646
|
+
end
|
647
|
+
.,.,
|
648
|
+
|
649
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 91)
|
650
|
+
def _reduce_33(val, _values)
|
651
|
+
val
|
652
|
+
end
|
653
|
+
.,.,
|
654
|
+
|
655
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 93)
|
656
|
+
def _reduce_34(val, _values)
|
657
|
+
[PlainTextBlock.new(@inline_parser.parse(val[0]))]
|
658
|
+
end
|
659
|
+
.,.,
|
660
|
+
|
661
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 94)
|
662
|
+
def _reduce_35(val, _values)
|
663
|
+
val[0] << PlainTextBlock.new(@inline_parser.parse(val[1]))
|
664
|
+
end
|
665
|
+
.,.,
|
666
|
+
|
667
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 96)
|
668
|
+
def _reduce_36(val, _values)
|
669
|
+
val[0]
|
670
|
+
end
|
671
|
+
.,.,
|
672
|
+
|
673
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 97)
|
674
|
+
def _reduce_37(val, _values)
|
675
|
+
val[0] + val[1]
|
676
|
+
end
|
677
|
+
.,.,
|
678
|
+
|
679
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 99)
|
680
|
+
def _reduce_38(val, _values)
|
681
|
+
"\n" + val[0]
|
682
|
+
end
|
683
|
+
.,.,
|
684
|
+
|
685
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 100)
|
686
|
+
def _reduce_39(val, _values)
|
687
|
+
val[0] + "\n" + val[1]
|
688
|
+
end
|
689
|
+
.,.,
|
690
|
+
|
691
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 104)
|
692
|
+
def _reduce_40(val, _values)
|
693
|
+
val[0]
|
694
|
+
end
|
695
|
+
.,.,
|
696
|
+
|
697
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 105)
|
698
|
+
def _reduce_41(val, _values)
|
699
|
+
val[0] << val[1]
|
700
|
+
end
|
701
|
+
.,.,
|
702
|
+
|
703
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 107)
|
704
|
+
def _reduce_42(val, _values)
|
705
|
+
val[0]
|
706
|
+
end
|
707
|
+
.,.,
|
708
|
+
|
709
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 108)
|
710
|
+
def _reduce_43(val, _values)
|
711
|
+
val[0]
|
712
|
+
end
|
713
|
+
.,.,
|
714
|
+
|
715
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 110)
|
716
|
+
def _reduce_44(val, _values)
|
717
|
+
val
|
718
|
+
end
|
719
|
+
.,.,
|
720
|
+
|
721
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 112)
|
722
|
+
def _reduce_45(val, _values)
|
723
|
+
[PlainTextBlock.new(@inline_parser.parse(val[0]))]
|
724
|
+
end
|
725
|
+
.,.,
|
726
|
+
|
727
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 113)
|
728
|
+
def _reduce_46(val, _values)
|
729
|
+
val[0] << PlainTextBlock.new(@inline_parser.parse(val[1]))
|
730
|
+
end
|
731
|
+
.,.,
|
732
|
+
|
733
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 118)
|
734
|
+
def _reduce_47(val, _values)
|
735
|
+
Table.new(val[0])
|
736
|
+
end
|
737
|
+
.,.,
|
738
|
+
|
739
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 120)
|
740
|
+
def _reduce_48(val, _values)
|
741
|
+
val
|
742
|
+
end
|
743
|
+
.,.,
|
744
|
+
|
745
|
+
module_eval(<<'.,.,', 'mokblockparser.ry', 121)
|
746
|
+
def _reduce_49(val, _values)
|
747
|
+
val[0] << val[1]
|
748
|
+
end
|
749
|
+
.,.,
|
750
|
+
|
751
|
+
def _reduce_none(val, _values)
|
752
|
+
val[0]
|
753
|
+
end
|
754
|
+
|
755
|
+
end # class BlockParser
|
756
|
+
|
757
|
+
if __FILE__ == $0
|
758
|
+
mok = BlockParser.new
|
759
|
+
src = $stdin.readlines
|
760
|
+
nodes = mok.parse(src)
|
761
|
+
puts "----- index -----"
|
762
|
+
mok.index.each do |key,val|
|
763
|
+
puts key
|
764
|
+
val.each do |v| p v end
|
765
|
+
end
|
766
|
+
puts "----- info -----"
|
767
|
+
p mok.info
|
768
|
+
puts "----- output -----"
|
769
|
+
nodes.each do |n|
|
770
|
+
puts n.apply
|
771
|
+
end
|
772
|
+
end
|
773
|
+
end # end of module Mok
|