review 1.7.2 → 2.0.0.beta1

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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -43
  3. data/.travis.yml +0 -9
  4. data/ChangeLog +0 -16
  5. data/Gemfile +1 -0
  6. data/README.rdoc +1 -1
  7. data/Rakefile +12 -1
  8. data/bin/review-check +21 -8
  9. data/bin/review-compile +15 -9
  10. data/bin/review-epubmaker-legacy +6 -6
  11. data/bin/review-index +13 -2
  12. data/bin/review-init +18 -12
  13. data/bin/review-preproc +14 -1
  14. data/bin/review-validate +1 -1
  15. data/bin/review-vol +13 -1
  16. data/doc/quickstart.ja.md +1 -1
  17. data/doc/quickstart.md +1 -1
  18. data/lib/epubmaker/content.rb +3 -3
  19. data/lib/epubmaker/epubcommon.rb +108 -91
  20. data/lib/epubmaker/epubv2.rb +67 -14
  21. data/lib/epubmaker/epubv3.rb +59 -25
  22. data/lib/epubmaker/producer.rb +1 -13
  23. data/lib/lineinput.rb +0 -48
  24. data/lib/review/book/base.rb +4 -12
  25. data/lib/review/book/compilable.rb +3 -1
  26. data/lib/review/book/index.rb +4 -4
  27. data/lib/review/builder.rb +54 -47
  28. data/lib/review/compiler.rb +4662 -326
  29. data/lib/review/compiler/literals_1_8.kpeg +19 -0
  30. data/lib/review/compiler/literals_1_8.rb +432 -0
  31. data/lib/review/compiler/literals_1_9.kpeg +22 -0
  32. data/lib/review/compiler/literals_1_9.rb +435 -0
  33. data/lib/review/configure.rb +8 -20
  34. data/lib/review/epubbuilder.rb +1 -1
  35. data/lib/review/epubmaker.rb +122 -52
  36. data/lib/review/ewbbuilder.rb +4 -4
  37. data/lib/review/exception.rb +1 -1
  38. data/lib/review/extentions.rb +1 -0
  39. data/lib/review/extentions/array.rb +25 -0
  40. data/lib/review/htmlbuilder.rb +286 -275
  41. data/lib/review/htmllayout.rb +0 -2
  42. data/lib/review/htmlutils.rb +4 -4
  43. data/lib/review/i18n.rb +2 -6
  44. data/lib/review/i18n.yml +1 -1
  45. data/lib/review/idgxmlbuilder.rb +239 -204
  46. data/lib/review/inaobuilder.rb +75 -73
  47. data/lib/review/latexbuilder.rb +265 -219
  48. data/lib/review/latexutils.rb +6 -6
  49. data/lib/review/layout.tex.erb +1 -1
  50. data/lib/review/location.rb +24 -0
  51. data/lib/review/markdownbuilder.rb +124 -79
  52. data/lib/review/node.rb +267 -0
  53. data/lib/review/pdfmaker.rb +92 -92
  54. data/lib/review/preprocessor.rb +51 -14
  55. data/lib/review/review.kpeg +724 -0
  56. data/lib/review/textbuilder.rb +1 -1
  57. data/lib/review/textutils.rb +24 -18
  58. data/lib/review/tocparser.rb +3 -3
  59. data/lib/review/tocprinter.rb +31 -8
  60. data/lib/review/topbuilder.rb +119 -111
  61. data/lib/review/unfold.rb +2 -2
  62. data/lib/review/version.rb +1 -1
  63. data/review.gemspec +2 -2
  64. data/rubocop-todo.yml +456 -0
  65. data/test/assets/test_template.tex +1 -1
  66. data/test/sample-book/src/config.yml +0 -1
  67. data/test/test.re +1 -1
  68. data/test/test_book.rb +4 -4
  69. data/test/test_book_chapter.rb +70 -0
  70. data/test/test_book_part.rb +1 -1
  71. data/test/test_builder.rb +6 -28
  72. data/test/test_compiler.rb +59 -14
  73. data/test/test_helper.rb +47 -4
  74. data/test/test_htmlbuilder.rb +104 -73
  75. data/test/test_i18n.rb +5 -3
  76. data/test/test_idgxmlbuilder.rb +5 -2
  77. data/test/test_inaobuilder.rb +4 -2
  78. data/test/test_latexbuilder.rb +18 -37
  79. data/test/test_lineinput.rb +25 -4
  80. data/test/test_markdownbuilder.rb +4 -22
  81. data/test/test_pdfmaker.rb +12 -11
  82. data/test/test_textutils.rb +0 -36
  83. data/test/test_topbuilder.rb +2 -0
  84. metadata +14 -28
  85. data/.rubocop_todo.yml +0 -605
  86. data/Dockerfile +0 -22
  87. data/doc/NEWS.ja.md +0 -362
  88. data/doc/NEWS.md +0 -366
  89. data/lib/review/htmltoc.rb +0 -45
  90. data/lib/review/template.rb +0 -21
  91. data/templates/html/layout-html5.html.erb +0 -17
  92. data/templates/html/layout-xhtml1.html.erb +0 -20
  93. data/templates/ncx/epubv2.ncx.erb +0 -11
  94. data/templates/opf/epubv2.opf.erb +0 -21
  95. data/templates/opf/epubv3.opf.erb +0 -18
  96. data/templates/xml/container.xml.erb +0 -6
  97. data/test/assets/test.xml.erb +0 -3
  98. data/test/sample-book/src/config-epub2.yml +0 -186
  99. data/test/test_configure.rb +0 -50
  100. data/test/test_htmltoc.rb +0 -32
  101. data/test/test_template.rb +0 -26
@@ -0,0 +1,19 @@
1
+ %% name = ReVIEW::Compiler::Literals
2
+
3
+ %% header {
4
+ $KCODE='u' ## for Ruby 1.8 :-(
5
+
6
+ ##
7
+ # Provides Literals appropriate for your ruby version.
8
+ #--
9
+ # This set of literals is for Ruby 1.8 regular expressions.
10
+ }
11
+
12
+ Alphanumeric = /[0-9A-Za-z\200-\377]/n
13
+ AlphanumericAscii = /[A-Za-z0-9]/
14
+ LowerAlphabetAscii = /[a-z]/
15
+ Digit = /[0-9]/
16
+ BOM = "\357\273\277"
17
+ Newline = /\n|\r\n?/
18
+ NonAlphanumeric = /[\000-\057\072-\100\133-\140\173-\177]/n
19
+ Spacechar = / |\t/
@@ -0,0 +1,432 @@
1
+ $KCODE='u' ## for Ruby 1.8 :-(
2
+
3
+ ##
4
+ # Provides Literals appropriate for your ruby version.
5
+ #--
6
+ # This set of literals is for Ruby 1.8 regular expressions.
7
+ class ReVIEW::Compiler::Literals
8
+ # :stopdoc:
9
+
10
+ # This is distinct from setup_parser so that a standalone parser
11
+ # can redefine #initialize and still have access to the proper
12
+ # parser setup code.
13
+ def initialize(str, debug=false)
14
+ setup_parser(str, debug)
15
+ end
16
+
17
+
18
+
19
+ # Prepares for parsing +str+. If you define a custom initialize you must
20
+ # call this method before #parse
21
+ def setup_parser(str, debug=false)
22
+ set_string str, 0
23
+ @memoizations = Hash.new { |h,k| h[k] = {} }
24
+ @result = nil
25
+ @failed_rule = nil
26
+ @failing_rule_offset = -1
27
+
28
+ setup_foreign_grammar
29
+ end
30
+
31
+ attr_reader :string
32
+ attr_reader :failing_rule_offset
33
+ attr_accessor :result, :pos
34
+
35
+ def current_column(target=pos)
36
+ if c = string.rindex("\n", target-1)
37
+ return target - c - 1
38
+ end
39
+
40
+ target + 1
41
+ end
42
+
43
+ def current_line(target=pos)
44
+ cur_offset = 0
45
+ cur_line = 0
46
+
47
+ string.each_line do |line|
48
+ cur_line += 1
49
+ cur_offset += line.size
50
+ return cur_line if cur_offset >= target
51
+ end
52
+
53
+ -1
54
+ end
55
+
56
+ def lines
57
+ lines = []
58
+ string.each_line { |l| lines << l }
59
+ lines
60
+ end
61
+
62
+
63
+
64
+ def get_text(start)
65
+ @string[start..@pos-1]
66
+ end
67
+
68
+ # Sets the string and current parsing position for the parser.
69
+ def set_string string, pos
70
+ @string = string
71
+ @string_size = string ? string.size : 0
72
+ @pos = pos
73
+ end
74
+
75
+ def show_pos
76
+ width = 10
77
+ if @pos < width
78
+ "#{@pos} (\"#{@string[0,@pos]}\" @ \"#{@string[@pos,width]}\")"
79
+ else
80
+ "#{@pos} (\"... #{@string[@pos - width, width]}\" @ \"#{@string[@pos,width]}\")"
81
+ end
82
+ end
83
+
84
+ def failure_info
85
+ l = current_line @failing_rule_offset
86
+ c = current_column @failing_rule_offset
87
+
88
+ if @failed_rule.kind_of? Symbol
89
+ info = self.class::Rules[@failed_rule]
90
+ "line #{l}, column #{c}: failed rule '#{info.name}' = '#{info.rendered}'"
91
+ else
92
+ "line #{l}, column #{c}: failed rule '#{@failed_rule}'"
93
+ end
94
+ end
95
+
96
+ def failure_caret
97
+ l = current_line @failing_rule_offset
98
+ c = current_column @failing_rule_offset
99
+
100
+ line = lines[l-1]
101
+ "#{line}\n#{' ' * (c - 1)}^"
102
+ end
103
+
104
+ def failure_character
105
+ l = current_line @failing_rule_offset
106
+ c = current_column @failing_rule_offset
107
+ lines[l-1][c-1, 1]
108
+ end
109
+
110
+ def failure_oneline
111
+ l = current_line @failing_rule_offset
112
+ c = current_column @failing_rule_offset
113
+
114
+ char = lines[l-1][c-1, 1]
115
+
116
+ if @failed_rule.kind_of? Symbol
117
+ info = self.class::Rules[@failed_rule]
118
+ "@#{l}:#{c} failed rule '#{info.name}', got '#{char}'"
119
+ else
120
+ "@#{l}:#{c} failed rule '#{@failed_rule}', got '#{char}'"
121
+ end
122
+ end
123
+
124
+ class ParseError < RuntimeError
125
+ end
126
+
127
+ def raise_error
128
+ raise ParseError, failure_oneline
129
+ end
130
+
131
+ def show_error(io=STDOUT)
132
+ error_pos = @failing_rule_offset
133
+ line_no = current_line(error_pos)
134
+ col_no = current_column(error_pos)
135
+
136
+ io.puts "On line #{line_no}, column #{col_no}:"
137
+
138
+ if @failed_rule.kind_of? Symbol
139
+ info = self.class::Rules[@failed_rule]
140
+ io.puts "Failed to match '#{info.rendered}' (rule '#{info.name}')"
141
+ else
142
+ io.puts "Failed to match rule '#{@failed_rule}'"
143
+ end
144
+
145
+ io.puts "Got: #{string[error_pos,1].inspect}"
146
+ line = lines[line_no-1]
147
+ io.puts "=> #{line}"
148
+ io.print(" " * (col_no + 3))
149
+ io.puts "^"
150
+ end
151
+
152
+ def set_failed_rule(name)
153
+ if @pos > @failing_rule_offset
154
+ @failed_rule = name
155
+ @failing_rule_offset = @pos
156
+ end
157
+ end
158
+
159
+ attr_reader :failed_rule
160
+
161
+ def match_string(str)
162
+ len = str.size
163
+ if @string[pos,len] == str
164
+ @pos += len
165
+ return str
166
+ end
167
+
168
+ return nil
169
+ end
170
+
171
+ def scan(reg)
172
+ if m = reg.match(@string[@pos..-1])
173
+ width = m.end(0)
174
+ @pos += width
175
+ return true
176
+ end
177
+
178
+ return nil
179
+ end
180
+
181
+ if "".respond_to? :ord
182
+ def get_byte
183
+ if @pos >= @string_size
184
+ return nil
185
+ end
186
+
187
+ s = @string[@pos].ord
188
+ @pos += 1
189
+ s
190
+ end
191
+ else
192
+ def get_byte
193
+ if @pos >= @string_size
194
+ return nil
195
+ end
196
+
197
+ s = @string[@pos]
198
+ @pos += 1
199
+ s
200
+ end
201
+ end
202
+
203
+ def parse(rule=nil)
204
+ # We invoke the rules indirectly via apply
205
+ # instead of by just calling them as methods because
206
+ # if the rules use left recursion, apply needs to
207
+ # manage that.
208
+
209
+ if !rule
210
+ apply(:_root)
211
+ else
212
+ method = rule.gsub("-","_hyphen_")
213
+ apply :"_#{method}"
214
+ end
215
+ end
216
+
217
+ class MemoEntry
218
+ def initialize(ans, pos)
219
+ @ans = ans
220
+ @pos = pos
221
+ @result = nil
222
+ @set = false
223
+ @left_rec = false
224
+ end
225
+
226
+ attr_reader :ans, :pos, :result, :set
227
+ attr_accessor :left_rec
228
+
229
+ def move!(ans, pos, result)
230
+ @ans = ans
231
+ @pos = pos
232
+ @result = result
233
+ @set = true
234
+ @left_rec = false
235
+ end
236
+ end
237
+
238
+ def external_invoke(other, rule, *args)
239
+ old_pos = @pos
240
+ old_string = @string
241
+
242
+ set_string other.string, other.pos
243
+
244
+ begin
245
+ if val = __send__(rule, *args)
246
+ other.pos = @pos
247
+ other.result = @result
248
+ else
249
+ other.set_failed_rule "#{self.class}##{rule}"
250
+ end
251
+ val
252
+ ensure
253
+ set_string old_string, old_pos
254
+ end
255
+ end
256
+
257
+ def apply_with_args(rule, *args)
258
+ memo_key = [rule, args]
259
+ if m = @memoizations[memo_key][@pos]
260
+ @pos = m.pos
261
+ if !m.set
262
+ m.left_rec = true
263
+ return nil
264
+ end
265
+
266
+ @result = m.result
267
+
268
+ return m.ans
269
+ else
270
+ m = MemoEntry.new(nil, @pos)
271
+ @memoizations[memo_key][@pos] = m
272
+ start_pos = @pos
273
+
274
+ ans = __send__ rule, *args
275
+
276
+ lr = m.left_rec
277
+
278
+ m.move! ans, @pos, @result
279
+
280
+ # Don't bother trying to grow the left recursion
281
+ # if it's failing straight away (thus there is no seed)
282
+ if ans and lr
283
+ return grow_lr(rule, args, start_pos, m)
284
+ else
285
+ return ans
286
+ end
287
+
288
+ return ans
289
+ end
290
+ end
291
+
292
+ def apply(rule)
293
+ if m = @memoizations[rule][@pos]
294
+ @pos = m.pos
295
+ if !m.set
296
+ m.left_rec = true
297
+ return nil
298
+ end
299
+
300
+ @result = m.result
301
+
302
+ return m.ans
303
+ else
304
+ m = MemoEntry.new(nil, @pos)
305
+ @memoizations[rule][@pos] = m
306
+ start_pos = @pos
307
+
308
+ ans = __send__ rule
309
+
310
+ lr = m.left_rec
311
+
312
+ m.move! ans, @pos, @result
313
+
314
+ # Don't bother trying to grow the left recursion
315
+ # if it's failing straight away (thus there is no seed)
316
+ if ans and lr
317
+ return grow_lr(rule, nil, start_pos, m)
318
+ else
319
+ return ans
320
+ end
321
+
322
+ return ans
323
+ end
324
+ end
325
+
326
+ def grow_lr(rule, args, start_pos, m)
327
+ while true
328
+ @pos = start_pos
329
+ @result = m.result
330
+
331
+ if args
332
+ ans = __send__ rule, *args
333
+ else
334
+ ans = __send__ rule
335
+ end
336
+ return nil unless ans
337
+
338
+ break if @pos <= m.pos
339
+
340
+ m.move! ans, @pos, @result
341
+ end
342
+
343
+ @result = m.result
344
+ @pos = m.pos
345
+ return m.ans
346
+ end
347
+
348
+ class RuleInfo
349
+ def initialize(name, rendered)
350
+ @name = name
351
+ @rendered = rendered
352
+ end
353
+
354
+ attr_reader :name, :rendered
355
+ end
356
+
357
+ def self.rule_info(name, rendered)
358
+ RuleInfo.new(name, rendered)
359
+ end
360
+
361
+
362
+ # :startdoc:
363
+ # :stopdoc:
364
+ def setup_foreign_grammar; end
365
+
366
+ # Alphanumeric = /[0-9A-Za-z\200-\377]/n
367
+ def _Alphanumeric
368
+ _tmp = scan(/\A(?-mix:[0-9A-Za-z\200-\377])/)
369
+ set_failed_rule :_Alphanumeric unless _tmp
370
+ return _tmp
371
+ end
372
+
373
+ # AlphanumericAscii = /[A-Za-z0-9]/
374
+ def _AlphanumericAscii
375
+ _tmp = scan(/\A(?-mix:[A-Za-z0-9])/)
376
+ set_failed_rule :_AlphanumericAscii unless _tmp
377
+ return _tmp
378
+ end
379
+
380
+ # LowerAlphabetAscii = /[a-z]/
381
+ def _LowerAlphabetAscii
382
+ _tmp = scan(/\A(?-mix:[a-z])/)
383
+ set_failed_rule :_LowerAlphabetAscii unless _tmp
384
+ return _tmp
385
+ end
386
+
387
+ # Digit = /[0-9]/
388
+ def _Digit
389
+ _tmp = scan(/\A(?-mix:[0-9])/)
390
+ set_failed_rule :_Digit unless _tmp
391
+ return _tmp
392
+ end
393
+
394
+ # BOM = ""
395
+ def _BOM
396
+ _tmp = match_string("\u{ef}\u{bb}\u{bf}")
397
+ set_failed_rule :_BOM unless _tmp
398
+ return _tmp
399
+ end
400
+
401
+ # Newline = /\n|\r\n?/
402
+ def _Newline
403
+ _tmp = scan(/\A(?-mix:\n|\r\n?)/)
404
+ set_failed_rule :_Newline unless _tmp
405
+ return _tmp
406
+ end
407
+
408
+ # NonAlphanumeric = /[\000-\057\072-\100\133-\140\173-\177]/n
409
+ def _NonAlphanumeric
410
+ _tmp = scan(/\A(?-mix:[\000-\057\072-\100\133-\140\173-\177])/)
411
+ set_failed_rule :_NonAlphanumeric unless _tmp
412
+ return _tmp
413
+ end
414
+
415
+ # Spacechar = / |\t/
416
+ def _Spacechar
417
+ _tmp = scan(/\A(?-mix: |\t)/)
418
+ set_failed_rule :_Spacechar unless _tmp
419
+ return _tmp
420
+ end
421
+
422
+ Rules = {}
423
+ Rules[:_Alphanumeric] = rule_info("Alphanumeric", "/[0-9A-Za-z\\200-\\377]/n")
424
+ Rules[:_AlphanumericAscii] = rule_info("AlphanumericAscii", "/[A-Za-z0-9]/")
425
+ Rules[:_LowerAlphabetAscii] = rule_info("LowerAlphabetAscii", "/[a-z]/")
426
+ Rules[:_Digit] = rule_info("Digit", "/[0-9]/")
427
+ Rules[:_BOM] = rule_info("BOM", "\"\"")
428
+ Rules[:_Newline] = rule_info("Newline", "/\\n|\\r\\n?/")
429
+ Rules[:_NonAlphanumeric] = rule_info("NonAlphanumeric", "/[\\000-\\057\\072-\\100\\133-\\140\\173-\\177]/n")
430
+ Rules[:_Spacechar] = rule_info("Spacechar", "/ |\\t/")
431
+ # :startdoc:
432
+ end