Module: SgfGrammar

Includes:
Treetop::Runtime
Included in:
SgfGrammarParser
Defined in:
lib/grammar/sgf-grammar.rb

Defined Under Namespace

Modules: Chunk0, Chunk1, Node0, Node1, Property0, PropertyBracket0, PropertySet0, PropertySet1

Instance Method Summary collapse

Instance Method Details

#_nt_chunkObject



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
185
186
187
188
# File 'lib/grammar/sgf-grammar.rb', line 138

def _nt_chunk
  start_index = index
  if node_cache[:chunk].has_key?(index)
    cached = node_cache[:chunk][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0, s0 = index, []
  if input.index(';', index) == index
    r1 = (SyntaxNode).new(input, index...(index + 1))
    @index += 1
  else
    terminal_parse_failure(';')
    r1 = nil
  end
  s0 << r1
  if r1
    r2 = _nt_sp
    s0 << r2
    if r2
      s3, i3 = [], index
      loop do
        r4 = _nt_property_set
        if r4
          s3 << r4
        else
          break
        end
      end
      r3 = SyntaxNode.new(input, i3...index, s3)
      s0 << r3
      if r3
        r5 = _nt_sp
        s0 << r5
      end
    end
  end
  if s0.last
    r0 = (SyntaxNode).new(input, i0...index, s0)
    r0.extend(Chunk0)
    r0.extend(Chunk1)
  else
    self.index = i0
    r0 = nil
  end

  node_cache[:chunk][start_index] = r0

  return r0
end

#_nt_nodeObject



42
43
44
45
46
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
99
100
101
102
103
104
105
106
# File 'lib/grammar/sgf-grammar.rb', line 42

def _nt_node
  start_index = index
  if node_cache[:node].has_key?(index)
    cached = node_cache[:node][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0, s0 = index, []
  if input.index('(', index) == index
    r1 = (SyntaxNode).new(input, index...(index + 1))
    @index += 1
  else
    terminal_parse_failure('(')
    r1 = nil
  end
  s0 << r1
  if r1
    r2 = _nt_sp
    s0 << r2
    if r2
      s3, i3 = [], index
      loop do
        r4 = _nt_chunk
        if r4
          s3 << r4
        else
          break
        end
      end
      r3 = SyntaxNode.new(input, i3...index, s3)
      s0 << r3
      if r3
        r5 = _nt_sp
        s0 << r5
        if r5
          if input.index(')', index) == index
            r6 = (SyntaxNode).new(input, index...(index + 1))
            @index += 1
          else
            terminal_parse_failure(')')
            r6 = nil
          end
          s0 << r6
          if r6
            r7 = _nt_sp
            s0 << r7
          end
        end
      end
    end
  end
  if s0.last
    r0 = (SyntaxNode).new(input, i0...index, s0)
    r0.extend(Node0)
    r0.extend(Node1)
  else
    self.index = i0
    r0 = nil
  end

  node_cache[:node][start_index] = r0

  return r0
end

#_nt_propertyObject



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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/grammar/sgf-grammar.rb', line 330

def _nt_property
  start_index = index
  if node_cache[:property].has_key?(index)
    cached = node_cache[:property][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0 = index
  s1, i1 = [], index
  loop do
    if input.index(Regexp.new('[A-Z]'), index) == index
      r2 = (SyntaxNode).new(input, index...(index + 1))
      @index += 1
    else
      r2 = nil
    end
    if r2
      s1 << r2
    else
      break
    end
  end
  if s1.empty?
    self.index = i1
    r1 = nil
  else
    r1 = SyntaxNode.new(input, i1...index, s1)
  end
  if r1
    r0 = r1
  else
    i3, s3 = index, []
    if input.index(Regexp.new('[A-Z]'), index) == index
      r4 = (SyntaxNode).new(input, index...(index + 1))
      @index += 1
    else
      r4 = nil
    end
    s3 << r4
    if r4
      r5 = _nt_sp
      s3 << r5
    end
    if s3.last
      r3 = (SyntaxNode).new(input, i3...index, s3)
      r3.extend(Property0)
    else
      self.index = i3
      r3 = nil
    end
    if r3
      r0 = r3
    else
      self.index = i0
      r0 = nil
    end
  end

  node_cache[:property][start_index] = r0

  return r0
end

#_nt_property_bracketObject



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
288
289
290
291
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
# File 'lib/grammar/sgf-grammar.rb', line 254

def _nt_property_bracket
  start_index = index
  if node_cache[:property_bracket].has_key?(index)
    cached = node_cache[:property_bracket][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0, s0 = index, []
  if input.index('[', index) == index
    r1 = (SyntaxNode).new(input, index...(index + 1))
    @index += 1
  else
    terminal_parse_failure('[')
    r1 = nil
  end
  s0 << r1
  if r1
    s2, i2 = [], index
    loop do
      i3 = index
      if input.index(Regexp.new('[^\\[\\]]'), index) == index
        r4 = (SyntaxNode).new(input, index...(index + 1))
        @index += 1
      else
        r4 = nil
      end
      if r4
        r3 = r4
      else
        r5 = _nt_property_bracket
        if r5
          r3 = r5
        else
          self.index = i3
          r3 = nil
        end
      end
      if r3
        s2 << r3
      else
        break
      end
    end
    r2 = SyntaxNode.new(input, i2...index, s2)
    s0 << r2
    if r2
      if input.index(']', index) == index
        r6 = (SyntaxNode).new(input, index...(index + 1))
        @index += 1
      else
        terminal_parse_failure(']')
        r6 = nil
      end
      s0 << r6
    end
  end
  if s0.last
    r0 = (SyntaxNode).new(input, i0...index, s0)
    r0.extend(PropertyBracket0)
  else
    self.index = i0
    r0 = nil
  end

  node_cache[:property_bracket][start_index] = r0

  return r0
end

#_nt_property_setObject



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
243
244
245
246
247
248
249
# File 'lib/grammar/sgf-grammar.rb', line 209

def _nt_property_set
  start_index = index
  if node_cache[:property_set].has_key?(index)
    cached = node_cache[:property_set][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0, s0 = index, []
  r1 = _nt_property
  s0 << r1
  if r1
    s2, i2 = [], index
    loop do
      r3 = _nt_property_bracket
      if r3
        s2 << r3
      else
        break
      end
    end
    r2 = SyntaxNode.new(input, i2...index, s2)
    s0 << r2
    if r2
      r4 = _nt_sp
      s0 << r4
    end
  end
  if s0.last
    r0 = (SyntaxNode).new(input, i0...index, s0)
    r0.extend(PropertySet0)
    r0.extend(PropertySet1)
  else
    self.index = i0
    r0 = nil
  end

  node_cache[:property_set][start_index] = r0

  return r0
end

#_nt_spObject



394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/grammar/sgf-grammar.rb', line 394

def _nt_sp
  start_index = index
  if node_cache[:sp].has_key?(index)
    cached = node_cache[:sp][index]
    @index = cached.interval.end if cached
    return cached
  end

  s0, i0 = [], index
  loop do
    if input.index(Regexp.new('[\\r\\n\\t ]'), index) == index
      r1 = (SyntaxNode).new(input, index...(index + 1))
      @index += 1
    else
      r1 = nil
    end
    if r1
      s0 << r1
    else
      break
    end
  end
  r0 = SyntaxNode.new(input, i0...index, s0)

  node_cache[:sp][start_index] = r0

  return r0
end

#rootObject



4
5
6
# File 'lib/grammar/sgf-grammar.rb', line 4

def root
  @root || :node
end