review-peg 0.1.0

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