hemingway 0.0.0 → 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +297 -0
- data/Rakefile +1 -0
- data/hemingway.gemspec +23 -0
- data/lib/hemingway/block/block.rb +378 -0
- data/lib/hemingway/block/block.treetop +36 -0
- data/lib/hemingway/block/block_nodes.rb +9 -0
- data/lib/hemingway/block/list/list.rb +412 -0
- data/lib/hemingway/block/list/list.treetop +51 -0
- data/lib/hemingway/block/list/list_nodes.rb +39 -0
- data/lib/hemingway/block/quote/quote.rb +192 -0
- data/lib/hemingway/block/quote/quote.treetop +27 -0
- data/lib/hemingway/block/quote/quote_nodes.rb +25 -0
- data/lib/hemingway/block/verbatim/verbatim.rb +159 -0
- data/lib/hemingway/block/verbatim/verbatim.treetop +21 -0
- data/lib/hemingway/block/verbatim/verbatim_nodes.rb +9 -0
- data/lib/hemingway/build.rb +65 -0
- data/lib/hemingway/footnote/footnote.rb +83 -0
- data/lib/hemingway/footnote/footnote.treetop +11 -0
- data/lib/hemingway/footnote/footnote_nodes.rb +21 -0
- data/lib/hemingway/latex.rb +409 -0
- data/lib/hemingway/latex.treetop +81 -0
- data/lib/hemingway/latex_nodes.rb +45 -0
- data/lib/hemingway/math/math.rb +135 -0
- data/lib/hemingway/math/math.treetop +29 -0
- data/lib/hemingway/math/math_nodes.rb +7 -0
- data/lib/hemingway/special/special.rb +164 -0
- data/lib/hemingway/special/special.treetop +17 -0
- data/lib/hemingway/special/special_nodes.rb +7 -0
- data/lib/hemingway/symbol/symbol.rb +460 -0
- data/lib/hemingway/symbol/symbol.treetop +47 -0
- data/lib/hemingway/symbol/symbol_nodes.rb +7 -0
- data/lib/hemingway/tag/tag.rb +538 -0
- data/lib/hemingway/tag/tag.treetop +63 -0
- data/lib/hemingway/tag/tag_nodes.rb +49 -0
- data/lib/hemingway/text/text.rb +121 -0
- data/lib/hemingway/text/text.treetop +35 -0
- data/lib/hemingway/text/text_nodes.rb +7 -0
- data/lib/hemingway/version.rb +3 -0
- data/lib/hemingway.rb +7 -0
- data/script/build +22 -0
- data/script/test +2 -0
- data/spec/build_spec.rb +65 -0
- data/spec/nodes/block/list_spec.rb +91 -0
- data/spec/nodes/block/quote_spec.rb +31 -0
- data/spec/nodes/block/verbatim_spec.rb +27 -0
- data/spec/nodes/block_spec.rb +21 -0
- data/spec/nodes/footnote_spec.rb +42 -0
- data/spec/nodes/math_spec.rb +31 -0
- data/spec/nodes/special_spec.rb +27 -0
- data/spec/nodes/tag_spec.rb +98 -0
- data/spec/parser_spec.rb +48 -0
- data/spec/spec_helper.rb +5 -0
- metadata +110 -18
@@ -0,0 +1,47 @@
|
|
1
|
+
require "hemingway/symbol/symbol_nodes"
|
2
|
+
|
3
|
+
module Hemingway
|
4
|
+
grammar Symbol
|
5
|
+
|
6
|
+
rule math_symbol
|
7
|
+
(
|
8
|
+
"\\Gamma" /
|
9
|
+
"\\Delta" /
|
10
|
+
"\\Theta" /
|
11
|
+
"\\Lambda" /
|
12
|
+
"\\Xi" /
|
13
|
+
"\\Pi" /
|
14
|
+
"\\Sigma" /
|
15
|
+
"\\Upsilon" /
|
16
|
+
"\\Phi" /
|
17
|
+
"\\Psi" /
|
18
|
+
"\\Omega" /
|
19
|
+
"\\alpha" /
|
20
|
+
"\\beta" /
|
21
|
+
"\\gamma" /
|
22
|
+
"\\delta" /
|
23
|
+
"\\epsilon" /
|
24
|
+
"\\zeta" /
|
25
|
+
"\\eta" /
|
26
|
+
"\\theta" /
|
27
|
+
"\\iota" /
|
28
|
+
"\\kappa" /
|
29
|
+
"\\lambda" /
|
30
|
+
"\\mu" /
|
31
|
+
"\\nu" /
|
32
|
+
"\\xi" /
|
33
|
+
"\\pi" /
|
34
|
+
"\\rho" /
|
35
|
+
"\\varsigma" /
|
36
|
+
"\\sigma" /
|
37
|
+
"\\tau" /
|
38
|
+
"\\upsilon" /
|
39
|
+
"\\phi" /
|
40
|
+
"\\chi" /
|
41
|
+
"\\psi" /
|
42
|
+
"\\omega"
|
43
|
+
) <SymbolNode>
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,538 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
require "hemingway/tag/tag_nodes"
|
5
|
+
|
6
|
+
module Hemingway
|
7
|
+
module Tag
|
8
|
+
include Treetop::Runtime
|
9
|
+
|
10
|
+
def root
|
11
|
+
@root ||= :tag
|
12
|
+
end
|
13
|
+
|
14
|
+
module Tag0
|
15
|
+
def tag_start
|
16
|
+
elements[0]
|
17
|
+
end
|
18
|
+
|
19
|
+
def tag_type
|
20
|
+
elements[1]
|
21
|
+
end
|
22
|
+
|
23
|
+
def sequence
|
24
|
+
elements[3]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
module Tag1
|
30
|
+
def tag_start
|
31
|
+
elements[0]
|
32
|
+
end
|
33
|
+
|
34
|
+
def vertical_space
|
35
|
+
elements[1]
|
36
|
+
end
|
37
|
+
|
38
|
+
def vertical_height
|
39
|
+
elements[3]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
module Tag2
|
45
|
+
def content
|
46
|
+
elements[1]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module Tag3
|
51
|
+
def tag_start
|
52
|
+
elements[0]
|
53
|
+
end
|
54
|
+
|
55
|
+
def hfill
|
56
|
+
elements[1]
|
57
|
+
end
|
58
|
+
|
59
|
+
def spaces
|
60
|
+
elements[2]
|
61
|
+
end
|
62
|
+
|
63
|
+
def sequence
|
64
|
+
elements[3]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
module Tag4
|
69
|
+
def tag_start
|
70
|
+
elements[0]
|
71
|
+
end
|
72
|
+
|
73
|
+
def neatline
|
74
|
+
elements[1]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def _nt_tag
|
79
|
+
start_index = index
|
80
|
+
if node_cache[:tag].has_key?(index)
|
81
|
+
cached = node_cache[:tag][index]
|
82
|
+
if cached
|
83
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
84
|
+
@index = cached.interval.end
|
85
|
+
end
|
86
|
+
return cached
|
87
|
+
end
|
88
|
+
|
89
|
+
i0 = index
|
90
|
+
i1, s1 = index, []
|
91
|
+
r2 = _nt_tag_start
|
92
|
+
s1 << r2
|
93
|
+
if r2
|
94
|
+
r3 = _nt_tag_type
|
95
|
+
s1 << r3
|
96
|
+
if r3
|
97
|
+
if has_terminal?("{", false, index)
|
98
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
99
|
+
@index += 1
|
100
|
+
else
|
101
|
+
terminal_parse_failure("{")
|
102
|
+
r4 = nil
|
103
|
+
end
|
104
|
+
s1 << r4
|
105
|
+
if r4
|
106
|
+
s5, i5 = [], index
|
107
|
+
loop do
|
108
|
+
r6 = _nt_content
|
109
|
+
if r6
|
110
|
+
s5 << r6
|
111
|
+
else
|
112
|
+
break
|
113
|
+
end
|
114
|
+
end
|
115
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
116
|
+
s1 << r5
|
117
|
+
if r5
|
118
|
+
if has_terminal?("}", false, index)
|
119
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
120
|
+
@index += 1
|
121
|
+
else
|
122
|
+
terminal_parse_failure("}")
|
123
|
+
r7 = nil
|
124
|
+
end
|
125
|
+
s1 << r7
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
if s1.last
|
131
|
+
r1 = instantiate_node(TagNode,input, i1...index, s1)
|
132
|
+
r1.extend(Tag0)
|
133
|
+
else
|
134
|
+
@index = i1
|
135
|
+
r1 = nil
|
136
|
+
end
|
137
|
+
if r1
|
138
|
+
r0 = r1
|
139
|
+
else
|
140
|
+
i8, s8 = index, []
|
141
|
+
r9 = _nt_tag_start
|
142
|
+
s8 << r9
|
143
|
+
if r9
|
144
|
+
r10 = _nt_vertical_space
|
145
|
+
s8 << r10
|
146
|
+
if r10
|
147
|
+
if has_terminal?("{", false, index)
|
148
|
+
r11 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
149
|
+
@index += 1
|
150
|
+
else
|
151
|
+
terminal_parse_failure("{")
|
152
|
+
r11 = nil
|
153
|
+
end
|
154
|
+
s8 << r11
|
155
|
+
if r11
|
156
|
+
r12 = _nt_vertical_height
|
157
|
+
s8 << r12
|
158
|
+
if r12
|
159
|
+
if has_terminal?("}", false, index)
|
160
|
+
r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
161
|
+
@index += 1
|
162
|
+
else
|
163
|
+
terminal_parse_failure("}")
|
164
|
+
r13 = nil
|
165
|
+
end
|
166
|
+
s8 << r13
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
if s8.last
|
172
|
+
r8 = instantiate_node(VerticalSpaceTagNode,input, i8...index, s8)
|
173
|
+
r8.extend(Tag1)
|
174
|
+
else
|
175
|
+
@index = i8
|
176
|
+
r8 = nil
|
177
|
+
end
|
178
|
+
if r8
|
179
|
+
r0 = r8
|
180
|
+
else
|
181
|
+
i14, s14 = index, []
|
182
|
+
r15 = _nt_tag_start
|
183
|
+
s14 << r15
|
184
|
+
if r15
|
185
|
+
r16 = _nt_hfill
|
186
|
+
s14 << r16
|
187
|
+
if r16
|
188
|
+
r17 = _nt_spaces
|
189
|
+
s14 << r17
|
190
|
+
if r17
|
191
|
+
s18, i18 = [], index
|
192
|
+
loop do
|
193
|
+
i19, s19 = index, []
|
194
|
+
i20 = index
|
195
|
+
r21 = _nt_newline
|
196
|
+
if r21
|
197
|
+
r20 = nil
|
198
|
+
else
|
199
|
+
@index = i20
|
200
|
+
r20 = instantiate_node(SyntaxNode,input, index...index)
|
201
|
+
end
|
202
|
+
s19 << r20
|
203
|
+
if r20
|
204
|
+
r22 = _nt_content
|
205
|
+
s19 << r22
|
206
|
+
end
|
207
|
+
if s19.last
|
208
|
+
r19 = instantiate_node(SyntaxNode,input, i19...index, s19)
|
209
|
+
r19.extend(Tag2)
|
210
|
+
else
|
211
|
+
@index = i19
|
212
|
+
r19 = nil
|
213
|
+
end
|
214
|
+
if r19
|
215
|
+
s18 << r19
|
216
|
+
else
|
217
|
+
break
|
218
|
+
end
|
219
|
+
end
|
220
|
+
r18 = instantiate_node(SyntaxNode,input, i18...index, s18)
|
221
|
+
s14 << r18
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
if s14.last
|
226
|
+
r14 = instantiate_node(HFillNode,input, i14...index, s14)
|
227
|
+
r14.extend(Tag3)
|
228
|
+
else
|
229
|
+
@index = i14
|
230
|
+
r14 = nil
|
231
|
+
end
|
232
|
+
if r14
|
233
|
+
r0 = r14
|
234
|
+
else
|
235
|
+
i23, s23 = index, []
|
236
|
+
r24 = _nt_tag_start
|
237
|
+
s23 << r24
|
238
|
+
if r24
|
239
|
+
r25 = _nt_neatline
|
240
|
+
s23 << r25
|
241
|
+
end
|
242
|
+
if s23.last
|
243
|
+
r23 = instantiate_node(NeatLineNode,input, i23...index, s23)
|
244
|
+
r23.extend(Tag4)
|
245
|
+
else
|
246
|
+
@index = i23
|
247
|
+
r23 = nil
|
248
|
+
end
|
249
|
+
if r23
|
250
|
+
r0 = r23
|
251
|
+
else
|
252
|
+
@index = i0
|
253
|
+
r0 = nil
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
node_cache[:tag][start_index] = r0
|
260
|
+
|
261
|
+
r0
|
262
|
+
end
|
263
|
+
|
264
|
+
def _nt_tag_type
|
265
|
+
start_index = index
|
266
|
+
if node_cache[:tag_type].has_key?(index)
|
267
|
+
cached = node_cache[:tag_type][index]
|
268
|
+
if cached
|
269
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
270
|
+
@index = cached.interval.end
|
271
|
+
end
|
272
|
+
return cached
|
273
|
+
end
|
274
|
+
|
275
|
+
i0 = index
|
276
|
+
if has_terminal?("emph", false, index)
|
277
|
+
r1 = instantiate_node(EmphTagNode,input, index...(index + 4))
|
278
|
+
@index += 4
|
279
|
+
else
|
280
|
+
terminal_parse_failure("emph")
|
281
|
+
r1 = nil
|
282
|
+
end
|
283
|
+
if r1
|
284
|
+
r0 = r1
|
285
|
+
else
|
286
|
+
if has_terminal?("texttt", false, index)
|
287
|
+
r2 = instantiate_node(TextttTagNode,input, index...(index + 6))
|
288
|
+
@index += 6
|
289
|
+
else
|
290
|
+
terminal_parse_failure("texttt")
|
291
|
+
r2 = nil
|
292
|
+
end
|
293
|
+
if r2
|
294
|
+
r0 = r2
|
295
|
+
else
|
296
|
+
if has_terminal?("textbf", false, index)
|
297
|
+
r3 = instantiate_node(TextbfTagNode,input, index...(index + 6))
|
298
|
+
@index += 6
|
299
|
+
else
|
300
|
+
terminal_parse_failure("textbf")
|
301
|
+
r3 = nil
|
302
|
+
end
|
303
|
+
if r3
|
304
|
+
r0 = r3
|
305
|
+
else
|
306
|
+
if has_terminal?("textsc", false, index)
|
307
|
+
r4 = instantiate_node(TextscTagNode,input, index...(index + 6))
|
308
|
+
@index += 6
|
309
|
+
else
|
310
|
+
terminal_parse_failure("textsc")
|
311
|
+
r4 = nil
|
312
|
+
end
|
313
|
+
if r4
|
314
|
+
r0 = r4
|
315
|
+
else
|
316
|
+
@index = i0
|
317
|
+
r0 = nil
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
node_cache[:tag_type][start_index] = r0
|
324
|
+
|
325
|
+
r0
|
326
|
+
end
|
327
|
+
|
328
|
+
def _nt_vertical_space
|
329
|
+
start_index = index
|
330
|
+
if node_cache[:vertical_space].has_key?(index)
|
331
|
+
cached = node_cache[:vertical_space][index]
|
332
|
+
if cached
|
333
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
334
|
+
@index = cached.interval.end
|
335
|
+
end
|
336
|
+
return cached
|
337
|
+
end
|
338
|
+
|
339
|
+
if has_terminal?("vspace", false, index)
|
340
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 6))
|
341
|
+
@index += 6
|
342
|
+
else
|
343
|
+
terminal_parse_failure("vspace")
|
344
|
+
r0 = nil
|
345
|
+
end
|
346
|
+
|
347
|
+
node_cache[:vertical_space][start_index] = r0
|
348
|
+
|
349
|
+
r0
|
350
|
+
end
|
351
|
+
|
352
|
+
module VerticalHeight0
|
353
|
+
def height
|
354
|
+
elements[0]
|
355
|
+
end
|
356
|
+
|
357
|
+
def millimeter
|
358
|
+
elements[1]
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
def _nt_vertical_height
|
363
|
+
start_index = index
|
364
|
+
if node_cache[:vertical_height].has_key?(index)
|
365
|
+
cached = node_cache[:vertical_height][index]
|
366
|
+
if cached
|
367
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
368
|
+
@index = cached.interval.end
|
369
|
+
end
|
370
|
+
return cached
|
371
|
+
end
|
372
|
+
|
373
|
+
i0, s0 = index, []
|
374
|
+
s1, i1 = [], index
|
375
|
+
loop do
|
376
|
+
if has_terminal?('\G[0-9]', true, index)
|
377
|
+
r2 = true
|
378
|
+
@index += 1
|
379
|
+
else
|
380
|
+
r2 = nil
|
381
|
+
end
|
382
|
+
if r2
|
383
|
+
s1 << r2
|
384
|
+
else
|
385
|
+
break
|
386
|
+
end
|
387
|
+
end
|
388
|
+
if s1.empty?
|
389
|
+
@index = i1
|
390
|
+
r1 = nil
|
391
|
+
else
|
392
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
393
|
+
end
|
394
|
+
s0 << r1
|
395
|
+
if r1
|
396
|
+
r3 = _nt_millimeter
|
397
|
+
s0 << r3
|
398
|
+
end
|
399
|
+
if s0.last
|
400
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
401
|
+
r0.extend(VerticalHeight0)
|
402
|
+
else
|
403
|
+
@index = i0
|
404
|
+
r0 = nil
|
405
|
+
end
|
406
|
+
|
407
|
+
node_cache[:vertical_height][start_index] = r0
|
408
|
+
|
409
|
+
r0
|
410
|
+
end
|
411
|
+
|
412
|
+
def _nt_millimeter
|
413
|
+
start_index = index
|
414
|
+
if node_cache[:millimeter].has_key?(index)
|
415
|
+
cached = node_cache[:millimeter][index]
|
416
|
+
if cached
|
417
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
418
|
+
@index = cached.interval.end
|
419
|
+
end
|
420
|
+
return cached
|
421
|
+
end
|
422
|
+
|
423
|
+
if has_terminal?("mm", false, index)
|
424
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
425
|
+
@index += 2
|
426
|
+
else
|
427
|
+
terminal_parse_failure("mm")
|
428
|
+
r0 = nil
|
429
|
+
end
|
430
|
+
|
431
|
+
node_cache[:millimeter][start_index] = r0
|
432
|
+
|
433
|
+
r0
|
434
|
+
end
|
435
|
+
|
436
|
+
def _nt_hfill
|
437
|
+
start_index = index
|
438
|
+
if node_cache[:hfill].has_key?(index)
|
439
|
+
cached = node_cache[:hfill][index]
|
440
|
+
if cached
|
441
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
442
|
+
@index = cached.interval.end
|
443
|
+
end
|
444
|
+
return cached
|
445
|
+
end
|
446
|
+
|
447
|
+
if has_terminal?("hfill", false, index)
|
448
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
449
|
+
@index += 5
|
450
|
+
else
|
451
|
+
terminal_parse_failure("hfill")
|
452
|
+
r0 = nil
|
453
|
+
end
|
454
|
+
|
455
|
+
node_cache[:hfill][start_index] = r0
|
456
|
+
|
457
|
+
r0
|
458
|
+
end
|
459
|
+
|
460
|
+
def _nt_neatline
|
461
|
+
start_index = index
|
462
|
+
if node_cache[:neatline].has_key?(index)
|
463
|
+
cached = node_cache[:neatline][index]
|
464
|
+
if cached
|
465
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
466
|
+
@index = cached.interval.end
|
467
|
+
end
|
468
|
+
return cached
|
469
|
+
end
|
470
|
+
|
471
|
+
if has_terminal?("neatline", false, index)
|
472
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 8))
|
473
|
+
@index += 8
|
474
|
+
else
|
475
|
+
terminal_parse_failure("neatline")
|
476
|
+
r0 = nil
|
477
|
+
end
|
478
|
+
|
479
|
+
node_cache[:neatline][start_index] = r0
|
480
|
+
|
481
|
+
r0
|
482
|
+
end
|
483
|
+
|
484
|
+
def _nt_tag_start
|
485
|
+
start_index = index
|
486
|
+
if node_cache[:tag_start].has_key?(index)
|
487
|
+
cached = node_cache[:tag_start][index]
|
488
|
+
if cached
|
489
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
490
|
+
@index = cached.interval.end
|
491
|
+
end
|
492
|
+
return cached
|
493
|
+
end
|
494
|
+
|
495
|
+
if has_terminal?("\\", false, index)
|
496
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
497
|
+
@index += 1
|
498
|
+
else
|
499
|
+
terminal_parse_failure("\\")
|
500
|
+
r0 = nil
|
501
|
+
end
|
502
|
+
|
503
|
+
node_cache[:tag_start][start_index] = r0
|
504
|
+
|
505
|
+
r0
|
506
|
+
end
|
507
|
+
|
508
|
+
def _nt_tag_end
|
509
|
+
start_index = index
|
510
|
+
if node_cache[:tag_end].has_key?(index)
|
511
|
+
cached = node_cache[:tag_end][index]
|
512
|
+
if cached
|
513
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
514
|
+
@index = cached.interval.end
|
515
|
+
end
|
516
|
+
return cached
|
517
|
+
end
|
518
|
+
|
519
|
+
if has_terminal?("}", false, index)
|
520
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
521
|
+
@index += 1
|
522
|
+
else
|
523
|
+
terminal_parse_failure("}")
|
524
|
+
r0 = nil
|
525
|
+
end
|
526
|
+
|
527
|
+
node_cache[:tag_end][start_index] = r0
|
528
|
+
|
529
|
+
r0
|
530
|
+
end
|
531
|
+
|
532
|
+
end
|
533
|
+
|
534
|
+
class TagParser < Treetop::Runtime::CompiledParser
|
535
|
+
include Tag
|
536
|
+
end
|
537
|
+
|
538
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "hemingway/tag/tag_nodes"
|
2
|
+
|
3
|
+
module Hemingway
|
4
|
+
grammar Tag
|
5
|
+
|
6
|
+
rule tag
|
7
|
+
tag_start tag_type "{" sequence:( content )* "}" <TagNode>
|
8
|
+
/
|
9
|
+
tag_start vertical_space "{" vertical_height "}" <VerticalSpaceTagNode>
|
10
|
+
/
|
11
|
+
tag_start hfill spaces sequence:( !newline content )* <HFillNode>
|
12
|
+
/
|
13
|
+
tag_start neatline <NeatLineNode>
|
14
|
+
end
|
15
|
+
|
16
|
+
# All tag types will be responsible with implementing their own
|
17
|
+
# html methods. This is because emph should map to a <em> tag,
|
18
|
+
# textbf should map to a <strong> tag, and so forth.
|
19
|
+
rule tag_type
|
20
|
+
"emph" <EmphTagNode>
|
21
|
+
/
|
22
|
+
"texttt" <TextttTagNode>
|
23
|
+
/
|
24
|
+
"textbf" <TextbfTagNode>
|
25
|
+
/
|
26
|
+
"textsc" <TextscTagNode>
|
27
|
+
end
|
28
|
+
|
29
|
+
# I'm pretty annoyed at having to split this up into a different tag,
|
30
|
+
# but it is kinda fundamentally different than an inline-style-type tag.
|
31
|
+
# This tag is supposed to guarantee some vertical spacing, so fine.
|
32
|
+
# The contents of the tag are now also a measurement of the size of the
|
33
|
+
# vertical space so, yeah, different.
|
34
|
+
rule vertical_space
|
35
|
+
"vspace"
|
36
|
+
end
|
37
|
+
|
38
|
+
rule vertical_height
|
39
|
+
height:[0-9]+ millimeter
|
40
|
+
end
|
41
|
+
|
42
|
+
rule millimeter
|
43
|
+
"mm"
|
44
|
+
end
|
45
|
+
|
46
|
+
rule hfill
|
47
|
+
"hfill"
|
48
|
+
end
|
49
|
+
|
50
|
+
rule neatline
|
51
|
+
"neatline"
|
52
|
+
end
|
53
|
+
|
54
|
+
rule tag_start
|
55
|
+
"\\"
|
56
|
+
end
|
57
|
+
|
58
|
+
rule tag_end
|
59
|
+
"}"
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Hemingway
|
2
|
+
module TagNode
|
3
|
+
def html
|
4
|
+
tag_type.html(sequence.elements.map { |c| c.html }.join)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module VerticalSpaceTagNode
|
9
|
+
def html
|
10
|
+
Build.tag("div", nil, :class => "vspace#{vertical_height.height.text_value}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module HFillNode
|
15
|
+
def html
|
16
|
+
Build.tag("span", sequence.elements.map { |c| c.content.html }.join, :class => "pull-right")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module NeatLineNode
|
21
|
+
def html
|
22
|
+
Build.tag("hr", nil, :class => "neatline", :close_tag => false)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module EmphTagNode
|
27
|
+
def html(content)
|
28
|
+
Build.tag("em", content)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module TextttTagNode
|
33
|
+
def html(content)
|
34
|
+
Build.tag("code", content)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module TextbfTagNode
|
39
|
+
def html(content)
|
40
|
+
Build.tag("strong", content)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module TextscTagNode
|
45
|
+
def html(content)
|
46
|
+
Build.tag("span", content, :class => "textsc")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|