Add element groups into the AST and post processing, currently they're ignored
authorNick Downing <downing.nick@gmail.com>
Wed, 26 Sep 2018 12:10:56 +0000 (22:10 +1000)
committerNick Downing <downing.nick@gmail.com>
Wed, 26 Sep 2018 12:10:56 +0000 (22:10 +1000)
ast.py
tests_ast/cal_py.y

diff --git a/ast.py b/ast.py
index 23186af..71cf50e 100644 (file)
--- a/ast.py
+++ b/ast.py
@@ -759,6 +759,76 @@ class AST(element.Element):
         )
         return None
 
+    class GroupElement(Item):
+      # GENERATE ELEMENT() BEGIN
+      def __init__(
+        self,
+        tag = 'AST_Production_GroupElement',
+        attrib = {},
+        text = '',
+        children = []
+      ):
+        AST.Production.Item.__init__(
+          self,
+          tag,
+          attrib,
+          text,
+          children
+        )
+      def copy(self, factory = None):
+        result = AST.Production.Item.copy(
+          self,
+          GroupElement if factory is None else factory
+        )
+        return result
+      def __repr__(self):
+        params = []
+        self.repr_serialize(params)
+        return 'ast.AST.Production.GroupElement({0:s})'.format(', '.join(params))
+      # GENERATE END
+      def post_process(
+        self,
+        _ast,
+        section,
+        production,
+        character_to_symbol,
+        name_to_symbol,
+        string_to_symbol,
+        name_to_tag,
+        last_action
+      ):
+        for i in self[1:]:
+          last_action = i.post_process(
+            _ast,
+            section,
+            production,
+            character_to_symbol,
+            name_to_symbol,
+            string_to_symbol,
+            name_to_tag,
+            last_action
+          )
+        return last_action
+      def add_to_symbols(
+        self,
+        _ast,
+        production,
+        last_action,
+        _lr1,
+        symbols,
+        tag_names
+      ):
+        for i in self[1:]:
+          last_action = i.add_to_symbols(
+            _ast,
+            production,
+            last_action,
+            _lr1,
+            symbols,
+            tag_names
+          )
+        return last_action
     # GENERATE ELEMENT(int lhs_nonterminal, int n_symbols, int last_terminal, int precedence_terminal) BEGIN
     def __init__(
       self,
@@ -3707,6 +3777,7 @@ tag_to_class = {
   'AST_Production_Merge': AST.Production.Merge,
   'AST_Production_Prec': AST.Production.Prec,
   'AST_Production_SymbolRef': AST.Production.SymbolRef,
+  'AST_Production_GroupElement': AST.Production.GroupElement,
   'AST_Section1Or2': AST.Section1Or2,
   'AST_Section1Or2_Code': AST.Section1Or2.Code,
   'AST_Section1Or2_CodeProps': AST.Section1Or2.CodeProps,
index d62d9ef..9c29550 100644 (file)
@@ -20,7 +20,7 @@ S : S E '\n' {
   yyerrok()
 }
   ;
-E : E '+' E {
+E : (?E{ast.AST.Add}E '+' E) {
     yy_element_stack[-5:] = [
       element.Element(
         'root',