File: ActionEvaluator.py

package info (click to toggle)
python-stringtemplate3 3.1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,392 kB
  • sloc: python: 8,819; makefile: 20
file content (971 lines) | stat: -rw-r--r-- 29,799 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
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
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
189
190
191
192
193
194
195
196
197
198
199
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
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
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
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
### $ANTLR 2.7.7 (2006-11-01): "eval.g" -> "ActionEvaluator.py"$
### import antlr and other modules ..
import sys
import antlr

### header action >>> 
from six import StringIO
from stringtemplate3.language.CatIterator import CatList
from stringtemplate3.language.StringTemplateAST import StringTemplateAST

class NameValuePair(object):

   def __init__(self):
       self.name = None
       self.value = None
### header action <<< 

### import antlr.Token 
from antlr import Token
### >>>The Known Token Types <<<
SKIP                = antlr.SKIP
INVALID_TYPE        = antlr.INVALID_TYPE
EOF_TYPE            = antlr.EOF_TYPE
EOF                 = antlr.EOF
NULL_TREE_LOOKAHEAD = antlr.NULL_TREE_LOOKAHEAD
MIN_USER_TYPE       = antlr.MIN_USER_TYPE
APPLY = 4
MULTI_APPLY = 5
ARGS = 6
INCLUDE = 7
CONDITIONAL = 8
VALUE = 9
TEMPLATE = 10
FUNCTION = 11
SINGLEVALUEARG = 12
LIST = 13
NOTHING = 14
SEMI = 15
LPAREN = 16
RPAREN = 17
LITERAL_elseif = 18
COMMA = 19
ID = 20
ASSIGN = 21
COLON = 22
NOT = 23
PLUS = 24
DOT = 25
LITERAL_first = 26
LITERAL_rest = 27
LITERAL_last = 28
LITERAL_length = 29
LITERAL_strip = 30
LITERAL_trunc = 31
LITERAL_super = 32
ANONYMOUS_TEMPLATE = 33
STRING = 34
INT = 35
LBRACK = 36
RBRACK = 37
DOTDOTDOT = 38
TEMPLATE_ARGS = 39
NESTED_ANONYMOUS_TEMPLATE = 40
ESC_CHAR = 41
WS = 42
WS_CHAR = 43

### user code>>>

### user code<<<

class Walker(antlr.TreeParser):
    
    # ctor ..
    def __init__(self, *args, **kwargs):
        antlr.TreeParser.__init__(self, *args, **kwargs)
        self.tokenNames = _tokenNames
        ### __init__ header action >>> 
        self.this = None
        self.out = None
        self.chunk = None
        ### __init__ header action <<< 
    
    ### user action >>>
    def initialize(self, this, chunk, out):
       self.this = this
       self.chunk = chunk
       self.out = out
    
    def reportError(self, e):
       self.this.error("eval tree parse error", e)
    ### user action <<<
    def action(self, _t):    
        numCharsWritten = 0
        
        action_AST_in = None
        if _t != antlr.ASTNULL:
            action_AST_in = _t
        e = None
        try:      ## for error handling
            pass
            e=self.expr(_t)
            _t = self._retTree
            numCharsWritten = self.chunk.writeAttribute(self.this, e, self.out)
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return numCharsWritten
    
    def expr(self, _t):    
        value = None
        
        expr_AST_in = None
        if _t != antlr.ASTNULL:
            expr_AST_in = _t
        a = None
        b = None
        e = None
        try:      ## for error handling
            if not _t:
                _t = antlr.ASTNULL
            la1 = _t.getType()
            if False:
                pass
            elif la1 and la1 in [PLUS]:
                pass
                _t3 = _t
                tmp1_AST_in = _t
                self.match(_t,PLUS)
                _t = _t.getFirstChild()
                a=self.expr(_t)
                _t = self._retTree
                b=self.expr(_t)
                _t = self._retTree
                value = self.chunk.add(a,b)
                _t = _t3
                _t = _t.getNextSibling()
            elif la1 and la1 in [APPLY,MULTI_APPLY]:
                pass
                value=self.templateApplication(_t)
                _t = self._retTree
            elif la1 and la1 in [ID,DOT,ANONYMOUS_TEMPLATE,STRING,INT]:
                pass
                value=self.attribute(_t)
                _t = self._retTree
            elif la1 and la1 in [INCLUDE]:
                pass
                value=self.templateInclude(_t)
                _t = self._retTree
            elif la1 and la1 in [FUNCTION]:
                pass
                value=self.function(_t)
                _t = self._retTree
            elif la1 and la1 in [LIST,NOTHING]:
                pass
                value=self.list(_t)
                _t = self._retTree
            elif la1 and la1 in [VALUE]:
                pass
                _t4 = _t
                tmp2_AST_in = _t
                self.match(_t,VALUE)
                _t = _t.getFirstChild()
                e=self.expr(_t)
                _t = self._retTree
                _t = _t4
                _t = _t.getNextSibling()
                buf = StringIO()
                sw = self.this.group.getStringTemplateWriter(buf)
                n = self.chunk.writeAttribute(self.this, e, sw)
                if n > 0:
                   value = buf.getvalue()
            else:
                    raise antlr.NoViableAltException(_t)
                
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return value
    

    ###/** Apply template(s) to an attribute; can be applied to another apply
    ### *  result.
    ### */
    def templateApplication(self, _t):    
        value = None
        
        templateApplication_AST_in = None
        if _t != antlr.ASTNULL:
            templateApplication_AST_in = _t
        anon = None
        a = None
        templatesToApply = []
        attributes = []
        try:      ## for error handling
            if not _t:
                _t = antlr.ASTNULL
            la1 = _t.getType()
            if False:
                pass
            elif la1 and la1 in [APPLY]:
                pass
                _t14 = _t
                tmp3_AST_in = _t
                self.match(_t,APPLY)
                _t = _t.getFirstChild()
                a=self.expr(_t)
                _t = self._retTree
                _cnt16= 0
                while True:
                    if not _t:
                        _t = antlr.ASTNULL
                    if (_t.getType()==TEMPLATE):
                        pass
                        self.template(_t, templatesToApply)
                        _t = self._retTree
                    else:
                        break
                    
                    _cnt16 += 1
                if _cnt16 < 1:
                    raise antlr.NoViableAltException(_t)
                value = self.chunk.applyListOfAlternatingTemplates(self.this, \
                   a, templatesToApply)
                _t = _t14
                _t = _t.getNextSibling()
            elif la1 and la1 in [MULTI_APPLY]:
                pass
                _t17 = _t
                tmp4_AST_in = _t
                self.match(_t,MULTI_APPLY)
                _t = _t.getFirstChild()
                _cnt19= 0
                while True:
                    if not _t:
                        _t = antlr.ASTNULL
                    if (_tokenSet_0.member(_t.getType())):
                        pass
                        a=self.expr(_t)
                        _t = self._retTree
                        attributes.append(a)
                    else:
                        break
                    
                    _cnt19 += 1
                if _cnt19 < 1:
                    raise antlr.NoViableAltException(_t)
                tmp5_AST_in = _t
                self.match(_t,COLON)
                _t = _t.getNextSibling()
                anon = _t
                self.match(_t,ANONYMOUS_TEMPLATE)
                _t = _t.getNextSibling()
                anonymous = anon.getStringTemplate()
                templatesToApply.append(anonymous)
                value = self.chunk.applyTemplateToListOfAttributes(self.this, \
                   attributes, anon.getStringTemplate())
                _t = _t17
                _t = _t.getNextSibling()
            else:
                    raise antlr.NoViableAltException(_t)
                
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return value
    
    def attribute(self, _t):    
        value = None
        
        attribute_AST_in = None
        if _t != antlr.ASTNULL:
            attribute_AST_in = _t
        prop = None
        i3 = None
        i = None
        s = None
        at = None
        obj = None
        propName = None
        e = None
        try:      ## for error handling
            if not _t:
                _t = antlr.ASTNULL
            la1 = _t.getType()
            if False:
                pass
            elif la1 and la1 in [DOT]:
                pass
                _t33 = _t
                tmp6_AST_in = _t
                self.match(_t,DOT)
                _t = _t.getFirstChild()
                obj=self.expr(_t)
                _t = self._retTree
                if not _t:
                    _t = antlr.ASTNULL
                la1 = _t.getType()
                if False:
                    pass
                elif la1 and la1 in [ID]:
                    pass
                    prop = _t
                    self.match(_t,ID)
                    _t = _t.getNextSibling()
                    propName = prop.getText()
                elif la1 and la1 in [VALUE]:
                    pass
                    _t35 = _t
                    tmp7_AST_in = _t
                    self.match(_t,VALUE)
                    _t = _t.getFirstChild()
                    e=self.expr(_t)
                    _t = self._retTree
                    _t = _t35
                    _t = _t.getNextSibling()
                    if e: propName = str(e)
                else:
                        raise antlr.NoViableAltException(_t)
                    
                _t = _t33
                _t = _t.getNextSibling()
                value = self.chunk.getObjectProperty(self.this, obj, propName)
            elif la1 and la1 in [ID]:
                pass
                i3 = _t
                self.match(_t,ID)
                _t = _t.getNextSibling()
                value = self.this.getAttribute(i3.getText())
            elif la1 and la1 in [INT]:
                pass
                i = _t
                self.match(_t,INT)
                _t = _t.getNextSibling()
                value = int(i.getText())
            elif la1 and la1 in [STRING]:
                pass
                s = _t
                self.match(_t,STRING)
                _t = _t.getNextSibling()
                value = s.getText()
            elif la1 and la1 in [ANONYMOUS_TEMPLATE]:
                pass
                at = _t
                self.match(_t,ANONYMOUS_TEMPLATE)
                _t = _t.getNextSibling()
                value = at.getText();
                if at.getText():
                   from stringtemplate3.templates import StringTemplate
                   valueST = StringTemplate(
                       group=self.this.group,
                       template=at.getText()
                       )
                   valueST.enclosingInstance = self.this
                   valueST.name = "<anonymous template argument>"
                   value = valueST
            else:
                    raise antlr.NoViableAltException(_t)
                
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return value
    
    def templateInclude(self, _t):    
        value = None
        
        templateInclude_AST_in = None
        if _t != antlr.ASTNULL:
            templateInclude_AST_in = _t
        id = None
        a1 = None
        a2 = None
        args = None
        name = ""
        n = None
        try:      ## for error handling
            pass
            _t10 = _t
            tmp8_AST_in = _t
            self.match(_t,INCLUDE)
            _t = _t.getFirstChild()
            if not _t:
                _t = antlr.ASTNULL
            la1 = _t.getType()
            if False:
                pass
            elif la1 and la1 in [ID]:
                pass
                id = _t
                self.match(_t,ID)
                _t = _t.getNextSibling()
                a1 = _t
                if not _t:
                    raise antlr.MismatchedTokenException()
                _t = _t.getNextSibling()
                name=id.getText(); args=a1
            elif la1 and la1 in [VALUE]:
                pass
                _t12 = _t
                tmp9_AST_in = _t
                self.match(_t,VALUE)
                _t = _t.getFirstChild()
                n=self.expr(_t)
                _t = self._retTree
                a2 = _t
                if not _t:
                    raise antlr.MismatchedTokenException()
                _t = _t.getNextSibling()
                _t = _t12
                _t = _t.getNextSibling()
                if n: name = str(n); args=a2
            else:
                    raise antlr.NoViableAltException(_t)
                
            _t = _t10
            _t = _t.getNextSibling()
            if name:
               value = self.chunk.getTemplateInclude(self.this, name, args)
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return value
    
    def function(self, _t):    
        value = None
        
        function_AST_in = None
        if _t != antlr.ASTNULL:
            function_AST_in = _t
        a = None
        try:      ## for error handling
            pass
            _t21 = _t
            tmp10_AST_in = _t
            self.match(_t,FUNCTION)
            _t = _t.getFirstChild()
            if not _t:
                _t = antlr.ASTNULL
            la1 = _t.getType()
            if False:
                pass
            elif la1 and la1 in [LITERAL_first]:
                pass
                tmp11_AST_in = _t
                self.match(_t,LITERAL_first)
                _t = _t.getNextSibling()
                a=self.singleFunctionArg(_t)
                _t = self._retTree
                value = self.chunk.first(a)
            elif la1 and la1 in [LITERAL_rest]:
                pass
                tmp12_AST_in = _t
                self.match(_t,LITERAL_rest)
                _t = _t.getNextSibling()
                a=self.singleFunctionArg(_t)
                _t = self._retTree
                value = self.chunk.rest(a)
            elif la1 and la1 in [LITERAL_last]:
                pass
                tmp13_AST_in = _t
                self.match(_t,LITERAL_last)
                _t = _t.getNextSibling()
                a=self.singleFunctionArg(_t)
                _t = self._retTree
                value = self.chunk.last(a)
            elif la1 and la1 in [LITERAL_length]:
                pass
                tmp14_AST_in = _t
                self.match(_t,LITERAL_length)
                _t = _t.getNextSibling()
                a=self.singleFunctionArg(_t)
                _t = self._retTree
                value = self.chunk.length(a)
            elif la1 and la1 in [LITERAL_strip]:
                pass
                tmp15_AST_in = _t
                self.match(_t,LITERAL_strip)
                _t = _t.getNextSibling()
                a=self.singleFunctionArg(_t)
                _t = self._retTree
                value = self.chunk.strip(a)
            elif la1 and la1 in [LITERAL_trunc]:
                pass
                tmp16_AST_in = _t
                self.match(_t,LITERAL_trunc)
                _t = _t.getNextSibling()
                a=self.singleFunctionArg(_t)
                _t = self._retTree
                value = self.chunk.trunc(a)
            else:
                    raise antlr.NoViableAltException(_t)
                
            _t = _t21
            _t = _t.getNextSibling()
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return value
    

    ###/** create a new list of expressions as a new multi-value attribute */
    def list(self, _t):    
        value=None
        
        list_AST_in = None
        if _t != antlr.ASTNULL:
            list_AST_in = _t
        e = None
        elements = []
        value = CatList(elements)
        try:      ## for error handling
            if not _t:
                _t = antlr.ASTNULL
            la1 = _t.getType()
            if False:
                pass
            elif la1 and la1 in [LIST]:
                pass
                _t6 = _t
                tmp17_AST_in = _t
                self.match(_t,LIST)
                _t = _t.getFirstChild()
                _cnt8= 0
                while True:
                    if not _t:
                        _t = antlr.ASTNULL
                    if (_tokenSet_0.member(_t.getType())):
                        pass
                        e=self.expr(_t)
                        _t = self._retTree
                        if e:
                           from stringtemplate3.language.ASTExpr import convertAnythingToList
                           e = convertAnythingToList(e)
                           elements.append(e)
                    else:
                        break
                    
                    _cnt8 += 1
                if _cnt8 < 1:
                    raise antlr.NoViableAltException(_t)
                _t = _t6
                _t = _t.getNextSibling()
            elif la1 and la1 in [NOTHING]:
                pass
                tmp18_AST_in = _t
                self.match(_t,NOTHING)
                _t = _t.getNextSibling()
                nullSingleton = [None]
                element.append(nullSingleton)
            else:
                    raise antlr.NoViableAltException(_t)
                
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return value
    
    def template(self, _t,
        templatesToApply
    ):    
        
        template_AST_in = None
        if _t != antlr.ASTNULL:
            template_AST_in = _t
        t = None
        args = None
        anon = None
        args2 = None
        argumentContext = {}
        n = None
        try:      ## for error handling
            pass
            _t26 = _t
            tmp19_AST_in = _t
            self.match(_t,TEMPLATE)
            _t = _t.getFirstChild()
            if not _t:
                _t = antlr.ASTNULL
            la1 = _t.getType()
            if False:
                pass
            elif la1 and la1 in [ID]:
                pass
                t = _t
                self.match(_t,ID)
                _t = _t.getNextSibling()
                args = _t
                if not _t:
                    raise antlr.MismatchedTokenException()
                _t = _t.getNextSibling()
                templateName = t.getText()
                group = self.this.group
                embedded = group.getEmbeddedInstanceOf(
                      templateName,
                      self.this
                  )
                if embedded:
                   embedded.argumentsAST = args
                   templatesToApply.append(embedded)
            elif la1 and la1 in [ANONYMOUS_TEMPLATE]:
                pass
                anon = _t
                self.match(_t,ANONYMOUS_TEMPLATE)
                _t = _t.getNextSibling()
                anonymous = anon.getStringTemplate()
                # to properly see overridden templates, always set
                # anonymous' group to be self's group
                anonymous.group = self.this.group
                templatesToApply.append(anonymous)
            elif la1 and la1 in [VALUE]:
                pass
                _t28 = _t
                tmp20_AST_in = _t
                self.match(_t,VALUE)
                _t = _t.getFirstChild()
                n=self.expr(_t)
                _t = self._retTree
                args2 = _t
                if not _t:
                    raise antlr.MismatchedTokenException()
                _t = _t.getNextSibling()
                embedded = None
                if n:
                   templateName = str(n)
                   group = self.this.group
                   embedded = group.getEmbeddedInstanceOf(
                       templateName,
                       self.this
                       )
                   if embedded:
                       embedded.argumentsAST = args2
                       templatesToApply.append(embedded)
                _t = _t28
                _t = _t.getNextSibling()
            else:
                    raise antlr.NoViableAltException(_t)
                
            _t = _t26
            _t = _t.getNextSibling()
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
    
    def singleFunctionArg(self, _t):    
        value = None
        
        singleFunctionArg_AST_in = None
        if _t != antlr.ASTNULL:
            singleFunctionArg_AST_in = _t
        try:      ## for error handling
            pass
            _t24 = _t
            tmp21_AST_in = _t
            self.match(_t,SINGLEVALUEARG)
            _t = _t.getFirstChild()
            value=self.expr(_t)
            _t = self._retTree
            _t = _t24
            _t = _t.getNextSibling()
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return value
    
    def ifCondition(self, _t):    
        value = False
        
        ifCondition_AST_in = None
        if _t != antlr.ASTNULL:
            ifCondition_AST_in = _t
        a = None
        try:      ## for error handling
            if not _t:
                _t = antlr.ASTNULL
            la1 = _t.getType()
            if False:
                pass
            elif la1 and la1 in [APPLY,MULTI_APPLY,INCLUDE,VALUE,FUNCTION,LIST,NOTHING,ID,PLUS,DOT,ANONYMOUS_TEMPLATE,STRING,INT]:
                pass
                a=self.ifAtom(_t)
                _t = self._retTree
                value = self.chunk.testAttributeTrue(a)
            elif la1 and la1 in [NOT]:
                pass
                _t30 = _t
                tmp22_AST_in = _t
                self.match(_t,NOT)
                _t = _t.getFirstChild()
                a=self.ifAtom(_t)
                _t = self._retTree
                _t = _t30
                _t = _t.getNextSibling()
                value = not self.chunk.testAttributeTrue(a)
            else:
                    raise antlr.NoViableAltException(_t)
                
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return value
    
    def ifAtom(self, _t):    
        value = None
        
        ifAtom_AST_in = None
        if _t != antlr.ASTNULL:
            ifAtom_AST_in = _t
        try:      ## for error handling
            pass
            value=self.expr(_t)
            _t = self._retTree
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return value
    

    ###/** self is assumed to be the enclosing context as foo(x=y) must find y in
    ### *  the template that encloses the ref to foo(x=y).  We must pass in
    ### *  the embedded template (the one invoked) so we can check formal args
    ### *  in rawSetArgumentAttribute.
    ### */
    def argList(self, _t,
        embedded, initialContext
    ):    
        argumentContext = None
        
        argList_AST_in = None
        if _t != antlr.ASTNULL:
            argList_AST_in = _t
        argumentContext = initialContext
        if not argumentContext:
           argumentContext = {}
        try:      ## for error handling
            if not _t:
                _t = antlr.ASTNULL
            la1 = _t.getType()
            if False:
                pass
            elif la1 and la1 in [ARGS]:
                pass
                _t37 = _t
                tmp23_AST_in = _t
                self.match(_t,ARGS)
                _t = _t.getFirstChild()
                while True:
                    if not _t:
                        _t = antlr.ASTNULL
                    if (_t.getType()==ASSIGN or _t.getType()==DOTDOTDOT):
                        pass
                        self.argumentAssignment(_t, embedded, argumentContext)
                        _t = self._retTree
                    else:
                        break
                    
                _t = _t37
                _t = _t.getNextSibling()
            elif la1 and la1 in [SINGLEVALUEARG]:
                pass
                self.singleTemplateArg(_t, embedded, argumentContext)
                _t = self._retTree
            else:
                    raise antlr.NoViableAltException(_t)
                
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
        return argumentContext
    
    def argumentAssignment(self, _t,
        embedded, argumentContext
    ):    
        
        argumentAssignment_AST_in = None
        if _t != antlr.ASTNULL:
            argumentAssignment_AST_in = _t
        arg = None
        e = None
        try:      ## for error handling
            if not _t:
                _t = antlr.ASTNULL
            la1 = _t.getType()
            if False:
                pass
            elif la1 and la1 in [ASSIGN]:
                pass
                _t43 = _t
                tmp24_AST_in = _t
                self.match(_t,ASSIGN)
                _t = _t.getFirstChild()
                arg = _t
                self.match(_t,ID)
                _t = _t.getNextSibling()
                e=self.expr(_t)
                _t = self._retTree
                _t = _t43
                _t = _t.getNextSibling()
                if e:
                   self.this.rawSetArgumentAttribute(embedded, argumentContext, \
                       arg.getText(), e)
            elif la1 and la1 in [DOTDOTDOT]:
                pass
                tmp25_AST_in = _t
                self.match(_t,DOTDOTDOT)
                _t = _t.getNextSibling()
                embedded.passThroughAttributes = True
            else:
                    raise antlr.NoViableAltException(_t)
                
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
    
    def singleTemplateArg(self, _t,
        embedded, argumentContext
    ):    
        
        singleTemplateArg_AST_in = None
        if _t != antlr.ASTNULL:
            singleTemplateArg_AST_in = _t
        e = None
        try:      ## for error handling
            pass
            _t41 = _t
            tmp26_AST_in = _t
            self.match(_t,SINGLEVALUEARG)
            _t = _t.getFirstChild()
            e=self.expr(_t)
            _t = self._retTree
            _t = _t41
            _t = _t.getNextSibling()
            if e:
               soleArgName = None
               # find the sole defined formal argument for embedded
               error = False
               formalArgs = embedded.formalArguments
               if formalArgs:
                   argNames = formalArgs.keys()
                   if len(argNames) == 1:
                       soleArgName = argNames[0]
                       #sys.stderr.write("sole formal arg of " +
                       #                 embedded.getName() + " is " +
                       #                 soleArgName)
                   else:
                       error = True
            else:
               error = True
            if error:
               self.this.error("template " + embedded.name +
                               " must have exactly one formal arg in" +
                               " template context " +
                               self.this.enclosingInstanceStackString)
            else:
               self.this.rawSetArgumentAttribute(embedded, \
                   argumentContext, soleArgName, e)
        
        except antlr.RecognitionException as ex:
            self.reportError(ex)
            if _t:
                _t = _t.getNextSibling()
        
        self._retTree = _t
    

_tokenNames = [
    "<0>", 
    "EOF", 
    "<2>", 
    "NULL_TREE_LOOKAHEAD", 
    "APPLY", 
    "MULTI_APPLY", 
    "ARGS", 
    "INCLUDE", 
    "\"if\"", 
    "VALUE", 
    "TEMPLATE", 
    "FUNCTION", 
    "SINGLEVALUEARG", 
    "LIST", 
    "NOTHING", 
    "SEMI", 
    "LPAREN", 
    "RPAREN", 
    "\"elseif\"", 
    "COMMA", 
    "ID", 
    "ASSIGN", 
    "COLON", 
    "NOT", 
    "PLUS", 
    "DOT", 
    "\"first\"", 
    "\"rest\"", 
    "\"last\"", 
    "\"length\"", 
    "\"strip\"", 
    "\"trunc\"", 
    "\"super\"", 
    "ANONYMOUS_TEMPLATE", 
    "STRING", 
    "INT", 
    "LBRACK", 
    "RBRACK", 
    "DOTDOTDOT", 
    "TEMPLATE_ARGS", 
    "NESTED_ANONYMOUS_TEMPLATE", 
    "ESC_CHAR", 
    "WS", 
    "WS_CHAR"
]
    

### generate bit set
def mk_tokenSet_0(): 
    ### var1
    data = [ 60180949680, 0]
    return data
_tokenSet_0 = antlr.BitSet(mk_tokenSet_0())