mok-parser 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,536 @@
1
+ # Copyright (C) garin <garin54@gmail.com> 2011
2
+ # See the included file COPYING for details.
3
+ class InlineParser
4
+ token EM_OPEN EM_CLOSE ITALIC_OPEN ITALIC_CLOSE STRIKE_OPEN STRIKE_CLOSE CODE_OPEN CODE_CLOSE KBD_OPEN KBD_CLOSE LABEL_OPEN LABEL_CLOSE LABEL_LINK_OPEN LABEL_LINK_CLOSE REFERENCE_OPEN REFERENCE_CLOSE VERB_OPEN VERB_CLOSE FOOTNOTE_OPEN FOOTNOTE_CLOSE RUBY_OPEN RUBY_CLOSE VARIABLE_OPEN VARIABLE_CLOSE MEDIA_OPEN MEDIA_CLOSE MANUEDO_OPEN MANUEDO_CLOSE OTHER
5
+ options no_result_var
6
+ rule
7
+ content :
8
+ | elements
9
+
10
+ elements : elements element { val[0].push(val[1]) }
11
+ | element { val }
12
+
13
+ element : emphasis
14
+ | italic
15
+ | strike
16
+ | code
17
+ | kbd
18
+ | label
19
+ | label_link
20
+ | reference
21
+ | ruby
22
+ | variable
23
+ | footnote
24
+ | media
25
+ | verb
26
+ | manuedo
27
+ | normal_strings
28
+
29
+ # --- inline
30
+ emphasis : EM_OPEN content EM_CLOSE { Emphasis.new(val[1]) }
31
+ italic : ITALIC_OPEN content ITALIC_CLOSE { Italic.new(val[1]) }
32
+ strike : STRIKE_OPEN content STRIKE_CLOSE { Strike.new(val[1]) }
33
+ code : CODE_OPEN content CODE_CLOSE { Code.new(val[1]) }
34
+ kbd : KBD_OPEN content KBD_CLOSE { Kbd.new(val[1]) }
35
+ footnote : FOOTNOTE_OPEN content FOOTNOTE_CLOSE {
36
+ @index[:footnote] ||= []
37
+ @index[:footnote] << {:content => val[1] }
38
+ Footnote.new([val[1], @index[:footnote].size])
39
+ }
40
+
41
+ # --- inline end
42
+
43
+ # --- media
44
+ media_string : OTHER
45
+ | EM_OPEN
46
+ | EM_CLOSE
47
+ | ITALIC_OPEN
48
+ | ITALIC_CLOSE
49
+ | STRIKE_OPEN
50
+ | STRIKE_CLOSE
51
+ | CODE_OPEN
52
+ | CODE_CLOSE
53
+ | KBD_OPEN
54
+ | KBD_CLOSE
55
+ | RUBY_OPEN
56
+ | RUBY_CLOSE
57
+ | VARIABLE_OPEN
58
+ | VARIABLE_CLOSE
59
+ | MANUEDO_OPEN
60
+ | MANUEDO_CLOSE
61
+ | REFERENCE_OPEN
62
+ | REFERENCE_CLOSE
63
+ | LABEL_OPEN
64
+ | LABEL_CLOSE
65
+ | LABEL_LINK_OPEN
66
+ | LABEL_LINK_CLOSE
67
+ | FOOTNOTE_OPEN
68
+ | FOOTNOTE_CLOSE
69
+ | VERB_OPEN
70
+ | VERB_CLOSE
71
+ | MEDIA_OPEN
72
+
73
+ media_strings : media_strings media_string { val.join }
74
+ | media_string {
75
+ unless @options[:media_directory].nil? || @options[:media_directory].empty?
76
+ val[0] = File.join(@options[:media_directory],val[0]) unless val[0] =~ /^.*:\/\/.*/
77
+ end
78
+ val[0]
79
+ }
80
+ media : MEDIA_OPEN media_strings MEDIA_CLOSE {
81
+ mime = MimeMagic.by_extension(val[1].split(".").last)
82
+ unless mime.nil?
83
+ mediatype, subtype = mime.mediatype, mime.subtype
84
+ else
85
+ mediatype, subtype = "",""
86
+ end
87
+ Media.new([val[1],mediatype,subtype])
88
+ }
89
+
90
+ # --- media end
91
+ # --- ruby
92
+ ruby_string : OTHER
93
+ | EM_OPEN
94
+ | EM_CLOSE
95
+ | ITALIC_OPEN
96
+ | ITALIC_CLOSE
97
+ | STRIKE_OPEN
98
+ | STRIKE_CLOSE
99
+ | CODE_OPEN
100
+ | CODE_CLOSE
101
+ | KBD_OPEN
102
+ | KBD_CLOSE
103
+ | MEDIA_OPEN
104
+ | MEDIA_CLOSE
105
+ | MANUEDO_OPEN
106
+ | MANUEDO_CLOSE
107
+ | REFERENCE_OPEN
108
+ | REFERENCE_CLOSE
109
+ | LABEL_OPEN
110
+ | LABEL_CLOSE
111
+ | LABEL_LINK_OPEN
112
+ | LABEL_LINK_CLOSE
113
+ | RUBY_OPEN
114
+ | FOOTNOTE_OPEN
115
+ | FOOTNOTE_CLOSE
116
+ | VERB_OPEN
117
+ | VERB_CLOSE
118
+
119
+ ruby_strings : ruby_strings ruby_string { val.join }
120
+ | ruby_string { val[0] }
121
+
122
+ ruby : RUBY_OPEN ruby_strings RUBY_CLOSE {
123
+ base, text = val[1].split("|",2)
124
+ text ||= base
125
+ # parser = InlineParser.new
126
+ # text = parser.parse(text).map do |n| n.apply end
127
+ Ruby.new([base, text])
128
+ }
129
+
130
+ # --- ruby end
131
+ # --- variable start
132
+ variable_string : OTHER
133
+ | EM_OPEN
134
+ | EM_CLOSE
135
+ | ITALIC_OPEN
136
+ | ITALIC_CLOSE
137
+ | STRIKE_OPEN
138
+ | STRIKE_CLOSE
139
+ | CODE_OPEN
140
+ | CODE_CLOSE
141
+ | KBD_OPEN
142
+ | KBD_CLOSE
143
+ | MEDIA_OPEN
144
+ | MEDIA_CLOSE
145
+ | MANUEDO_OPEN
146
+ | MANUEDO_CLOSE
147
+ | REFERENCE_OPEN
148
+ | REFERENCE_CLOSE
149
+ | LABEL_OPEN
150
+ | LABEL_CLOSE
151
+ | LABEL_LINK_OPEN
152
+ | LABEL_LINK_CLOSE
153
+ | RUBY_OPEN
154
+ | RUBY_CLOSE
155
+ | VARIABLE_OPEN
156
+ | FOOTNOTE_OPEN
157
+ | FOOTNOTE_CLOSE
158
+ | VERB_OPEN
159
+ | VERB_CLOSE
160
+
161
+ variable_strings : variable_strings variable_string { val.join }
162
+ | variable_string { val[0] }
163
+
164
+ variable : VARIABLE_OPEN variable_strings VARIABLE_CLOSE {
165
+ base, text = val[1].split("=",2)
166
+ @variables ||= {}
167
+ @variables[base] = text unless text.nil?
168
+ value = @variables[base]
169
+ unless value.nil?
170
+ parser = InlineParser.new
171
+ value = parser.parse(value).map do |n| n.apply end
172
+ else # 変数が未定義
173
+ value = base
174
+ end
175
+ Variable.new(value)
176
+ }
177
+ # --- variable end
178
+ # --- manuedo
179
+ manuedo : MANUEDO_OPEN content MANUEDO_CLOSE { Manuedo.new(val[1]) }
180
+
181
+ # --- manuedo end
182
+
183
+ # --- label
184
+ label_string : OTHER { val[0] }
185
+
186
+
187
+ label_strings : label_strings label_string { val.join }
188
+ | label_string { val[0] }
189
+
190
+ label : LABEL_OPEN label_strings LABEL_CLOSE {
191
+ label, title = val[1].split("|",2)
192
+ title ||= label
193
+ @index[:label] ||= []
194
+ @index[:label] << {:title => title }
195
+ Label.new([label.to_code, title, @index[:label].size])
196
+ }
197
+
198
+ # --- labe end
199
+ # --- label link: start
200
+ label_link_string : OTHER { val[0] }
201
+
202
+ label_link_strings : label_link_strings label_link_string { val.join }
203
+ | label_link_string { val[0] }
204
+
205
+ label_link : LABEL_LINK_OPEN label_link_strings LABEL_LINK_CLOSE {
206
+ label, title = val[1].split("|",2)
207
+ title ||= label
208
+ LabelLink.new([label.to_code, title])
209
+ }
210
+ # --- label link: end
211
+
212
+ # --- reference : start
213
+ reference_string : OTHER { val[0] }
214
+
215
+ reference_strings : reference_strings reference_string { val.join }
216
+ | reference_string { val[0] }
217
+
218
+ reference : REFERENCE_OPEN reference_strings REFERENCE_CLOSE {
219
+ title, uri = val[1].split("|",2)
220
+ uri ||= title
221
+ if uri.strip[-2,2] == ".%" and ! @options[:reference_extension].nil?
222
+ uri.slice!(-2,2)
223
+ uri = "#{uri}#{@options[:reference_extension]}"
224
+ end
225
+ Reference.new([title, uri])
226
+ }
227
+ # --- reference : end
228
+ # --- verb
229
+ verb_string : OTHER
230
+ | EM_OPEN
231
+ | EM_CLOSE
232
+ | ITALIC_OPEN
233
+ | ITALIC_CLOSE
234
+ | STRIKE_OPEN
235
+ | STRIKE_CLOSE
236
+ | CODE_OPEN
237
+ | CODE_CLOSE
238
+ | KBD_OPEN
239
+ | KBD_CLOSE
240
+ | MEDIA_OPEN
241
+ | MEDIA_CLOSE
242
+ | MANUEDO_OPEN
243
+ | MANUEDO_CLOSE
244
+ | REFERENCE_OPEN
245
+ | REFERENCE_CLOSE
246
+ | LABEL_OPEN
247
+ | LABEL_CLOSE
248
+ | LABEL_LINK_OPEN
249
+ | LABEL_LINK_CLOSE
250
+ | RUBY_OPEN
251
+ | RUBY_CLOSE
252
+ | VARIABLE_OPEN
253
+ | VARIABLE_CLOSE
254
+ | FOOTNOTE_OPEN
255
+ | FOOTNOTE_CLOSE
256
+ | VERB_OPEN
257
+
258
+ verb_strings : verb_string
259
+ | verb_strings verb_string { val }
260
+
261
+ verb : VERB_OPEN verb_strings VERB_CLOSE { Verb.new(val[1])}
262
+
263
+ # --- verb end
264
+ # --- normal
265
+ normal_strings : normal_string { Plain.new(val[0]) }
266
+ | normal_strings normal_string { Plain.new([val[0].contents, val[1]]) }
267
+
268
+ normal_string : OTHER { val[0] }
269
+ # --- normal end
270
+
271
+ ---- inner
272
+ include ParserUtility
273
+
274
+ EM_OPEN = '((*'
275
+ EM_OPEN_RE = /\A#{Regexp.quote(EM_OPEN)}/
276
+ EM_CLOSE = '*))'
277
+ EM_CLOSE_RE = /\A#{Regexp.quote(EM_CLOSE)}/
278
+
279
+ ITALIC_OPEN = '((_'
280
+ ITALIC_OPEN_RE = /\A#{Regexp.quote(ITALIC_OPEN)}/
281
+ ITALIC_CLOSE = '_))'
282
+ ITALIC_CLOSE_RE = /\A#{Regexp.quote(ITALIC_CLOSE)}/
283
+
284
+ STRIKE_OPEN = '((-'
285
+ STRIKE_OPEN_RE = /\A#{Regexp.quote(STRIKE_OPEN)}/
286
+ STRIKE_CLOSE = '-))'
287
+ STRIKE_CLOSE_RE = /\A#{Regexp.quote(STRIKE_CLOSE)}/
288
+
289
+ CODE_OPEN = '(({'
290
+ CODE_OPEN_RE = /\A#{Regexp.quote(CODE_OPEN)}/
291
+ CODE_CLOSE = '}))'
292
+ CODE_CLOSE_RE = /\A#{Regexp.quote(CODE_CLOSE)}/
293
+
294
+ KBD_OPEN = '((%'
295
+ KBD_OPEN_RE = /\A#{Regexp.quote(KBD_OPEN)}/
296
+ KBD_CLOSE = '%))'
297
+ KBD_CLOSE_RE = /\A#{Regexp.quote(KBD_CLOSE)}/
298
+
299
+ RUBY_OPEN = '((^'
300
+ RUBY_OPEN_RE = /\A#{Regexp.quote(RUBY_OPEN)}/
301
+ RUBY_CLOSE = '^))'
302
+ RUBY_CLOSE_RE = /\A#{Regexp.quote(RUBY_CLOSE)}/
303
+
304
+ VARIABLE_OPEN = '((@'
305
+ VARIABLE_OPEN_RE = /\A#{Regexp.quote(VARIABLE_OPEN)}/
306
+ VARIABLE_CLOSE = '@))'
307
+ VARIABLE_CLOSE_RE = /\A#{Regexp.quote(VARIABLE_CLOSE)}/
308
+
309
+ FOOTNOTE_OPEN = '((['
310
+ FOOTNOTE_OPEN_RE = /\A#{Regexp.quote(FOOTNOTE_OPEN)}/
311
+ FOOTNOTE_CLOSE = ']))'
312
+ FOOTNOTE_CLOSE_RE = /\A#{Regexp.quote(FOOTNOTE_CLOSE)}/
313
+
314
+ MEDIA_OPEN = '(($'
315
+ MEDIA_OPEN_RE = /\A#{Regexp.quote(MEDIA_OPEN)}/
316
+ MEDIA_CLOSE = '$))'
317
+ MEDIA_CLOSE_RE = /\A#{Regexp.quote(MEDIA_CLOSE)}/
318
+
319
+ LABEL_OPEN = '((>'
320
+ LABEL_OPEN_RE = /\A#{Regexp.quote(LABEL_OPEN)}/
321
+ LABEL_CLOSE = '<))'
322
+ LABEL_CLOSE_RE = /\A#{Regexp.quote(LABEL_CLOSE)}/
323
+
324
+ LABEL_HTML_OPEN = '((&gt;'
325
+ LABEL_HTML_OPEN_RE = /\A#{Regexp.quote(LABEL_HTML_OPEN)}/
326
+ LABEL_HTML_CLOSE = '&lt;))'
327
+ LABEL_HTML_CLOSE_RE = /\A#{Regexp.quote(LABEL_HTML_CLOSE)}/
328
+
329
+ LABEL_LINK_OPEN = '((='
330
+ LABEL_LINK_OPEN_RE = /\A#{Regexp.quote(LABEL_LINK_OPEN)}/
331
+ LABEL_LINK_CLOSE = '=))'
332
+ LABEL_LINK_CLOSE_RE = /\A#{Regexp.quote(LABEL_LINK_CLOSE)}/
333
+
334
+ REFERENCE_OPEN = '((<'
335
+ REFERENCE_OPEN_RE = /\A#{Regexp.quote(REFERENCE_OPEN)}/
336
+ REFERENCE_CLOSE = '>))'
337
+ REFERENCE_CLOSE_RE = /\A#{Regexp.quote(REFERENCE_CLOSE)}/
338
+
339
+ REFERENCE_HTML_OPEN = '((<'
340
+ REFERENCE_HTML_OPEN_RE = /\A#{Regexp.quote(REFERENCE_HTML_OPEN)}/
341
+ REFERENCE_HTML_CLOSE = '>))'
342
+ REFERENCE_HTML_CLOSE_RE = /\A#{Regexp.quote(REFERENCE_HTML_CLOSE)}/
343
+
344
+ VERB_OPEN = "(('"
345
+ VERB_OPEN_RE = /\A#{Regexp.quote(VERB_OPEN)}/
346
+ VERB_CLOSE = "'))"
347
+ VERB_CLOSE_RE = /\A#{Regexp.quote(VERB_CLOSE)}/
348
+
349
+ MANUEDO_OPEN = "((/"
350
+ MANUEDO_OPEN_RE = /\A#{Regexp.quote(MANUEDO_OPEN)}/
351
+ MANUEDO_CLOSE = "/))"
352
+ MANUEDO_CLOSE_RE = /\A#{Regexp.quote(MANUEDO_CLOSE)}/
353
+
354
+ # URL = "URL:"
355
+ # URL_RE = /\A#{Regexp.quote(URL)}/
356
+
357
+ #other_re_mode = Regexp::EXTENDED
358
+ other_re_mode = Regexp::MULTILINE
359
+ OTHER_RE = Regexp.new(
360
+ "\\A.+?(?=#{Regexp.quote(EM_OPEN)}|#{Regexp.quote(EM_CLOSE)}|#{Regexp.quote(ITALIC_OPEN)}|#{Regexp.quote(ITALIC_CLOSE)}|#{Regexp.quote(STRIKE_OPEN)}|#{Regexp.quote(STRIKE_CLOSE)}|#{Regexp.quote(CODE_OPEN)}|#{Regexp.quote(CODE_CLOSE)}|#{Regexp.quote(KBD_OPEN)}|#{Regexp.quote(KBD_CLOSE)}|#{Regexp.quote(FOOTNOTE_OPEN)}|#{Regexp.quote(FOOTNOTE_CLOSE)}|#{Regexp.quote(RUBY_OPEN)}|#{Regexp.quote(RUBY_CLOSE)}|#{Regexp.quote(VARIABLE_OPEN)}|#{Regexp.quote(VARIABLE_CLOSE)}|#{Regexp.quote(MEDIA_OPEN)}|#{Regexp.quote(MEDIA_CLOSE)}|#{Regexp.quote(LABEL_OPEN)}|#{Regexp.quote(LABEL_CLOSE)}|#{Regexp.quote(LABEL_LINK_OPEN)}|#{Regexp.quote(LABEL_LINK_CLOSE)}|#{Regexp.quote(LABEL_HTML_OPEN)}|#{Regexp.quote(LABEL_HTML_CLOSE)}|#{Regexp.quote(REFERENCE_OPEN)}|#{Regexp.quote(REFERENCE_CLOSE)}|#{Regexp.quote(REFERENCE_HTML_OPEN)}|#{Regexp.quote(REFERENCE_HTML_CLOSE)}|#{Regexp.quote(MANUEDO_OPEN)}|#{Regexp.quote(MANUEDO_CLOSE)}|#{Regexp.quote(VERB_OPEN)}|#{Regexp.quote(VERB_CLOSE)})", other_re_mode)
361
+
362
+ def parse(src)
363
+ @src = StringScanner.new(Array(src).join)
364
+ @pre = ""
365
+ @@yydebug = false
366
+ @view_token_type = false
367
+ do_parse
368
+ end
369
+ def initialize(options = {})
370
+ @options = options
371
+ @index = {}
372
+ end
373
+ attr_reader :index
374
+
375
+ def next_token
376
+ return [false, false] if @src.eos?
377
+ if ret = @src.scan(EM_OPEN_RE)
378
+ puts "i: EM_OPEN: #{ret}" if @view_token_type
379
+ @pre << ret
380
+ [:EM_OPEN, ret]
381
+ elsif ret = @src.scan(EM_CLOSE_RE)
382
+ puts "i: EM_CLOSE: #{ret}" if @view_token_type
383
+ @pre << ret
384
+ [:EM_CLOSE, ret]
385
+ elsif ret = @src.scan(ITALIC_OPEN_RE)
386
+ puts "i: ITALIC_OPEN: #{ret}" if @view_token_type
387
+ @pre << ret
388
+ [:ITALIC_OPEN, ret]
389
+ elsif ret = @src.scan(ITALIC_CLOSE_RE)
390
+ puts "i: ITALIC_CLOSE: #{ret}" if @view_token_type
391
+ @pre << ret
392
+ [:ITALIC_CLOSE, ret]
393
+ elsif ret = @src.scan(STRIKE_OPEN_RE)
394
+ @pre << ret
395
+ puts "i: STRIKE_OPEN: #{ret}" if @view_token_type
396
+ [:STRIKE_OPEN, ret]
397
+ elsif ret = @src.scan(STRIKE_CLOSE_RE)
398
+ @pre << ret
399
+ puts "i: STRIKE_CLOSE: #{ret}" if @view_token_type
400
+ [:STRIKE_CLOSE, ret]
401
+ elsif ret = @src.scan(CODE_OPEN_RE)
402
+ @pre << ret
403
+ puts "i: CODE_OPEN: #{ret}" if @view_token_type
404
+ [:CODE_OPEN, ret]
405
+ elsif ret = @src.scan(CODE_CLOSE_RE)
406
+ @pre << ret
407
+ puts "i: CODE_CLOSE: #{ret}" if @view_token_type
408
+ [:CODE_CLOSE, ret]
409
+ elsif ret = @src.scan(KBD_OPEN_RE)
410
+ @pre << ret
411
+ puts "i: KBD_OPEN: #{ret}" if @view_token_type
412
+ [:KBD_OPEN, ret]
413
+ elsif ret = @src.scan(KBD_CLOSE_RE)
414
+ @pre << ret
415
+ puts "i: KBD_CLOSE: #{ret}" if @view_token_type
416
+ [:KBD_CLOSE, ret]
417
+ elsif ret = @src.scan(LABEL_OPEN_RE)
418
+ @pre << ret
419
+ puts "i: LABEL_OPEN: #{ret}" if @view_token_type
420
+ [:LABEL_OPEN, ret]
421
+ elsif ret = @src.scan(LABEL_CLOSE_RE)
422
+ puts "i: LABEL_CLOSE: #{ret}" if @view_token_type
423
+ @pre << ret
424
+ [:LABEL_CLOSE, ret]
425
+ elsif ret = @src.scan(LABEL_LINK_OPEN_RE)
426
+ @pre << ret
427
+ puts "i: LABEL_LINK_OPEN: #{ret}" if @view_token_type
428
+ [:LABEL_LINK_OPEN, ret]
429
+ elsif ret = @src.scan(LABEL_LINK_CLOSE_RE)
430
+ puts "i: LABEL_LINK_CLOSE: #{ret}" if @view_token_type
431
+ @pre << ret
432
+ [:LABEL_LINK_CLOSE, ret]
433
+ elsif ret = @src.scan(LABEL_HTML_OPEN_RE)
434
+ @pre << ret
435
+ puts "i: LABEL_OPEN: #{ret}" if @view_token_type
436
+ [:LABEL_OPEN, ret]
437
+ elsif ret = @src.scan(LABEL_HTML_CLOSE_RE)
438
+ puts "i: LABEL_CLOSE: #{ret}" if @view_token_type
439
+ @pre << ret
440
+ [:LABEL_CLOSE, ret]
441
+ elsif ret = @src.scan(REFERENCE_OPEN_RE)
442
+ puts "i: REFERENCE_OPEN: #{ret}" if @view_token_type
443
+ @pre << ret
444
+ [:REFERENCE_OPEN, ret]
445
+ elsif ret = @src.scan(REFERENCE_CLOSE_RE)
446
+ puts "i: REFERENCE_CLOSE: #{ret}" if @view_token_type
447
+ @pre << ret
448
+ [:REFERENCE_CLOSE, ret]
449
+ elsif ret = @src.scan(REFERENCE_HTML_OPEN_RE)
450
+ puts "i: REFERENCE_HTML_OPEN: #{ret}" if @view_token_type
451
+ @pre << ret
452
+ [:REFERENCE_OPEN, ret]
453
+ elsif ret = @src.scan(REFERENCE_HTML_CLOSE_RE)
454
+ puts "i: REFERENCE_HTML_CLOSE: #{ret}" if @view_token_type
455
+ @pre << ret
456
+ [:REFERENCE_CLOSE, ret]
457
+ elsif ret = @src.scan(VERB_OPEN_RE)
458
+ puts "i: VERB_OPEN: #{ret}" if @view_token_type
459
+ @pre << ret
460
+ [:VERB_OPEN, ret]
461
+ elsif ret = @src.scan(VERB_CLOSE_RE)
462
+ puts "i: VERB_CLOSE: #{ret}" if @view_token_type
463
+ @pre << ret
464
+ [:VERB_CLOSE, ret]
465
+ elsif ret = @src.scan(RUBY_OPEN_RE)
466
+ puts "i: RUBY_OPEN: #{ret}" if @view_token_type
467
+ @pre << ret
468
+ [:RUBY_OPEN, ret]
469
+ elsif ret = @src.scan(RUBY_CLOSE_RE)
470
+ puts "i: RUBY_CLOSE: #{ret}" if @view_token_type
471
+ @pre << ret
472
+ [:RUBY_CLOSE, ret]
473
+ elsif ret = @src.scan(VARIABLE_OPEN_RE)
474
+ puts "i: VARIABLE_OPEN: #{ret}" if @view_token_type
475
+ @pre << ret
476
+ [:VARIABLE_OPEN, ret]
477
+ elsif ret = @src.scan(VARIABLE_CLOSE_RE)
478
+ puts "i: VARIABLE_CLOSE: #{ret}" if @view_token_type
479
+ @pre << ret
480
+ [:VARIABLE_CLOSE, ret]
481
+ elsif ret = @src.scan(FOOTNOTE_OPEN_RE)
482
+ puts "i: FOOTNOTE_OPEN: #{ret}" if @view_token_type
483
+ @pre << ret
484
+ [:FOOTNOTE_OPEN, ret]
485
+ elsif ret = @src.scan(FOOTNOTE_CLOSE_RE)
486
+ puts "i: FOOTNOTE_CLOSE: #{ret}" if @view_token_type
487
+ @pre << ret
488
+ [:FOOTNOTE_CLOSE, ret]
489
+ elsif ret = @src.scan(MEDIA_OPEN_RE)
490
+ puts "i: MEDIA_OPEN: #{ret}" if @view_token_type
491
+ @pre << ret
492
+ [:MEDIA_OPEN, ret]
493
+ elsif ret = @src.scan(MEDIA_CLOSE_RE)
494
+ puts "i: MEDIA_CLOSE: #{ret}" if @view_token_type
495
+ @pre << ret
496
+ [:MEDIA_CLOSE, ret]
497
+ elsif ret = @src.scan(MANUEDO_OPEN_RE)
498
+ puts "i: MANUEDO_OPEN: #{ret}" if @view_token_type
499
+ @pre << ret
500
+ [:MANUEDO_OPEN, ret]
501
+ elsif ret = @src.scan(MANUEDO_CLOSE_RE)
502
+ puts "i: MANUED_CLOSE: #{ret}" if @view_token_type
503
+ @pre << ret
504
+ [:MANUEDO_CLOSE, ret]
505
+ elsif ret = @src.scan(OTHER_RE)
506
+ puts "i: OTHER_RE: #{ret}" if @view_token_type
507
+ @pre << ret
508
+ [:OTHER, ret]
509
+ else
510
+ puts "i: OTHER_RE(else): #{ret}" if @view_token_type
511
+ ret = @src.rest
512
+ @pre << ret
513
+ @src.terminate
514
+ [:OTHER, ret]
515
+ end
516
+ end
517
+
518
+ ---- header
519
+ require "parserutility"
520
+ require 'strscan'
521
+ require 'mimemagic'
522
+ require 'erb'
523
+ require 'mokelement'
524
+
525
+ module Mok
526
+ ---- footer
527
+ if __FILE__ == $0
528
+ mok = InlineParser.new
529
+ src = $stdin.readline
530
+ nodes = mok.parse(src)
531
+ puts "----- output -----"
532
+ nodes.each do |n|
533
+ puts n.apply
534
+ end
535
+ end
536
+ end # end of module Mok