Statistics
| Branch: | Tag: | Revision:

one / src / flow / lib / grammar.rb @ 56fbcea8

History | View | Annotate | Download (26.9 KB)

1
# -------------------------------------------------------------------------- #
2
# Autogenerated from a Treetop grammar. Edits may be lost.
3

    
4

    
5
# Copyright 2010-2015, C12G Labs S.L.                                        #
6
#                                                                            #
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
8
# not use this file except in compliance with the License. You may obtain    #
9
# a copy of the License at                                                   #
10
#                                                                            #
11
# http://www.apache.org/licenses/LICENSE-2.0                                 #
12
#                                                                            #
13
# Unless required by applicable law or agreed to in writing, software        #
14
# distributed under the License is distributed on an "AS IS" BASIS,          #
15
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
16
# See the License for the specific language governing permissions and        #
17
# limitations under the License.                                             #
18
#--------------------------------------------------------------------------- #
19

    
20
module ElasticityGrammar
21
  include Treetop::Runtime
22

    
23
  def root
24
    @root ||= :expression
25
  end
26

    
27
  module Expression0
28
    def space1
29
      elements[0]
30
    end
31

    
32
    def exp
33
      elements[1]
34
    end
35

    
36
    def space2
37
      elements[2]
38
    end
39
  end
40

    
41
  module Expression1
42
    def result(role)
43
        return exp.result(role)
44
    end
45
  end
46

    
47
  def _nt_expression
48
    start_index = index
49
    if node_cache[:expression].has_key?(index)
50
      cached = node_cache[:expression][index]
51
      if cached
52
        node_cache[:expression][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
53
        @index = cached.interval.end
54
      end
55
      return cached
56
    end
57

    
58
    i0, s0 = index, []
59
    r1 = _nt_space
60
    s0 << r1
61
    if r1
62
      i2 = index
63
      r3 = _nt_boolean_exp
64
      if r3
65
        r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
66
        r2 = r3
67
      else
68
        r4 = _nt_logic_cond
69
        if r4
70
          r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
71
          r2 = r4
72
        else
73
          @index = i2
74
          r2 = nil
75
        end
76
      end
77
      s0 << r2
78
      if r2
79
        r5 = _nt_space
80
        s0 << r5
81
      end
82
    end
83
    if s0.last
84
      r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
85
      r0.extend(Expression0)
86
      r0.extend(Expression1)
87
    else
88
      @index = i0
89
      r0 = nil
90
    end
91

    
92
    node_cache[:expression][start_index] = r0
93

    
94
    r0
95
  end
96

    
97
  module BooleanExp0
98
    def left
99
      elements[0]
100
    end
101

    
102
    def space1
103
      elements[1]
104
    end
105

    
106
    def op
107
      elements[2]
108
    end
109

    
110
    def space2
111
      elements[3]
112
    end
113

    
114
    def right
115
      elements[4]
116
    end
117
  end
118

    
119
  module BooleanExp1
120
    def result(role)
121
        l_val, l_st = left.result(role)
122
        r_val, r_st = right.result(role)
123

    
124
        st = "#{l_st} #{op.text_value} #{r_st}"
125
        val = l_val && r_val
126

    
127
        return [val, st]
128
    end
129
  end
130

    
131
  module BooleanExp2
132
    def left
133
      elements[0]
134
    end
135

    
136
    def space1
137
      elements[1]
138
    end
139

    
140
    def op
141
      elements[2]
142
    end
143

    
144
    def space2
145
      elements[3]
146
    end
147

    
148
    def right
149
      elements[4]
150
    end
151
  end
152

    
153
  module BooleanExp3
154
    def result(role)
155
        l_val, l_st = left.result(role)
156
        r_val, r_st = right.result(role)
157

    
158
        st = "#{l_st} #{op.text_value} #{r_st}"
159
        val = l_val || r_val
160

    
161
        return [val, st]
162
    end
163
  end
164

    
165
  def _nt_boolean_exp
166
    start_index = index
167
    if node_cache[:boolean_exp].has_key?(index)
168
      cached = node_cache[:boolean_exp][index]
169
      if cached
170
        node_cache[:boolean_exp][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
171
        @index = cached.interval.end
172
      end
173
      return cached
174
    end
175

    
176
    i0 = index
177
    i1, s1 = index, []
178
    r2 = _nt_logic_cond
179
    s1 << r2
180
    if r2
181
      r3 = _nt_space
182
      s1 << r3
183
      if r3
184
        i4 = index
185
        if (match_len = has_terminal?('&&', false, index))
186
          r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
187
          @index += match_len
188
        else
189
          terminal_parse_failure('\'&&\'')
190
          r5 = nil
191
        end
192
        if r5
193
          r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
194
          r4 = r5
195
        else
196
          if (match_len = has_terminal?('&', false, index))
197
            r6 = true
198
            @index += match_len
199
          else
200
            terminal_parse_failure('\'&\'')
201
            r6 = nil
202
          end
203
          if r6
204
            r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
205
            r4 = r6
206
          else
207
            @index = i4
208
            r4 = nil
209
          end
210
        end
211
        s1 << r4
212
        if r4
213
          r7 = _nt_space
214
          s1 << r7
215
          if r7
216
            r8 = _nt_expression
217
            s1 << r8
218
          end
219
        end
220
      end
221
    end
222
    if s1.last
223
      r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
224
      r1.extend(BooleanExp0)
225
      r1.extend(BooleanExp1)
226
    else
227
      @index = i1
228
      r1 = nil
229
    end
230
    if r1
231
      r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
232
      r0 = r1
233
    else
234
      i9, s9 = index, []
235
      r10 = _nt_logic_cond
236
      s9 << r10
237
      if r10
238
        r11 = _nt_space
239
        s9 << r11
240
        if r11
241
          i12 = index
242
          if (match_len = has_terminal?('||', false, index))
243
            r13 = instantiate_node(SyntaxNode,input, index...(index + match_len))
244
            @index += match_len
245
          else
246
            terminal_parse_failure('\'||\'')
247
            r13 = nil
248
          end
249
          if r13
250
            r13 = SyntaxNode.new(input, (index-1)...index) if r13 == true
251
            r12 = r13
252
          else
253
            if (match_len = has_terminal?('|', false, index))
254
              r14 = true
255
              @index += match_len
256
            else
257
              terminal_parse_failure('\'|\'')
258
              r14 = nil
259
            end
260
            if r14
261
              r14 = SyntaxNode.new(input, (index-1)...index) if r14 == true
262
              r12 = r14
263
            else
264
              @index = i12
265
              r12 = nil
266
            end
267
          end
268
          s9 << r12
269
          if r12
270
            r15 = _nt_space
271
            s9 << r15
272
            if r15
273
              r16 = _nt_expression
274
              s9 << r16
275
            end
276
          end
277
        end
278
      end
279
      if s9.last
280
        r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
281
        r9.extend(BooleanExp2)
282
        r9.extend(BooleanExp3)
283
      else
284
        @index = i9
285
        r9 = nil
286
      end
287
      if r9
288
        r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
289
        r0 = r9
290
      else
291
        @index = i0
292
        r0 = nil
293
      end
294
    end
295

    
296
    node_cache[:boolean_exp][start_index] = r0
297

    
298
    r0
299
  end
300

    
301
  module LogicCond0
302
    def left
303
      elements[0]
304
    end
305

    
306
    def space1
307
      elements[1]
308
    end
309

    
310
    def comp_op
311
      elements[2]
312
    end
313

    
314
    def space2
315
      elements[3]
316
    end
317

    
318
    def right
319
      elements[4]
320
    end
321
  end
322

    
323
  module LogicCond1
324
    def result(role)
325
        l_val, l_st = left.result(role)
326
        r_val, r_st = right.result(role)
327

    
328
        st = "#{l_st} #{comp_op.text_value} #{r_st}"
329

    
330
        if l_val.nil? || r_val.nil?
331
            # An attribute was not found, we return false instead
332
            # of assuming a value of 0
333

    
334
            val = false
335
        else
336
            val = comp_op.apply(l_val, r_val)
337
        end
338

    
339
        return [val, st]
340
    end
341
  end
342

    
343
  module LogicCond2
344
    def space
345
      elements[1]
346
    end
347

    
348
    def expression
349
      elements[2]
350
    end
351
  end
352

    
353
  module LogicCond3
354
    def result(role)
355
        e_val, e_st = expression.result(role)
356

    
357
        val = !e_val
358
        st = "!#{e_st}"
359

    
360
        return [val, st]
361
    end
362
  end
363

    
364
  module LogicCond4
365
    def space1
366
      elements[1]
367
    end
368

    
369
    def expression
370
      elements[2]
371
    end
372

    
373
    def space2
374
      elements[3]
375
    end
376

    
377
  end
378

    
379
  module LogicCond5
380
    def result(role)
381
        e_val, e_st = expression.result(role)
382

    
383
        st = "(#{e_st})"
384

    
385
        return [e_val, st]
386
    end
387
  end
388

    
389
  def _nt_logic_cond
390
    start_index = index
391
    if node_cache[:logic_cond].has_key?(index)
392
      cached = node_cache[:logic_cond][index]
393
      if cached
394
        node_cache[:logic_cond][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
395
        @index = cached.interval.end
396
      end
397
      return cached
398
    end
399

    
400
    i0 = index
401
    i1, s1 = index, []
402
    r2 = _nt_operand
403
    s1 << r2
404
    if r2
405
      r3 = _nt_space
406
      s1 << r3
407
      if r3
408
        r4 = _nt_comp_op
409
        s1 << r4
410
        if r4
411
          r5 = _nt_space
412
          s1 << r5
413
          if r5
414
            r6 = _nt_operand
415
            s1 << r6
416
          end
417
        end
418
      end
419
    end
420
    if s1.last
421
      r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
422
      r1.extend(LogicCond0)
423
      r1.extend(LogicCond1)
424
    else
425
      @index = i1
426
      r1 = nil
427
    end
428
    if r1
429
      r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
430
      r0 = r1
431
    else
432
      i7, s7 = index, []
433
      if (match_len = has_terminal?('!', false, index))
434
        r8 = true
435
        @index += match_len
436
      else
437
        terminal_parse_failure('\'!\'')
438
        r8 = nil
439
      end
440
      s7 << r8
441
      if r8
442
        r9 = _nt_space
443
        s7 << r9
444
        if r9
445
          r10 = _nt_expression
446
          s7 << r10
447
        end
448
      end
449
      if s7.last
450
        r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
451
        r7.extend(LogicCond2)
452
        r7.extend(LogicCond3)
453
      else
454
        @index = i7
455
        r7 = nil
456
      end
457
      if r7
458
        r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
459
        r0 = r7
460
      else
461
        i11, s11 = index, []
462
        if (match_len = has_terminal?('(', false, index))
463
          r12 = true
464
          @index += match_len
465
        else
466
          terminal_parse_failure('\'(\'')
467
          r12 = nil
468
        end
469
        s11 << r12
470
        if r12
471
          r13 = _nt_space
472
          s11 << r13
473
          if r13
474
            r14 = _nt_expression
475
            s11 << r14
476
            if r14
477
              r15 = _nt_space
478
              s11 << r15
479
              if r15
480
                if (match_len = has_terminal?(')', false, index))
481
                  r16 = true
482
                  @index += match_len
483
                else
484
                  terminal_parse_failure('\')\'')
485
                  r16 = nil
486
                end
487
                s11 << r16
488
              end
489
            end
490
          end
491
        end
492
        if s11.last
493
          r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
494
          r11.extend(LogicCond4)
495
          r11.extend(LogicCond5)
496
        else
497
          @index = i11
498
          r11 = nil
499
        end
500
        if r11
501
          r11 = SyntaxNode.new(input, (index-1)...index) if r11 == true
502
          r0 = r11
503
        else
504
          @index = i0
505
          r0 = nil
506
        end
507
      end
508
    end
509

    
510
    node_cache[:logic_cond][start_index] = r0
511

    
512
    r0
513
  end
514

    
515
  module CompOp0
516
    def apply(a,b)
517
        a == b
518
    end
519
  end
520

    
521
  module CompOp1
522
    def apply(a,b)
523
        a != b
524
    end
525
  end
526

    
527
  module CompOp2
528
    def apply(a,b)
529
        a >= b
530
    end
531
  end
532

    
533
  module CompOp3
534
    def apply(a,b)
535
        a > b
536
    end
537
  end
538

    
539
  module CompOp4
540
    def apply(a,b)
541
        a <= b
542
    end
543
  end
544

    
545
  module CompOp5
546
    def apply(a,b)
547
        a < b
548
    end
549
  end
550

    
551
  def _nt_comp_op
552
    start_index = index
553
    if node_cache[:comp_op].has_key?(index)
554
      cached = node_cache[:comp_op][index]
555
      if cached
556
        node_cache[:comp_op][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
557
        @index = cached.interval.end
558
      end
559
      return cached
560
    end
561

    
562
    i0 = index
563
    i1 = index
564
    if (match_len = has_terminal?('==', false, index))
565
      r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
566
      @index += match_len
567
    else
568
      terminal_parse_failure('\'==\'')
569
      r2 = nil
570
    end
571
    if r2
572
      r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
573
      r1 = r2
574
      r1.extend(CompOp0)
575
    else
576
      if (match_len = has_terminal?('=', false, index))
577
        r3 = true
578
        @index += match_len
579
      else
580
        terminal_parse_failure('\'=\'')
581
        r3 = nil
582
      end
583
      if r3
584
        r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
585
        r1 = r3
586
        r1.extend(CompOp0)
587
      else
588
        @index = i1
589
        r1 = nil
590
      end
591
    end
592
    if r1
593
      r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
594
      r0 = r1
595
    else
596
      i4 = index
597
      if (match_len = has_terminal?('!=', false, index))
598
        r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
599
        @index += match_len
600
      else
601
        terminal_parse_failure('\'!=\'')
602
        r5 = nil
603
      end
604
      if r5
605
        r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
606
        r4 = r5
607
        r4.extend(CompOp1)
608
      else
609
        if (match_len = has_terminal?('<>', false, index))
610
          r6 = instantiate_node(SyntaxNode,input, index...(index + match_len))
611
          @index += match_len
612
        else
613
          terminal_parse_failure('\'<>\'')
614
          r6 = nil
615
        end
616
        if r6
617
          r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
618
          r4 = r6
619
          r4.extend(CompOp1)
620
        else
621
          @index = i4
622
          r4 = nil
623
        end
624
      end
625
      if r4
626
        r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
627
        r0 = r4
628
      else
629
        if (match_len = has_terminal?('>=', false, index))
630
          r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
631
          r7.extend(CompOp2)
632
          @index += match_len
633
        else
634
          terminal_parse_failure('\'>=\'')
635
          r7 = nil
636
        end
637
        if r7
638
          r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
639
          r0 = r7
640
        else
641
          if (match_len = has_terminal?('>', false, index))
642
            r8 = instantiate_node(SyntaxNode,input, index...(index + match_len))
643
            r8.extend(CompOp3)
644
            @index += match_len
645
          else
646
            terminal_parse_failure('\'>\'')
647
            r8 = nil
648
          end
649
          if r8
650
            r8 = SyntaxNode.new(input, (index-1)...index) if r8 == true
651
            r0 = r8
652
          else
653
            if (match_len = has_terminal?('<=', false, index))
654
              r9 = instantiate_node(SyntaxNode,input, index...(index + match_len))
655
              r9.extend(CompOp4)
656
              @index += match_len
657
            else
658
              terminal_parse_failure('\'<=\'')
659
              r9 = nil
660
            end
661
            if r9
662
              r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
663
              r0 = r9
664
            else
665
              if (match_len = has_terminal?('<', false, index))
666
                r10 = instantiate_node(SyntaxNode,input, index...(index + match_len))
667
                r10.extend(CompOp5)
668
                @index += match_len
669
              else
670
                terminal_parse_failure('\'<\'')
671
                r10 = nil
672
              end
673
              if r10
674
                r10 = SyntaxNode.new(input, (index-1)...index) if r10 == true
675
                r0 = r10
676
              else
677
                @index = i0
678
                r0 = nil
679
              end
680
            end
681
          end
682
        end
683
      end
684
    end
685

    
686
    node_cache[:comp_op][start_index] = r0
687

    
688
    r0
689
  end
690

    
691
  module Operand0
692
    def result
693
        number.result(role)
694
    end
695
  end
696

    
697
  module Operand1
698
    def result
699
        variable.result(role)
700
    end
701
  end
702

    
703
  def _nt_operand
704
    start_index = index
705
    if node_cache[:operand].has_key?(index)
706
      cached = node_cache[:operand][index]
707
      if cached
708
        node_cache[:operand][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
709
        @index = cached.interval.end
710
      end
711
      return cached
712
    end
713

    
714
    i0 = index
715
    r1 = _nt_number
716
    if r1
717
      r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
718
      r0 = r1
719
    else
720
      r2 = _nt_variable
721
      if r2
722
        r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
723
        r0 = r2
724
      else
725
        @index = i0
726
        r0 = nil
727
      end
728
    end
729

    
730
    node_cache[:operand][start_index] = r0
731

    
732
    r0
733
  end
734

    
735
  module Number0
736
  end
737

    
738
  module Number1
739
    def result(role)
740
        val = text_value.to_f
741
        st = val.to_s
742

    
743
        return [val, st]
744
    end
745
  end
746

    
747
  module Number2
748
  end
749

    
750
  module Number3
751
    def result(role)
752
        val = text_value.to_i
753
        st = val.to_s
754

    
755
        return [val, st]
756
    end
757
  end
758

    
759
  def _nt_number
760
    start_index = index
761
    if node_cache[:number].has_key?(index)
762
      cached = node_cache[:number][index]
763
      if cached
764
        node_cache[:number][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
765
        @index = cached.interval.end
766
      end
767
      return cached
768
    end
769

    
770
    i0 = index
771
    i1, s1 = index, []
772
    if (match_len = has_terminal?('-', false, index))
773
      r3 = true
774
      @index += match_len
775
    else
776
      terminal_parse_failure('\'-\'')
777
      r3 = nil
778
    end
779
    if r3
780
      r2 = r3
781
    else
782
      r2 = instantiate_node(SyntaxNode,input, index...index)
783
    end
784
    s1 << r2
785
    if r2
786
      s4, i4 = [], index
787
      loop do
788
        if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
789
          r5 = true
790
          @index += 1
791
        else
792
          terminal_parse_failure('[0-9]')
793
          r5 = nil
794
        end
795
        if r5
796
          s4 << r5
797
        else
798
          break
799
        end
800
      end
801
      if s4.empty?
802
        @index = i4
803
        r4 = nil
804
      else
805
        r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
806
      end
807
      s1 << r4
808
      if r4
809
        if (match_len = has_terminal?('.', false, index))
810
          r6 = true
811
          @index += match_len
812
        else
813
          terminal_parse_failure('\'.\'')
814
          r6 = nil
815
        end
816
        s1 << r6
817
        if r6
818
          s7, i7 = [], index
819
          loop do
820
            if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
821
              r8 = true
822
              @index += 1
823
            else
824
              terminal_parse_failure('[0-9]')
825
              r8 = nil
826
            end
827
            if r8
828
              s7 << r8
829
            else
830
              break
831
            end
832
          end
833
          if s7.empty?
834
            @index = i7
835
            r7 = nil
836
          else
837
            r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
838
          end
839
          s1 << r7
840
        end
841
      end
842
    end
843
    if s1.last
844
      r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
845
      r1.extend(Number0)
846
      r1.extend(Number1)
847
    else
848
      @index = i1
849
      r1 = nil
850
    end
851
    if r1
852
      r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
853
      r0 = r1
854
    else
855
      i9, s9 = index, []
856
      if (match_len = has_terminal?('-', false, index))
857
        r11 = true
858
        @index += match_len
859
      else
860
        terminal_parse_failure('\'-\'')
861
        r11 = nil
862
      end
863
      if r11
864
        r10 = r11
865
      else
866
        r10 = instantiate_node(SyntaxNode,input, index...index)
867
      end
868
      s9 << r10
869
      if r10
870
        s12, i12 = [], index
871
        loop do
872
          if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
873
            r13 = true
874
            @index += 1
875
          else
876
            terminal_parse_failure('[0-9]')
877
            r13 = nil
878
          end
879
          if r13
880
            s12 << r13
881
          else
882
            break
883
          end
884
        end
885
        if s12.empty?
886
          @index = i12
887
          r12 = nil
888
        else
889
          r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
890
        end
891
        s9 << r12
892
      end
893
      if s9.last
894
        r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
895
        r9.extend(Number2)
896
        r9.extend(Number3)
897
      else
898
        @index = i9
899
        r9 = nil
900
      end
901
      if r9
902
        r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
903
        r0 = r9
904
      else
905
        @index = i0
906
        r0 = nil
907
      end
908
    end
909

    
910
    node_cache[:number][start_index] = r0
911

    
912
    r0
913
  end
914

    
915
  module Variable0
916
  end
917

    
918
  module Variable1
919
  end
920

    
921
  module Variable2
922
  end
923

    
924
  module Variable3
925

    
926
    def result(role)
927
        nodes = role.get_nodes
928
        total = 0
929
        n_nodes = 0
930
        att = text_value.upcase
931

    
932
        nodes.each { |node|
933
            if node && node['vm_info']
934

    
935
                vm_state = node['vm_info']['VM']['STATE']
936
                lcm_state = node['vm_info']['VM']['LCM_STATE']
937

    
938
                # Use values from VMs in RUNNING only
939

    
940
                if vm_state != '3' || lcm_state != '3'
941
                    next
942
                end
943

    
944
                if node['vm_info']['VM']['USER_TEMPLATE'][att]
945
                    total += (node['vm_info']['VM']['USER_TEMPLATE'][att]).to_f
946
                    n_nodes += 1
947
                elsif node['vm_info']['VM']['MONITORING'][att]
948
                    total += (node['vm_info']['VM']['MONITORING'][att]).to_f
949
                    n_nodes += 1
950
                elsif node['vm_info']['VM']['TEMPLATE'][att]
951
                    total += (node['vm_info']['VM']['TEMPLATE'][att]).to_f
952
                    n_nodes += 1
953
                elsif node['vm_info']['VM'][att]
954
                    total += (node['vm_info']['VM'][att]).to_f
955
                    n_nodes += 1
956
                end
957
            end
958
        }
959

    
960
        # The attribute wasn't found for any of the nodes
961
        if n_nodes == 0
962
            val = nil
963
            st = "#{att}[--]"
964
        else
965
            val = ((total / n_nodes)*100).round/100.0
966
            st = "#{att}[#{val.to_s}]"
967
        end
968

    
969
        return [val, st]
970
    end
971
  end
972

    
973
  def _nt_variable
974
    start_index = index
975
    if node_cache[:variable].has_key?(index)
976
      cached = node_cache[:variable][index]
977
      if cached
978
        node_cache[:variable][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
979
        @index = cached.interval.end
980
      end
981
      return cached
982
    end
983

    
984
    i0 = index
985
    i1, s1 = index, []
986
    if (match_len = has_terminal?('"', false, index))
987
      r2 = true
988
      @index += match_len
989
    else
990
      terminal_parse_failure('\'"\'')
991
      r2 = nil
992
    end
993
    s1 << r2
994
    if r2
995
      if has_terminal?(@regexps[gr = '\A[a-zA-Z]'] ||= Regexp.new(gr), :regexp, index)
996
        r3 = true
997
        @index += 1
998
      else
999
        terminal_parse_failure('[a-zA-Z]')
1000
        r3 = nil
1001
      end
1002
      s1 << r3
1003
      if r3
1004
        s4, i4 = [], index
1005
        loop do
1006
          if has_terminal?(@regexps[gr = '\A[0-9a-zA-Z_]'] ||= Regexp.new(gr), :regexp, index)
1007
            r5 = true
1008
            @index += 1
1009
          else
1010
            terminal_parse_failure('[0-9a-zA-Z_]')
1011
            r5 = nil
1012
          end
1013
          if r5
1014
            s4 << r5
1015
          else
1016
            break
1017
          end
1018
        end
1019
        r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
1020
        s1 << r4
1021
        if r4
1022
          if (match_len = has_terminal?('"', false, index))
1023
            r6 = true
1024
            @index += match_len
1025
          else
1026
            terminal_parse_failure('\'"\'')
1027
            r6 = nil
1028
          end
1029
          s1 << r6
1030
        end
1031
      end
1032
    end
1033
    if s1.last
1034
      r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
1035
      r1.extend(Variable0)
1036
    else
1037
      @index = i1
1038
      r1 = nil
1039
    end
1040
    if r1
1041
      r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
1042
      r0 = r1
1043
      r0.extend(Variable3)
1044
    else
1045
      i7, s7 = index, []
1046
      if (match_len = has_terminal?('\'', false, index))
1047
        r8 = true
1048
        @index += match_len
1049
      else
1050
        terminal_parse_failure('\'\\\'\'')
1051
        r8 = nil
1052
      end
1053
      s7 << r8
1054
      if r8
1055
        if has_terminal?(@regexps[gr = '\A[a-zA-Z]'] ||= Regexp.new(gr), :regexp, index)
1056
          r9 = true
1057
          @index += 1
1058
        else
1059
          terminal_parse_failure('[a-zA-Z]')
1060
          r9 = nil
1061
        end
1062
        s7 << r9
1063
        if r9
1064
          s10, i10 = [], index
1065
          loop do
1066
            if has_terminal?(@regexps[gr = '\A[0-9a-zA-Z_]'] ||= Regexp.new(gr), :regexp, index)
1067
              r11 = true
1068
              @index += 1
1069
            else
1070
              terminal_parse_failure('[0-9a-zA-Z_]')
1071
              r11 = nil
1072
            end
1073
            if r11
1074
              s10 << r11
1075
            else
1076
              break
1077
            end
1078
          end
1079
          r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
1080
          s7 << r10
1081
          if r10
1082
            if (match_len = has_terminal?('\'', false, index))
1083
              r12 = true
1084
              @index += match_len
1085
            else
1086
              terminal_parse_failure('\'\\\'\'')
1087
              r12 = nil
1088
            end
1089
            s7 << r12
1090
          end
1091
        end
1092
      end
1093
      if s7.last
1094
        r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
1095
        r7.extend(Variable1)
1096
      else
1097
        @index = i7
1098
        r7 = nil
1099
      end
1100
      if r7
1101
        r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
1102
        r0 = r7
1103
        r0.extend(Variable3)
1104
      else
1105
        i13, s13 = index, []
1106
        if has_terminal?(@regexps[gr = '\A[a-zA-Z]'] ||= Regexp.new(gr), :regexp, index)
1107
          r14 = true
1108
          @index += 1
1109
        else
1110
          terminal_parse_failure('[a-zA-Z]')
1111
          r14 = nil
1112
        end
1113
        s13 << r14
1114
        if r14
1115
          s15, i15 = [], index
1116
          loop do
1117
            if has_terminal?(@regexps[gr = '\A[0-9a-zA-Z_]'] ||= Regexp.new(gr), :regexp, index)
1118
              r16 = true
1119
              @index += 1
1120
            else
1121
              terminal_parse_failure('[0-9a-zA-Z_]')
1122
              r16 = nil
1123
            end
1124
            if r16
1125
              s15 << r16
1126
            else
1127
              break
1128
            end
1129
          end
1130
          r15 = instantiate_node(SyntaxNode,input, i15...index, s15)
1131
          s13 << r15
1132
        end
1133
        if s13.last
1134
          r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
1135
          r13.extend(Variable2)
1136
        else
1137
          @index = i13
1138
          r13 = nil
1139
        end
1140
        if r13
1141
          r13 = SyntaxNode.new(input, (index-1)...index) if r13 == true
1142
          r0 = r13
1143
          r0.extend(Variable3)
1144
        else
1145
          @index = i0
1146
          r0 = nil
1147
        end
1148
      end
1149
    end
1150

    
1151
    node_cache[:variable][start_index] = r0
1152

    
1153
    r0
1154
  end
1155

    
1156
  def _nt_space
1157
    start_index = index
1158
    if node_cache[:space].has_key?(index)
1159
      cached = node_cache[:space][index]
1160
      if cached
1161
        node_cache[:space][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
1162
        @index = cached.interval.end
1163
      end
1164
      return cached
1165
    end
1166

    
1167
    s0, i0 = [], index
1168
    loop do
1169
      if (match_len = has_terminal?(' ', false, index))
1170
        r1 = true
1171
        @index += match_len
1172
      else
1173
        terminal_parse_failure('\' \'')
1174
        r1 = nil
1175
      end
1176
      if r1
1177
        s0 << r1
1178
      else
1179
        break
1180
      end
1181
    end
1182
    r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
1183

    
1184
    node_cache[:space][start_index] = r0
1185

    
1186
    r0
1187
  end
1188

    
1189
end
1190

    
1191
class ElasticityGrammarParser < Treetop::Runtime::CompiledParser
1192
  include ElasticityGrammar
1193
end