Get rid of TaggedSymbols, just put tags/symbols inside Section1.Type or similar
authorNick Downing <downing.nick@gmail.com>
Sat, 28 Jul 2018 23:53:27 +0000 (09:53 +1000)
committerNick Downing <downing.nick@gmail.com>
Sun, 29 Jul 2018 01:43:51 +0000 (11:43 +1000)
ast.py

diff --git a/ast.py b/ast.py
index 2a04c33..f4a1b4f 100644 (file)
--- a/ast.py
+++ b/ast.py
@@ -1068,16 +1068,17 @@ class PYACC(element.Element):
         string_to_symbol,
         name_to_tag
       ):
-        self[1].set_code_props(
-          pyacc,
-          section,
-          character_to_symbol,
-          name_to_symbol,
-          string_to_symbol,
-          name_to_tag,
-          self._type,
-          self[0]
-        )
+        for i in self[1:]:
+          i.set_code_props(
+            pyacc,
+            section,
+            character_to_symbol,
+            name_to_symbol,
+            string_to_symbol,
+            name_to_tag,
+            self._type, # _type
+            self[0] # code
+          )
 
     class DefaultPrec(Item):
       # GENERATE ELEMENT() BEGIN
@@ -1134,6 +1135,27 @@ class PYACC(element.Element):
         self.repr_serialize(params)
         return 'ast.PYACC.Section1Or2.NTerm({0:s})'.format(', '.join(params))
       # GENERATE END
+      def post_process(
+        self,
+        pyacc,
+        section,
+        character_to_symbol,
+        name_to_symbol,
+        string_to_symbol,
+        name_to_tag
+      ):
+        _tag = -1
+        for i in self:
+          _tag = i.post_process(
+            pyacc,
+            section,
+            character_to_symbol,
+            name_to_symbol,
+            string_to_symbol,
+            name_to_tag,
+            _tag,
+            -1 # precedence
+          )
 
     class Precedence(Item):
       # GENERATE ELEMENT(int _type) BEGIN
@@ -1190,15 +1212,18 @@ class PYACC(element.Element):
         string_to_symbol,
         name_to_tag
       ):
-        self[0].post_process(
-          pyacc,
-          section,
-          character_to_symbol,
-          name_to_symbol,
-          string_to_symbol,
-          name_to_tag,
-          len(pyacc.associativities) # precedence
-        )
+        _tag = -1
+        for i in self:
+          _tag = i.post_process(
+            pyacc,
+            section,
+            character_to_symbol,
+            name_to_symbol,
+            string_to_symbol,
+            name_to_tag,
+            _tag,
+            len(pyacc.associativities) # precedence
+          )
         pyacc.associativities.append(self._type)
 
     class Start(Item):
@@ -1248,16 +1273,16 @@ class PYACC(element.Element):
         )
         pyacc.start_nonterminal = self[0].symbol
 
-    class TaggedSymbols(element.Element):
+    class Token(Item):
       # GENERATE ELEMENT() BEGIN
       def __init__(
         self,
-        tag = 'PYACC_Section1Or2_TaggedSymbols',
+        tag = 'PYACC_Section1Or2_Token',
         attrib = {},
         text = '',
         children = []
       ):
-        element.Element.__init__(
+        Item.__init__(
           self,
           tag,
           attrib,
@@ -1265,15 +1290,15 @@ class PYACC(element.Element):
           children
         )
       def copy(self, factory = None):
-        result = element.Element.copy(
+        result = Item.copy(
           self,
-          TaggedSymbols if factory is None else factory
+          Token if factory is None else factory
         )
         return result
       def __repr__(self):
         params = []
         self.repr_serialize(params)
-        return 'ast.PYACC.Section1Or2.TaggedSymbols({0:s})'.format(', '.join(params))
+        return 'ast.PYACC.Section1Or2.Token({0:s})'.format(', '.join(params))
       # GENERATE END
       def post_process(
         self,
@@ -1282,8 +1307,7 @@ class PYACC(element.Element):
         character_to_symbol,
         name_to_symbol,
         string_to_symbol,
-        name_to_tag,
-        precedence
+        name_to_tag
       ):
         _tag = -1
         for i in self:
@@ -1295,76 +1319,8 @@ class PYACC(element.Element):
             string_to_symbol,
             name_to_tag,
             _tag,
-            precedence
+            -1 # precedence
           )
-      def set_code_props(
-        self,
-        pyacc,
-        section,
-        character_to_symbol,
-        name_to_symbol,
-        string_to_symbol,
-        name_to_tag,
-        _type,
-        code
-      ):
-        for i in self:
-          i.set_code_props(
-            pyacc,
-            section,
-            character_to_symbol,
-            name_to_symbol,
-            string_to_symbol,
-            name_to_tag,
-            _type,
-            code
-          )
-
-    class Token(Item):
-      # GENERATE ELEMENT() BEGIN
-      def __init__(
-        self,
-        tag = 'PYACC_Section1Or2_Token',
-        attrib = {},
-        text = '',
-        children = []
-      ):
-        Item.__init__(
-          self,
-          tag,
-          attrib,
-          text,
-          children
-        )
-      def copy(self, factory = None):
-        result = Item.copy(
-          self,
-          Token if factory is None else factory
-        )
-        return result
-      def __repr__(self):
-        params = []
-        self.repr_serialize(params)
-        return 'ast.PYACC.Section1Or2.Token({0:s})'.format(', '.join(params))
-      # GENERATE END
-      def post_process(
-        self,
-        pyacc,
-        section,
-        character_to_symbol,
-        name_to_symbol,
-        string_to_symbol,
-        name_to_tag
-      ):
-        self[0].post_process(
-          pyacc,
-          section,
-          character_to_symbol,
-          name_to_symbol,
-          string_to_symbol,
-          name_to_tag,
-          -1 # precedence
-        )
 
     class Type(Item):
       # GENERATE ELEMENT() BEGIN
@@ -1402,15 +1358,18 @@ class PYACC(element.Element):
         string_to_symbol,
         name_to_tag
       ):
-        self[0].post_process(
-          pyacc,
-          section,
-          character_to_symbol,
-          name_to_symbol,
-          string_to_symbol,
-          name_to_tag,
-          -1 # precedence
-        )
+        _tag = -1
+        for i in self:
+          _tag = i.post_process(
+            pyacc,
+            section,
+            character_to_symbol,
+            name_to_symbol,
+            string_to_symbol,
+            name_to_tag,
+            _tag,
+            -1 # precedence
+          )
 
     class Union(Item):
       # GENERATE ELEMENT() BEGIN
@@ -1448,7 +1407,9 @@ class PYACC(element.Element):
         string_to_symbol,
         name_to_tag
       ):
+        assert len(pyacc.union_name) == 0 # fix this later
         pyacc.union_name = self[0].get_text()
+        assert pyacc.union_code is None # fix this later
         pyacc.union_code = self[1] 
 
     # GENERATE ELEMENT() BEGIN
@@ -3801,7 +3762,6 @@ tag_to_class = {
   'PYACC_Section1Or2_NTerm': PYACC.Section1Or2.NTerm,
   'PYACC_Section1Or2_Precedence': PYACC.Section1Or2.Precedence,
   'PYACC_Section1Or2_Start': PYACC.Section1Or2.Start,
-  'PYACC_Section1Or2_TaggedSymbols': PYACC.Section1Or2.TaggedSymbols,
   'PYACC_Section1Or2_Token': PYACC.Section1Or2.Token,
   'PYACC_Section1Or2_Type': PYACC.Section1Or2.Type,
   'PYACC_Section1Or2_Union': PYACC.Section1Or2.Union,