review 3.0.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby-win.yml +39 -0
  3. data/.github/workflows/ruby.yml +27 -0
  4. data/.rubocop.yml +50 -12
  5. data/.travis.yml +17 -8
  6. data/Dockerfile +21 -5
  7. data/NEWS.ja.md +358 -0
  8. data/NEWS.md +358 -1
  9. data/README.md +11 -8
  10. data/appveyor.yml +1 -3
  11. data/bin/review-catalog-converter +4 -4
  12. data/bin/review-check +8 -8
  13. data/bin/review-checkdep +1 -1
  14. data/bin/review-compile +12 -12
  15. data/bin/review-epubmaker +3 -35
  16. data/bin/review-idgxmlmaker +16 -0
  17. data/bin/review-index +2 -89
  18. data/bin/review-preproc +14 -19
  19. data/bin/review-validate +3 -3
  20. data/bin/review-vol +4 -78
  21. data/doc/LICENSE +1 -1
  22. data/doc/config.yml.sample +46 -12
  23. data/doc/config.yml.sample-simple +4 -2
  24. data/doc/format.ja.md +37 -13
  25. data/doc/format.md +35 -20
  26. data/doc/pdfmaker.ja.md +43 -1
  27. data/doc/pdfmaker.md +42 -1
  28. data/doc/quickstart.ja.md +46 -26
  29. data/doc/quickstart.md +38 -17
  30. data/lib/epubmaker/epubcommon.rb +10 -5
  31. data/lib/epubmaker/epubv2.rb +1 -1
  32. data/lib/epubmaker/epubv3.rb +1 -0
  33. data/lib/epubmaker/producer.rb +4 -2
  34. data/lib/review/book.rb +1 -1
  35. data/lib/review/book/base.rb +38 -79
  36. data/lib/review/book/chapter.rb +18 -3
  37. data/lib/review/book/compilable.rb +6 -5
  38. data/lib/review/book/index.rb +69 -101
  39. data/lib/review/book/index/item.rb +40 -0
  40. data/lib/review/book/page_metric.rb +7 -7
  41. data/lib/review/book/part.rb +28 -5
  42. data/lib/review/book/volume.rb +3 -4
  43. data/lib/review/builder.rb +105 -44
  44. data/lib/review/catalog.rb +13 -16
  45. data/lib/review/compiler.rb +84 -72
  46. data/lib/review/configure.rb +19 -8
  47. data/lib/review/epub2html.rb +37 -4
  48. data/lib/review/epubmaker.rb +62 -7
  49. data/lib/review/extentions/string.rb +0 -4
  50. data/lib/review/htmlbuilder.rb +102 -115
  51. data/lib/review/htmlutils.rb +2 -3
  52. data/lib/review/i18n.rb +2 -2
  53. data/lib/review/i18n.yml +9 -0
  54. data/lib/review/idgxmlbuilder.rb +153 -74
  55. data/lib/review/idgxmlmaker.rb +191 -0
  56. data/lib/review/init-web/finish.html +10 -0
  57. data/lib/review/init-web/index.html +190 -0
  58. data/lib/review/init-web/review-layout-design.js +691 -0
  59. data/lib/review/init.rb +125 -34
  60. data/lib/review/latexbuilder.rb +199 -88
  61. data/lib/review/lineinput.rb +1 -1
  62. data/lib/review/location.rb +32 -0
  63. data/lib/review/logger.rb +4 -8
  64. data/lib/review/makerhelper.rb +24 -5
  65. data/lib/review/markdownbuilder.rb +31 -37
  66. data/lib/review/md2inaobuilder.rb +3 -5
  67. data/lib/review/pdfmaker.rb +44 -22
  68. data/lib/review/plaintextbuilder.rb +106 -85
  69. data/lib/review/preprocessor.rb +32 -41
  70. data/lib/review/rstbuilder.rb +33 -33
  71. data/lib/review/textmaker.rb +19 -3
  72. data/lib/review/textutils.rb +76 -2
  73. data/lib/review/tocprinter.rb +231 -102
  74. data/lib/review/topbuilder.rb +114 -61
  75. data/lib/review/update.rb +19 -19
  76. data/lib/review/version.rb +1 -1
  77. data/lib/review/volumeprinter.rb +99 -0
  78. data/lib/review/webmaker.rb +11 -4
  79. data/lib/review/webtocprinter.rb +38 -35
  80. data/lib/review/yamlloader.rb +26 -16
  81. data/review.gemspec +6 -4
  82. data/samples/sample-book/README.md +7 -2
  83. data/samples/sample-book/src/.gitignore +154 -0
  84. data/samples/sample-book/src/config-ebook.yml +4 -0
  85. data/samples/sample-book/src/config-jlreq-ebook.yml +4 -0
  86. data/samples/sample-book/src/config-jlreq.yml +6 -0
  87. data/samples/sample-book/src/config.yml +2 -2
  88. data/samples/sample-book/src/lib/tasks/review.rake +29 -14
  89. data/samples/sample-book/src/lib/tasks/z01_copy_sty.rake +14 -8
  90. data/samples/syntax-book/ch01.re +4 -2
  91. data/samples/syntax-book/ch02.re +8 -16
  92. data/samples/syntax-book/ch03.re +3 -6
  93. data/samples/syntax-book/config-jlreq-lualatex.yml +4 -0
  94. data/samples/syntax-book/config-jlreq.yml +5 -0
  95. data/samples/syntax-book/config-print.yml +3 -0
  96. data/samples/syntax-book/config.yml +1 -1
  97. data/samples/syntax-book/lib/tasks/review.rake +30 -15
  98. data/samples/syntax-book/lib/tasks/z01_copy_sty.rake +14 -8
  99. data/templates/latex/config.erb +16 -0
  100. data/templates/latex/layout.tex.erb +4 -0
  101. data/templates/latex/review-jlreq/review-base.sty +150 -61
  102. data/templates/latex/review-jlreq/review-jlreq.cls +74 -8
  103. data/templates/latex/review-jlreq/review-style.sty +4 -1
  104. data/templates/latex/review-jsbook/README.md +39 -0
  105. data/templates/latex/review-jsbook/review-base.sty +101 -23
  106. data/templates/latex/review-jsbook/review-jsbook.cls +28 -5
  107. data/templates/latex/review-jsbook/review-style.sty +5 -2
  108. data/templates/opf/epubv3.opf.erb +1 -0
  109. data/templates/web/html/layout-html5.html.erb +2 -2
  110. data/test/assets/test_template.tex +24 -3
  111. data/test/assets/test_template_backmatter.tex +24 -3
  112. data/test/test_book.rb +75 -21
  113. data/test/test_book_chapter.rb +4 -2
  114. data/test/test_book_part.rb +3 -3
  115. data/test/test_builder.rb +16 -0
  116. data/test/test_catalog.rb +24 -42
  117. data/test/test_catalog_converter_cmd.rb +1 -1
  118. data/test/test_epubmaker_cmd.rb +14 -7
  119. data/test/test_helper.rb +15 -7
  120. data/test/test_htmlbuilder.rb +909 -159
  121. data/test/test_i18n.rb +25 -25
  122. data/test/test_idgxmlbuilder.rb +395 -38
  123. data/test/test_idgxmlmaker_cmd.rb +46 -0
  124. data/test/test_image_finder.rb +52 -70
  125. data/test/test_index.rb +50 -10
  126. data/test/test_latexbuilder.rb +1194 -106
  127. data/test/test_latexbuilder_v2.rb +628 -97
  128. data/test/test_logger.rb +14 -1
  129. data/test/test_makerhelper.rb +3 -3
  130. data/test/test_markdownbuilder.rb +134 -16
  131. data/test/test_md2inaobuilder.rb +32 -9
  132. data/test/test_pdfmaker.rb +18 -1
  133. data/test/test_pdfmaker_cmd.rb +100 -6
  134. data/test/test_plaintextbuilder.rb +371 -25
  135. data/test/test_preprocessor.rb +2 -16
  136. data/test/test_rstbuilder.rb +249 -26
  137. data/test/test_textmaker_cmd.rb +54 -0
  138. data/test/test_textutils.rb +109 -2
  139. data/test/test_topbuilder.rb +546 -31
  140. data/test/test_update.rb +17 -8
  141. data/test/test_webtocprinter.rb +66 -34
  142. data/test/test_yamlloader.rb +13 -0
  143. data/vendor/jsclasses/LICENSE +1 -1
  144. data/vendor/jsclasses/jis/jsarticle.cls +53 -14
  145. data/vendor/jsclasses/jis/jsbook.cls +53 -14
  146. data/vendor/jsclasses/jis/jsclasses.dtx +84 -25
  147. data/vendor/jsclasses/jis/jslogo.dtx +4 -4
  148. data/vendor/jsclasses/jis/jslogo.sty +3 -3
  149. data/vendor/jsclasses/jis/jspf.cls +52 -13
  150. data/vendor/jsclasses/jis/jsreport.cls +53 -14
  151. data/vendor/jsclasses/jis/kiyou.cls +53 -14
  152. data/vendor/jsclasses/jis/okumacro.dtx +4 -5
  153. data/vendor/jsclasses/jis/okumacro.sty +3 -4
  154. data/vendor/jsclasses/jsarticle.cls +53 -14
  155. data/vendor/jsclasses/jsbook.cls +53 -14
  156. data/vendor/jsclasses/jsclasses.dtx +84 -25
  157. data/vendor/jsclasses/jsclasses.pdf +0 -0
  158. data/vendor/jsclasses/jslogo.dtx +4 -4
  159. data/vendor/jsclasses/jslogo.pdf +0 -0
  160. data/vendor/jsclasses/jslogo.sty +3 -3
  161. data/vendor/jsclasses/jspf.cls +52 -13
  162. data/vendor/jsclasses/jsreport.cls +53 -14
  163. data/vendor/jsclasses/kiyou.cls +53 -14
  164. data/vendor/jsclasses/okumacro.dtx +4 -5
  165. data/vendor/jsclasses/okumacro.pdf +0 -0
  166. data/vendor/jsclasses/okumacro.sty +3 -4
  167. metadata +55 -10
  168. data/lib/review/tocparser.rb +0 -271
  169. data/samples/syntax-book/review-ext.rb +0 -14
  170. data/test/test_tocparser.rb +0 -25
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2018 Kenshi Muto
1
+ # Copyright (c) 2018-2020 Kenshi Muto
2
2
  #
3
3
  # This program is free software.
4
4
  # You can distribute or modify this program under the terms of
@@ -87,7 +87,7 @@ module ReVIEW
87
87
  end
88
88
 
89
89
  def ul_item(lines)
90
- puts lines.join
90
+ puts join_lines_to_paragraph(lines)
91
91
  end
92
92
 
93
93
  def ul_end
@@ -100,7 +100,7 @@ module ReVIEW
100
100
  end
101
101
 
102
102
  def ol_item(lines, num)
103
- puts "#{num} #{lines.join}"
103
+ puts "#{num} #{join_lines_to_paragraph(lines)}"
104
104
  end
105
105
 
106
106
  def ol_end
@@ -127,7 +127,7 @@ module ReVIEW
127
127
  end
128
128
 
129
129
  def paragraph(lines)
130
- puts lines.join
130
+ puts join_lines_to_paragraph(lines)
131
131
  end
132
132
 
133
133
  def read(lines)
@@ -137,27 +137,47 @@ module ReVIEW
137
137
 
138
138
  alias_method :lead, :read
139
139
 
140
- def list_header(id, caption, _lang)
140
+ def list(lines, id, caption, lang = nil)
141
+ blank
142
+ begin
143
+ if caption_top?('list')
144
+ list_header(id, caption, lang)
145
+ blank
146
+ end
147
+ list_body(id, lines, lang)
148
+ unless caption_top?('list')
149
+ blank
150
+ list_header(id, caption, lang)
151
+ end
152
+ rescue KeyError
153
+ error "no such list: #{id}"
154
+ end
141
155
  blank
156
+ end
157
+
158
+ def list_header(id, caption, _lang)
142
159
  if get_chap
143
160
  puts %Q(#{I18n.t('list')}#{I18n.t('format_number', [get_chap, @chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)})
144
161
  else
145
162
  puts %Q(#{I18n.t('list')}#{I18n.t('format_number_without_chapter', [@chapter.list(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)})
146
163
  end
147
- blank
148
164
  end
149
165
 
150
166
  def list_body(_id, lines, _lang)
151
167
  lines.each do |line|
152
168
  puts detab(line)
153
169
  end
154
- blank
155
170
  end
156
171
 
157
172
  def base_block(_type, lines, caption = nil)
158
173
  blank
159
- puts compile_inline(caption) if caption.present?
174
+ if caption_top?('list') && caption.present?
175
+ puts compile_inline(caption)
176
+ end
160
177
  puts lines.join("\n")
178
+ if !caption_top?('list') && caption.present?
179
+ puts compile_inline(caption)
180
+ end
161
181
  blank
162
182
  end
163
183
 
@@ -169,15 +189,38 @@ module ReVIEW
169
189
  end
170
190
 
171
191
  def emlist(lines, caption = nil, _lang = nil)
172
- base_block 'emlist', lines, caption
192
+ base_block('emlist', lines, caption)
173
193
  end
174
194
 
175
195
  def emlistnum(lines, caption = nil, _lang = nil)
176
196
  blank
177
- puts compile_inline(caption) if caption.present?
197
+ if caption_top?('list')
198
+ puts compile_inline(caption) if caption.present?
199
+ end
178
200
  lines.each_with_index do |line, i|
179
201
  puts((i + 1).to_s.rjust(2) + ": #{line}")
180
202
  end
203
+ unless caption_top?('list')
204
+ puts compile_inline(caption) if caption.present?
205
+ end
206
+ blank
207
+ end
208
+
209
+ def listnum(lines, id, caption, lang = nil)
210
+ blank
211
+ begin
212
+ if caption_top?('list')
213
+ list_header(id, caption, lang)
214
+ blank
215
+ end
216
+ listnum_body(lines, lang)
217
+ unless caption_top?('list')
218
+ blank
219
+ list_header(id, caption, lang)
220
+ end
221
+ rescue KeyError
222
+ error "no such list: #{id}"
223
+ end
181
224
  blank
182
225
  end
183
226
 
@@ -185,15 +228,14 @@ module ReVIEW
185
228
  lines.each_with_index do |line, i|
186
229
  puts((i + 1).to_s.rjust(2) + ": #{line}")
187
230
  end
188
- blank
189
231
  end
190
232
 
191
233
  def cmd(lines, caption = nil)
192
- base_block 'cmd', lines, caption
234
+ base_block('cmd', lines, caption)
193
235
  end
194
236
 
195
237
  def quote(lines)
196
- base_parablock 'quote', lines, nil
238
+ base_parablock('quote', lines, nil)
197
239
  end
198
240
 
199
241
  def image(_lines, id, caption, _metric = nil)
@@ -207,58 +249,35 @@ module ReVIEW
207
249
  end
208
250
 
209
251
  def texequation(lines, id = nil, caption = '')
252
+ blank
253
+ texequation_header(id, caption) if caption_top?('equation')
254
+ puts lines.join("\n")
255
+ texequation_header(id, caption) unless caption_top?('equation')
256
+ blank
257
+ end
258
+
259
+ def texequation_header(id, caption)
210
260
  if id
211
- blank
212
261
  if get_chap
213
262
  puts "#{I18n.t('equation')}#{I18n.t('format_number', [get_chap, @chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
214
263
  else
215
264
  puts "#{I18n.t('equation')}#{I18n.t('format_number_without_chapter', [@chapter.equation(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
216
265
  end
217
266
  end
218
-
219
- puts lines.join("\n")
220
- blank
221
267
  end
222
268
 
223
- def table(lines, id = nil, caption = nil)
224
- blank
225
- rows = []
226
- sepidx = nil
227
- lines.each_with_index do |line, idx|
228
- if /\A[\=\-]{12}/ =~ line
229
- # just ignore
230
- # error "too many table separator" if sepidx
231
- sepidx ||= idx
232
- next
233
- end
234
- rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
235
- end
236
- rows = adjust_n_cols(rows)
237
-
238
- begin
239
- table_header(id, caption) if caption.present?
240
- rescue KeyError
241
- error "no such table: #{id}"
242
- end
243
- return if rows.empty?
244
- table_begin rows.first.size
245
- if sepidx
246
- sepidx.times do
247
- tr(rows.shift.map { |s| th(s) })
248
- end
249
- rows.each do |cols|
250
- tr(cols.map { |s| td(s) })
251
- end
252
- else
253
- rows.each do |cols|
254
- h, *cs = *cols
255
- tr([th(h)] + cs.map { |s| td(s) })
256
- end
269
+ def table(lines, id = nil, caption = nil, noblank = nil)
270
+ unless noblank
271
+ blank
257
272
  end
258
- table_end
273
+ super(lines, id, caption)
259
274
  end
260
275
 
261
276
  def table_header(id, caption)
277
+ unless caption_top?('table')
278
+ blank
279
+ end
280
+
262
281
  if id.nil?
263
282
  puts compile_inline(caption)
264
283
  elsif get_chap
@@ -266,7 +285,10 @@ module ReVIEW
266
285
  else
267
286
  puts "#{I18n.t('table')}#{I18n.t('format_number_without_chapter', [@chapter.table(id).number])}#{I18n.t('caption_prefix_idgxml')}#{compile_inline(caption)}"
268
287
  end
269
- blank
288
+
289
+ if caption_top?('table')
290
+ blank
291
+ end
270
292
  end
271
293
 
272
294
  def table_begin(_ncols)
@@ -344,8 +366,8 @@ module ReVIEW
344
366
  end
345
367
 
346
368
  def bibpaper(lines, id, caption)
347
- bibpaper_header id, caption
348
- bibpaper_bibpaper id, caption, lines unless lines.empty?
369
+ bibpaper_header(id, caption)
370
+ bibpaper_bibpaper(id, caption, lines) unless lines.empty?
349
371
  end
350
372
 
351
373
  def bibpaper_header(id, caption)
@@ -354,7 +376,7 @@ module ReVIEW
354
376
  end
355
377
 
356
378
  def bibpaper_bibpaper(_id, _caption, lines)
357
- print split_paragraph(lines).join
379
+ puts split_paragraph(lines).join("\n")
358
380
  end
359
381
 
360
382
  def inline_bib(id)
@@ -364,13 +386,12 @@ module ReVIEW
364
386
  end
365
387
 
366
388
  def inline_hd_chap(chap, id)
367
- if chap.number
368
- n = chap.headline_index.number(id)
369
- if @book.config['secnolevel'] >= n.split('.').size
370
- return I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
371
- end
389
+ n = chap.headline_index.number(id)
390
+ if n.present? && chap.number && over_secnolevel?(n)
391
+ I18n.t('hd_quote', [n, compile_inline(chap.headline(id).caption)])
392
+ else
393
+ I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
372
394
  end
373
- I18n.t('hd_quote_without_number', compile_inline(chap.headline(id).caption))
374
395
  rescue KeyError
375
396
  error "unknown headline: #{id}"
376
397
  end
@@ -472,87 +493,87 @@ module ReVIEW
472
493
  end
473
494
 
474
495
  def flushright(lines)
475
- base_parablock 'flushright', lines, nil
496
+ base_parablock('flushright', lines, nil)
476
497
  end
477
498
 
478
499
  def centering(lines)
479
- base_parablock 'centering', lines, nil
500
+ base_parablock('centering', lines, nil)
480
501
  end
481
502
 
482
503
  def note(lines, caption = nil)
483
- base_parablock 'note', lines, caption
504
+ base_parablock('note', lines, caption)
484
505
  end
485
506
 
486
507
  def memo(lines, caption = nil)
487
- base_parablock 'memo', lines, caption
508
+ base_parablock('memo', lines, caption)
488
509
  end
489
510
 
490
511
  def tip(lines, caption = nil)
491
- base_parablock 'tip', lines, caption
512
+ base_parablock('tip', lines, caption)
492
513
  end
493
514
 
494
515
  def info(lines, caption = nil)
495
- base_parablock 'info', lines, caption
516
+ base_parablock('info', lines, caption)
496
517
  end
497
518
 
498
519
  def planning(lines, caption = nil)
499
- base_parablock 'planning', lines, caption
520
+ base_parablock('planning', lines, caption)
500
521
  end
501
522
 
502
523
  def best(lines, caption = nil)
503
- base_parablock 'best', lines, caption
524
+ base_parablock('best', lines, caption)
504
525
  end
505
526
 
506
527
  def important(lines, caption = nil)
507
- base_parablock 'important', lines, caption
528
+ base_parablock('important', lines, caption)
508
529
  end
509
530
 
510
531
  def security(lines, caption = nil)
511
- base_parablock 'security', lines, caption
532
+ base_parablock('security', lines, caption)
512
533
  end
513
534
 
514
535
  def caution(lines, caption = nil)
515
- base_parablock 'caution', lines, caption
536
+ base_parablock('caution', lines, caption)
516
537
  end
517
538
 
518
539
  def term(lines)
519
- base_parablock 'term', lines, nil
540
+ base_parablock('term', lines, nil)
520
541
  end
521
542
 
522
543
  def link(lines, caption = nil)
523
- base_parablock 'link', lines, caption
544
+ base_parablock('link', lines, caption)
524
545
  end
525
546
 
526
547
  def notice(lines, caption = nil)
527
- base_parablock 'notice', lines, caption
548
+ base_parablock('notice', lines, caption)
528
549
  end
529
550
 
530
551
  def point(lines, caption = nil)
531
- base_parablock 'point', lines, caption
552
+ base_parablock('point', lines, caption)
532
553
  end
533
554
 
534
555
  def shoot(lines, caption = nil)
535
- base_parablock 'shoot', lines, caption
556
+ base_parablock('shoot', lines, caption)
536
557
  end
537
558
 
538
559
  def reference(lines)
539
- base_parablock 'reference', lines, nil
560
+ base_parablock('reference', lines, nil)
540
561
  end
541
562
 
542
563
  def practice(lines)
543
- base_parablock 'practice', lines, nil
564
+ base_parablock('practice', lines, nil)
544
565
  end
545
566
 
546
567
  def expert(lines)
547
- base_parablock 'expert', lines, nil
568
+ base_parablock('expert', lines, nil)
548
569
  end
549
570
 
550
571
  def insn(lines, caption = nil)
551
- base_block 'insn', lines, caption
572
+ base_block('insn', lines, caption)
552
573
  end
553
574
 
554
575
  def warning(lines, caption = nil)
555
- base_parablock 'warning', lines, caption
576
+ base_parablock('warning', lines, caption)
556
577
  end
557
578
 
558
579
  alias_method :box, :insn
@@ -573,7 +594,7 @@ module ReVIEW
573
594
  end
574
595
 
575
596
  def bpo(lines)
576
- base_block 'bpo', lines, nil
597
+ base_block('bpo', lines, nil)
577
598
  end
578
599
 
579
600
  def inline_dtp(_str)
@@ -623,7 +644,7 @@ module ReVIEW
623
644
  end
624
645
 
625
646
  def source(lines, caption = nil, _lang = nil)
626
- base_block 'source', lines, caption
647
+ base_block('source', lines, caption)
627
648
  end
628
649
 
629
650
  def inline_labelref(_idref)
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2017 Minero Aoki, Kenshi Muto
1
+ # Copyright (c) 2010-2019 Minero Aoki, Kenshi Muto
2
2
  # 2002-2009 Minero Aoki
3
3
  #
4
4
  # This program is free software.
@@ -43,41 +43,20 @@ module ReVIEW
43
43
  class Preprocessor
44
44
  include ErrorUtils
45
45
 
46
- class Strip
47
- def initialize(f)
48
- @f = f
49
- end
50
-
51
- def path
52
- @f.path
53
- end
54
-
55
- def lineno
56
- @f.lineno
57
- end
58
-
59
- def gets
60
- @f.each_line do |line|
61
- return "\#@\#\n" if /\A\#@/ =~ line
62
- return line
63
- end
64
- nil
65
- end
66
- end
67
-
68
46
  def initialize(repo, param)
69
47
  @repository = repo
70
48
  @config = param
71
49
  @logger = ReVIEW.logger
50
+ @leave_content = nil
72
51
  end
73
52
 
74
53
  def process(inf, outf)
75
- init_errorutils inf
54
+ init_errorutils(inf)
76
55
  @f = outf
77
56
  begin
78
- preproc inf
79
- rescue Errno::ENOENT => err
80
- error err.message
57
+ preproc(inf)
58
+ rescue Errno::ENOENT => e
59
+ error e.message
81
60
  end
82
61
  end
83
62
 
@@ -101,11 +80,12 @@ module ReVIEW
101
80
  direc = parse_directive(line, 1, 'stderr')
102
81
  @f.print line
103
82
  get_output(expand(direc.arg), direc['stderr']).each { |out| @f.print out.string }
104
- skip_list f
83
+ skip_list(f)
105
84
 
106
85
  when /\A\#@mapfile/
107
86
  direc = parse_directive(line, 1, 'eval')
108
87
  path = expand(direc.arg)
88
+ @leave_content = File.extname(path) == '.re'
109
89
  if direc['eval']
110
90
  ent = evaluate(path, ent)
111
91
  else
@@ -116,6 +96,7 @@ module ReVIEW
116
96
  when /\A\#@map(?:range)?/
117
97
  direc = parse_directive(line, 2, 'unindent')
118
98
  path = expand(direc.args[0])
99
+ @leave_content = File.extname(path) == '.re'
119
100
  ent = @repository.fetch_range(path, direc.args[1]) or
120
101
  error "unknown range: #{path}: #{direc.args[1]}"
121
102
  ent = (direc['unindent'] ? unindent(ent, direc['unindent']) : ent)
@@ -127,6 +108,9 @@ module ReVIEW
127
108
  when /\A\#@/
128
109
  op = line.slice(/@(\w+)/, 1)
129
110
  warn "unknown directive: #{line.strip}" unless known_directive?(op)
111
+ if op == 'warn'
112
+ warn line.strip.sub(/\#@warn\((.+)\)/, '\1')
113
+ end
130
114
  @f.print line
131
115
 
132
116
  when /\A\s*\z/ # empty line
@@ -147,15 +131,15 @@ module ReVIEW
147
131
  @f.print directive_line
148
132
  newlines.each do |line|
149
133
  if with_lineno
150
- print_number line.number
134
+ print_number(line.number)
151
135
  end
152
136
  @f.print line.string
153
137
  end
154
- skip_list f
138
+ skip_list(f)
155
139
  end
156
140
 
157
141
  def print_number(num)
158
- @f.printf '%4s ', (num ? num.to_s : '')
142
+ @f.printf('%4s ', (num ? num.to_s : ''))
159
143
  end
160
144
 
161
145
  def skip_list(f)
@@ -166,9 +150,11 @@ module ReVIEW
166
150
  @f.print line
167
151
  return nil
168
152
  when %r{\A//\}}
169
- warn '//} seen in list'
170
- @f.print line
171
- return nil
153
+ unless @leave_content
154
+ warn '//} seen in list'
155
+ @f.print line
156
+ return nil
157
+ end
172
158
  when /\A\#@\w/
173
159
  warn "#{line.slice(/\A\#@\w+/)} seen in list"
174
160
  @f.print line
@@ -293,7 +279,7 @@ module ReVIEW
293
279
  Open3.popen3(cmd) do |_stdin, stdout, stderr|
294
280
  out = stdout.readlines
295
281
  if use_stderr
296
- out.concat stderr.readlines
282
+ out.concat(stderr.readlines)
297
283
  else
298
284
  err = stderr.readlines
299
285
  end
@@ -357,6 +343,7 @@ module ReVIEW
357
343
  private
358
344
 
359
345
  def file_descripter(fname)
346
+ @leave_content = File.extname(fname) == '.re'
360
347
  return @repository[fname] if @repository[fname]
361
348
 
362
349
  @repository[fname] = git?(fname) ? parse_git_blob(fname) : parse_file(fname)
@@ -374,7 +361,7 @@ module ReVIEW
374
361
  end
375
362
 
376
363
  def parse_file(fname)
377
- File.open(fname, 'r:BOM|utf-8') do |f|
364
+ File.open(fname, 'rt:BOM|utf-8') do |f|
378
365
  init_errorutils f
379
366
  return _parse_file(f)
380
367
  end
@@ -416,14 +403,14 @@ module ReVIEW
416
403
  error "begin x2: #{key}"
417
404
  end
418
405
  (repo[type] ||= {})[spec] = curr[key] = []
419
- opened.push [type, spec]
406
+ opened.push([type, spec])
420
407
 
421
408
  when %r{(?:\A\#@|\#@@)([a-z]+)/(\w+)\}}
422
409
  type = check_type($1)
423
410
  spec = check_spec($2)
424
411
  curr.delete("#{type}/#{spec}") or
425
412
  error "end before begin: #{type}/#{spec}"
426
- opened.delete "#{type}/#{spec}"
413
+ opened.delete("#{type}/#{spec}")
427
414
 
428
415
  when /(?:\A\#@|\#@@)\}/
429
416
  type, spec = opened.last
@@ -436,17 +423,17 @@ module ReVIEW
436
423
 
437
424
  when /\A\#@-/ # does not increment line number.
438
425
  line = canonical($')
439
- curr.each_value { |list| list.push Line.new(nil, line) }
426
+ curr.each_value { |list| list.push(Line.new(nil, line)) }
440
427
 
441
428
  else
442
429
  next if yacchack and line.strip == ';'
443
430
  line = canonical(line)
444
- curr.each_value { |list| list.push Line.new(lineno, line) }
431
+ curr.each_value { |list| list.push(Line.new(lineno, line)) }
445
432
  lineno += 1
446
433
  end
447
434
  end
448
435
  if curr.size > 1
449
- curr.delete 'WHOLE'
436
+ curr.delete('WHOLE')
450
437
  curr.each { |range, lines| @logger.warn "#{filename}: unclosed range: #{range} (begin @#{lines.first.number})" }
451
438
  raise ApplicationError, 'ERROR'
452
439
  end
@@ -455,6 +442,10 @@ module ReVIEW
455
442
  end
456
443
 
457
444
  def canonical(line)
445
+ if @leave_content
446
+ return line
447
+ end
448
+
458
449
  tabwidth = @config['tabwidth'] || 8
459
450
  if tabwidth > 0
460
451
  detab(line, tabwidth).rstrip + "\n"