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,378 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
require "hemingway/block/block_nodes"
|
5
|
+
require "hemingway/block/list/list"
|
6
|
+
require "hemingway/block/verbatim/verbatim"
|
7
|
+
require "hemingway/block/quote/quote"
|
8
|
+
|
9
|
+
module Hemingway
|
10
|
+
module Block
|
11
|
+
include Treetop::Runtime
|
12
|
+
|
13
|
+
def root
|
14
|
+
@root ||= :block
|
15
|
+
end
|
16
|
+
|
17
|
+
include List
|
18
|
+
|
19
|
+
include Verbatim
|
20
|
+
|
21
|
+
include Quote
|
22
|
+
|
23
|
+
module Block0
|
24
|
+
def block_start
|
25
|
+
elements[0]
|
26
|
+
end
|
27
|
+
|
28
|
+
def type
|
29
|
+
elements[1]
|
30
|
+
end
|
31
|
+
|
32
|
+
def whitespace1
|
33
|
+
elements[3]
|
34
|
+
end
|
35
|
+
|
36
|
+
def content
|
37
|
+
elements[4]
|
38
|
+
end
|
39
|
+
|
40
|
+
def whitespace2
|
41
|
+
elements[5]
|
42
|
+
end
|
43
|
+
|
44
|
+
def block_end
|
45
|
+
elements[6]
|
46
|
+
end
|
47
|
+
|
48
|
+
def list_type
|
49
|
+
elements[7]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
module Block1
|
55
|
+
def block_start
|
56
|
+
elements[0]
|
57
|
+
end
|
58
|
+
|
59
|
+
def type
|
60
|
+
elements[1]
|
61
|
+
end
|
62
|
+
|
63
|
+
def whitespace1
|
64
|
+
elements[3]
|
65
|
+
end
|
66
|
+
|
67
|
+
def content
|
68
|
+
elements[4]
|
69
|
+
end
|
70
|
+
|
71
|
+
def whitespace2
|
72
|
+
elements[5]
|
73
|
+
end
|
74
|
+
|
75
|
+
def block_end
|
76
|
+
elements[6]
|
77
|
+
end
|
78
|
+
|
79
|
+
def verbatim_type
|
80
|
+
elements[7]
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
module Block2
|
86
|
+
def block_start
|
87
|
+
elements[0]
|
88
|
+
end
|
89
|
+
|
90
|
+
def type
|
91
|
+
elements[1]
|
92
|
+
end
|
93
|
+
|
94
|
+
def whitespace1
|
95
|
+
elements[3]
|
96
|
+
end
|
97
|
+
|
98
|
+
def content
|
99
|
+
elements[4]
|
100
|
+
end
|
101
|
+
|
102
|
+
def whitespace2
|
103
|
+
elements[5]
|
104
|
+
end
|
105
|
+
|
106
|
+
def block_end
|
107
|
+
elements[6]
|
108
|
+
end
|
109
|
+
|
110
|
+
def quote_type
|
111
|
+
elements[7]
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
def _nt_block
|
117
|
+
start_index = index
|
118
|
+
if node_cache[:block].has_key?(index)
|
119
|
+
cached = node_cache[:block][index]
|
120
|
+
if cached
|
121
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
122
|
+
@index = cached.interval.end
|
123
|
+
end
|
124
|
+
return cached
|
125
|
+
end
|
126
|
+
|
127
|
+
i0 = index
|
128
|
+
i1, s1 = index, []
|
129
|
+
r2 = _nt_block_start
|
130
|
+
s1 << r2
|
131
|
+
if r2
|
132
|
+
r3 = _nt_list_type
|
133
|
+
s1 << r3
|
134
|
+
if r3
|
135
|
+
if has_terminal?("}", false, index)
|
136
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
137
|
+
@index += 1
|
138
|
+
else
|
139
|
+
terminal_parse_failure("}")
|
140
|
+
r4 = nil
|
141
|
+
end
|
142
|
+
s1 << r4
|
143
|
+
if r4
|
144
|
+
r5 = _nt_whitespace
|
145
|
+
s1 << r5
|
146
|
+
if r5
|
147
|
+
r6 = _nt_list
|
148
|
+
s1 << r6
|
149
|
+
if r6
|
150
|
+
r7 = _nt_whitespace
|
151
|
+
s1 << r7
|
152
|
+
if r7
|
153
|
+
r8 = _nt_block_end
|
154
|
+
s1 << r8
|
155
|
+
if r8
|
156
|
+
r9 = _nt_list_type
|
157
|
+
s1 << r9
|
158
|
+
if r9
|
159
|
+
if has_terminal?("}", false, index)
|
160
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
161
|
+
@index += 1
|
162
|
+
else
|
163
|
+
terminal_parse_failure("}")
|
164
|
+
r10 = nil
|
165
|
+
end
|
166
|
+
s1 << r10
|
167
|
+
if r10
|
168
|
+
i11 = index
|
169
|
+
r12 = lambda { |seq| seq[1].text_value == seq[7].text_value }.call(s1)
|
170
|
+
if r12
|
171
|
+
@index = i11
|
172
|
+
r11 = instantiate_node(SyntaxNode,input, index...index)
|
173
|
+
else
|
174
|
+
r11 = nil
|
175
|
+
end
|
176
|
+
s1 << r11
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
if s1.last
|
187
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
188
|
+
r1.extend(Block0)
|
189
|
+
else
|
190
|
+
@index = i1
|
191
|
+
r1 = nil
|
192
|
+
end
|
193
|
+
if r1
|
194
|
+
r0 = r1
|
195
|
+
r0.extend(BlockNode)
|
196
|
+
else
|
197
|
+
i13, s13 = index, []
|
198
|
+
r14 = _nt_block_start
|
199
|
+
s13 << r14
|
200
|
+
if r14
|
201
|
+
r15 = _nt_verbatim_type
|
202
|
+
s13 << r15
|
203
|
+
if r15
|
204
|
+
if has_terminal?("}", false, index)
|
205
|
+
r16 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
206
|
+
@index += 1
|
207
|
+
else
|
208
|
+
terminal_parse_failure("}")
|
209
|
+
r16 = nil
|
210
|
+
end
|
211
|
+
s13 << r16
|
212
|
+
if r16
|
213
|
+
r17 = _nt_whitespace
|
214
|
+
s13 << r17
|
215
|
+
if r17
|
216
|
+
r18 = _nt_verbatim
|
217
|
+
s13 << r18
|
218
|
+
if r18
|
219
|
+
r19 = _nt_whitespace
|
220
|
+
s13 << r19
|
221
|
+
if r19
|
222
|
+
r20 = _nt_block_end
|
223
|
+
s13 << r20
|
224
|
+
if r20
|
225
|
+
r21 = _nt_verbatim_type
|
226
|
+
s13 << r21
|
227
|
+
if r21
|
228
|
+
if has_terminal?("}", false, index)
|
229
|
+
r22 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
230
|
+
@index += 1
|
231
|
+
else
|
232
|
+
terminal_parse_failure("}")
|
233
|
+
r22 = nil
|
234
|
+
end
|
235
|
+
s13 << r22
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
if s13.last
|
245
|
+
r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
|
246
|
+
r13.extend(Block1)
|
247
|
+
else
|
248
|
+
@index = i13
|
249
|
+
r13 = nil
|
250
|
+
end
|
251
|
+
if r13
|
252
|
+
r0 = r13
|
253
|
+
r0.extend(BlockNode)
|
254
|
+
else
|
255
|
+
i23, s23 = index, []
|
256
|
+
r24 = _nt_block_start
|
257
|
+
s23 << r24
|
258
|
+
if r24
|
259
|
+
r25 = _nt_quote_type
|
260
|
+
s23 << r25
|
261
|
+
if r25
|
262
|
+
if has_terminal?("}", false, index)
|
263
|
+
r26 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
264
|
+
@index += 1
|
265
|
+
else
|
266
|
+
terminal_parse_failure("}")
|
267
|
+
r26 = nil
|
268
|
+
end
|
269
|
+
s23 << r26
|
270
|
+
if r26
|
271
|
+
r27 = _nt_whitespace
|
272
|
+
s23 << r27
|
273
|
+
if r27
|
274
|
+
r28 = _nt_quote_entry
|
275
|
+
s23 << r28
|
276
|
+
if r28
|
277
|
+
r29 = _nt_whitespace
|
278
|
+
s23 << r29
|
279
|
+
if r29
|
280
|
+
r30 = _nt_block_end
|
281
|
+
s23 << r30
|
282
|
+
if r30
|
283
|
+
r31 = _nt_quote_type
|
284
|
+
s23 << r31
|
285
|
+
if r31
|
286
|
+
if has_terminal?("}", false, index)
|
287
|
+
r32 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
288
|
+
@index += 1
|
289
|
+
else
|
290
|
+
terminal_parse_failure("}")
|
291
|
+
r32 = nil
|
292
|
+
end
|
293
|
+
s23 << r32
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
if s23.last
|
303
|
+
r23 = instantiate_node(SyntaxNode,input, i23...index, s23)
|
304
|
+
r23.extend(Block2)
|
305
|
+
else
|
306
|
+
@index = i23
|
307
|
+
r23 = nil
|
308
|
+
end
|
309
|
+
if r23
|
310
|
+
r0 = r23
|
311
|
+
r0.extend(BlockNode)
|
312
|
+
else
|
313
|
+
@index = i0
|
314
|
+
r0 = nil
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
node_cache[:block][start_index] = r0
|
320
|
+
|
321
|
+
r0
|
322
|
+
end
|
323
|
+
|
324
|
+
def _nt_block_start
|
325
|
+
start_index = index
|
326
|
+
if node_cache[:block_start].has_key?(index)
|
327
|
+
cached = node_cache[:block_start][index]
|
328
|
+
if cached
|
329
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
330
|
+
@index = cached.interval.end
|
331
|
+
end
|
332
|
+
return cached
|
333
|
+
end
|
334
|
+
|
335
|
+
if has_terminal?("\\begin{", false, index)
|
336
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 7))
|
337
|
+
@index += 7
|
338
|
+
else
|
339
|
+
terminal_parse_failure("\\begin{")
|
340
|
+
r0 = nil
|
341
|
+
end
|
342
|
+
|
343
|
+
node_cache[:block_start][start_index] = r0
|
344
|
+
|
345
|
+
r0
|
346
|
+
end
|
347
|
+
|
348
|
+
def _nt_block_end
|
349
|
+
start_index = index
|
350
|
+
if node_cache[:block_end].has_key?(index)
|
351
|
+
cached = node_cache[:block_end][index]
|
352
|
+
if cached
|
353
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
354
|
+
@index = cached.interval.end
|
355
|
+
end
|
356
|
+
return cached
|
357
|
+
end
|
358
|
+
|
359
|
+
if has_terminal?("\\end{", false, index)
|
360
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
361
|
+
@index += 5
|
362
|
+
else
|
363
|
+
terminal_parse_failure("\\end{")
|
364
|
+
r0 = nil
|
365
|
+
end
|
366
|
+
|
367
|
+
node_cache[:block_end][start_index] = r0
|
368
|
+
|
369
|
+
r0
|
370
|
+
end
|
371
|
+
|
372
|
+
end
|
373
|
+
|
374
|
+
class BlockParser < Treetop::Runtime::CompiledParser
|
375
|
+
include Block
|
376
|
+
end
|
377
|
+
|
378
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "hemingway/block/block_nodes"
|
2
|
+
require "hemingway/block/list/list"
|
3
|
+
require "hemingway/block/verbatim/verbatim"
|
4
|
+
require "hemingway/block/quote/quote"
|
5
|
+
|
6
|
+
module Hemingway
|
7
|
+
grammar Block
|
8
|
+
|
9
|
+
include List
|
10
|
+
include Verbatim
|
11
|
+
include Quote
|
12
|
+
|
13
|
+
# Example:
|
14
|
+
# \begin{itemize}
|
15
|
+
# \item[Chewbacca] Wookie
|
16
|
+
# \item[Han] Smuggler
|
17
|
+
# \item[Anakin] Savant
|
18
|
+
# \end{itemize}
|
19
|
+
rule block
|
20
|
+
(
|
21
|
+
block_start type:list_type "}" whitespace content:list whitespace block_end list_type "}" &{ |seq| seq[1].text_value == seq[7].text_value } /
|
22
|
+
block_start type:verbatim_type "}" whitespace content:verbatim whitespace block_end verbatim_type "}" /
|
23
|
+
block_start type:quote_type "}" whitespace content:quote_entry whitespace block_end quote_type "}"
|
24
|
+
) <BlockNode>
|
25
|
+
end
|
26
|
+
|
27
|
+
rule block_start
|
28
|
+
"\\begin{"
|
29
|
+
end
|
30
|
+
|
31
|
+
rule block_end
|
32
|
+
"\\end{"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|