Module: ActiveFacts::CQL::Expressions

Includes:
Treetop::Runtime
Included in:
CQL, ExpressionsParser
Defined in:
lib/activefacts/cql/parser/Expressions.rb

Defined Under Namespace

Modules: DerivedVariable0, DerivedVariable1, Factor0, Factor1, Factor2, Factor3, Product0, Product1, Product2, Sum0, Sum1, Sum2

Instance Method Summary collapse

Instance Method Details

#_nt_add_opObject



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
# File 'lib/activefacts/cql/parser/Expressions.rb', line 145

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

  i0 = index
  if (match_len = has_terminal?('+', false, index))
    r1 = true
    @index += match_len
  else
    terminal_parse_failure('\'+\'')
    r1 = nil
  end
  if r1
    r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
    r0 = r1
  else
    if (match_len = has_terminal?('-', false, index))
      r2 = true
      @index += match_len
    else
      terminal_parse_failure('\'-\'')
      r2 = nil
    end
    if r2
      r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
      r0 = r2
    else
      @index = i0
      r0 = nil
    end
  end

  node_cache[:add_op][start_index] = r0

  r0
end

#_nt_derived_variableObject



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/activefacts/cql/parser/Expressions.rb', line 475

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

  i0, s0 = index, []
  r1 = _nt_term
  s0 << r1
  if r1
    r2 = _nt_s
    s0 << r2
    if r2
      i4 = index
      r5 = _nt_role_name
      if r5
        r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
        r4 = r5
      else
        r6 = _nt_subscript
        if r6
          r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
          r4 = r6
        else
          @index = i4
          r4 = nil
        end
      end
      if r4
        r3 = r4
      else
        r3 = instantiate_node(SyntaxNode,input, index...index)
      end
      s0 << r3
    end
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(DerivedVariable0)
    r0.extend(DerivedVariable1)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:derived_variable][start_index] = r0

  r0
end

#_nt_expressionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/activefacts/cql/parser/Expressions.rb', line 19

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

  r0 = _nt_sum

  node_cache[:expression][start_index] = r0

  r0
end

#_nt_factorObject



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
393
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/activefacts/cql/parser/Expressions.rb', line 339

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

  i0 = index
  i1, s1 = index, []
  r2 = _nt_literal
  s1 << r2
  if r2
    r4 = _nt_unit
    if r4
      r3 = r4
    else
      r3 = instantiate_node(SyntaxNode,input, index...index)
    end
    s1 << r3
    if r3
      r5 = _nt_s
      s1 << r5
    end
  end
  if s1.last
    r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
    r1.extend(Factor0)
    r1.extend(Factor1)
  else
    @index = i1
    r1 = nil
  end
  if r1
    r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
    r0 = r1
  else
    r6 = _nt_derived_variable
    if r6
      r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
      r0 = r6
    else
      i7, s7 = index, []
      i8 = index
      r9 = _nt_context_note
      if r9
        @index = i8
        r8 = nil
      else
        @index = i8
        r8 = instantiate_node(SyntaxNode,input, index...index)
      end
      s7 << r8
      if r8
        if (match_len = has_terminal?('(', false, index))
          r10 = true
          @index += match_len
        else
          terminal_parse_failure('\'(\'')
          r10 = nil
        end
        s7 << r10
        if r10
          r11 = _nt_s
          s7 << r11
          if r11
            r12 = _nt_sum
            s7 << r12
            if r12
              r13 = _nt_s
              s7 << r13
              if r13
                if (match_len = has_terminal?(')', false, index))
                  r14 = true
                  @index += match_len
                else
                  terminal_parse_failure('\')\'')
                  r14 = nil
                end
                s7 << r14
                if r14
                  r15 = _nt_s
                  s7 << r15
                end
              end
            end
          end
        end
      end
      if s7.last
        r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
        r7.extend(Factor2)
        r7.extend(Factor3)
      else
        @index = i7
        r7 = nil
      end
      if r7
        r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
        r0 = r7
      else
        @index = i0
        r0 = nil
      end
    end
  end

  node_cache[:factor][start_index] = r0

  r0
end

#_nt_productObject



231
232
233
234
235
236
237
238
239
240
241
242
243
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
288
289
290
291
292
293
294
295
# File 'lib/activefacts/cql/parser/Expressions.rb', line 231

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

  i0, s0 = index, []
  r1 = _nt_factor
  s0 << r1
  if r1
    r2 = _nt_s
    s0 << r2
    if r2
      s3, i3 = [], index
      loop do
        i4, s4 = index, []
        r5 = _nt_mul_op
        s4 << r5
        if r5
          r6 = _nt_s
          s4 << r6
          if r6
            r7 = _nt_factor
            s4 << r7
            if r7
              r8 = _nt_s
              s4 << r8
            end
          end
        end
        if s4.last
          r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
          r4.extend(Product0)
        else
          @index = i4
          r4 = nil
        end
        if r4
          s3 << r4
        else
          break
        end
      end
      r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
      s0 << r3
    end
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(Product1)
    r0.extend(Product2)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:product][start_index] = r0

  r0
end

#_nt_sumObject



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
107
108
109
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
# File 'lib/activefacts/cql/parser/Expressions.rb', line 79

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

  i0, s0 = index, []
  r1 = _nt_product
  s0 << r1
  if r1
    r2 = _nt_s
    s0 << r2
    if r2
      s3, i3 = [], index
      loop do
        i4, s4 = index, []
        r5 = _nt_add_op
        s4 << r5
        if r5
          r6 = _nt_s
          s4 << r6
          if r6
            r7 = _nt_product
            s4 << r7
            if r7
              r8 = _nt_s
              s4 << r8
            end
          end
        end
        if s4.last
          r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
          r4.extend(Sum0)
        else
          @index = i4
          r4 = nil
        end
        if r4
          s3 << r4
        else
          break
        end
      end
      r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
      s0 << r3
    end
  end
  if s0.last
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
    r0.extend(Sum1)
    r0.extend(Sum2)
  else
    @index = i0
    r0 = nil
  end

  node_cache[:sum][start_index] = r0

  r0
end

#rootObject



15
16
17
# File 'lib/activefacts/cql/parser/Expressions.rb', line 15

def root
  @root ||= :expression
end