Module: Hemingway::Block::List

Includes:
Treetop::Runtime
Included in:
Hemingway::Block, ListParser
Defined in:
lib/hemingway/block/list/list.rb

Defined Under Namespace

Modules: Item0, Label0, LabelText0

Instance Method Summary collapse

Instance Method Details

#_nt_itemObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/hemingway/block/list/list.rb', line 110

def _nt_item
  start_index = index
  if node_cache[:item].has_key?(index)
    cached = node_cache[:item][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  if has_terminal?("\\item", false, index)
    r1 = instantiate_node(SyntaxNode,input, index...(index + 5))
    @index += 5
  else
    terminal_parse_failure("\\item")
    r1 = nil
  end
  s0 << r1
  if r1
    r3 = _nt_whitespace
    if r3
      r2 = r3
    else
      r2 = instantiate_node(SyntaxNode,input, index...index)
    end
    s0 << r2
    if r2
      r5 = _nt_label
      if r5
        r4 = r5
      else
        r4 = instantiate_node(SyntaxNode,input, index...index)
      end
      s0 << r4
      if r4
        s6, i6 = [], index
        loop do
          i7 = index
          r8 = _nt_content
          if r8
            r7 = r8
          else
            r9 = _nt_whitespace
            if r9
              r7 = r9
            else
              @index = i7
              r7 = nil
            end
          end
          if r7
            s6 << r7
          else
            break
          end
        end
        r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
        s0 << r6
      end
    end
  end
  if s0.last
    r0 = instantiate_node(ItemNode,input, i0...index, s0)
    r0.extend(Item0)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:item][start_index] = r0

  r0
end

#_nt_labelObject



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/hemingway/block/list/list.rb', line 200

def _nt_label
  start_index = index
  if node_cache[:label].has_key?(index)
    cached = node_cache[:label][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0, s0 = index, []
  r1 = _nt_label_start
  s0 << r1
  if r1
    s2, i2 = [], index
    loop do
      r3 = _nt_label_content
      if r3
        s2 << r3
      else
        break
      end
    end
    r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
    s0 << r2
    if r2
      r4 = _nt_label_end
      s0 << r4
    end
  end
  if s0.last
    r0 = instantiate_node(LabelNode,input, i0...index, s0)
    r0.extend(Label0)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:label][start_index] = r0

  r0
end

#_nt_label_contentObject



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/hemingway/block/list/list.rb', line 244

def _nt_label_content
  start_index = index
  if node_cache[:label_content].has_key?(index)
    cached = node_cache[:label_content][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0 = index
  r1 = _nt_special
  if r1
    r0 = r1
  else
    r2 = _nt_tag
    if r2
      r0 = r2
    else
      r3 = _nt_block
      if r3
        r0 = r3
      else
        r4 = _nt_math
        if r4
          r0 = r4
        else
          r5 = _nt_label_text
          if r5
            r0 = r5
          else
            @index = i0
            r0 = nil
          end
        end
      end
    end
  end

  node_cache[:label_content][start_index] = r0

  r0
end

#_nt_label_endObject



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/hemingway/block/list/list.rb', line 386

def _nt_label_end
  start_index = index
  if node_cache[:label_end].has_key?(index)
    cached = node_cache[:label_end][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?("]", false, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    @index += 1
  else
    terminal_parse_failure("]")
    r0 = nil
  end

  node_cache[:label_end][start_index] = r0

  r0
end

#_nt_label_startObject



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/hemingway/block/list/list.rb', line 362

def _nt_label_start
  start_index = index
  if node_cache[:label_start].has_key?(index)
    cached = node_cache[:label_start][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  if has_terminal?("[", false, index)
    r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
    @index += 1
  else
    terminal_parse_failure("[")
    r0 = nil
  end

  node_cache[:label_start][start_index] = r0

  r0
end

#_nt_label_textObject



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/hemingway/block/list/list.rb', line 292

def _nt_label_text
  start_index = index
  if node_cache[:label_text].has_key?(index)
    cached = node_cache[:label_text][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  s0, i0 = [], index
  loop do
    i1, s1 = index, []
    i2 = index
    i3 = index
    r4 = _nt_non_text
    if r4
      r3 = r4
    else
      r5 = _nt_label_end
      if r5
        r3 = r5
      else
        @index = i3
        r3 = nil
      end
    end
    if r3
      r2 = nil
    else
      @index = i2
      r2 = instantiate_node(SyntaxNode,input, index...index)
    end
    s1 << r2
    if r2
      if index < input_length
        r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
        @index += 1
      else
        terminal_parse_failure("any character")
        r6 = nil
      end
      s1 << r6
    end
    if s1.last
      r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
      r1.extend(LabelText0)
    else
      @index = i1
      r1 = nil
    end
    if r1
      s0 << r1
    else
      break
    end
  end
  if s0.empty?
    @index = i0
    r0 = nil
  else
    r0 = instantiate_node(TextNode,input, i0...index, s0)
  end

  node_cache[:label_text][start_index] = r0

  r0
end

#_nt_listObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hemingway/block/list/list.rb', line 15

def _nt_list
  start_index = index
  if node_cache[:list].has_key?(index)
    cached = node_cache[:list][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  s0, i0 = [], index
  loop do
    r1 = _nt_item
    if r1
      s0 << r1
    else
      break
    end
  end
  if s0.empty?
    @index = i0
    r0 = nil
  else
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
  end

  node_cache[:list][start_index] = r0

  r0
end

#_nt_list_typeObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/hemingway/block/list/list.rb', line 47

def _nt_list_type
  start_index = index
  if node_cache[:list_type].has_key?(index)
    cached = node_cache[:list_type][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0 = index
  if has_terminal?("itemize", false, index)
    r1 = instantiate_node(ItemizeListNode,input, index...(index + 7))
    @index += 7
  else
    terminal_parse_failure("itemize")
    r1 = nil
  end
  if r1
    r0 = r1
  else
    if has_terminal?("enumerate", false, index)
      r2 = instantiate_node(EnumerateListNode,input, index...(index + 9))
      @index += 9
    else
      terminal_parse_failure("enumerate")
      r2 = nil
    end
    if r2
      r0 = r2
    else
      if has_terminal?("description", false, index)
        r3 = instantiate_node(DescriptionListNode,input, index...(index + 11))
        @index += 11
      else
        terminal_parse_failure("description")
        r3 = nil
      end
      if r3
        r0 = r3
      else
        @index = i0
        r0 = nil
      end
    end
  end

  node_cache[:list_type][start_index] = r0

  r0
end

#rootObject



11
12
13
# File 'lib/hemingway/block/list/list.rb', line 11

def root
  @root ||= :list
end