Update to pitree.git commit 350e5a9 (first cut)
authorNick Downing <nick@ndcode.org>
Tue, 29 Jan 2019 04:39:24 +0000 (15:39 +1100)
committerNick Downing <nick@ndcode.org>
Tue, 29 Jan 2019 04:39:24 +0000 (15:39 +1100)
generate_py.py
parse-gram.y
piyacc.t
scan-gram.l
skel_lex_yy.py
tests_ast/cal.py
tests_ast/cal_py.t

index 635f212..90dfe38 100644 (file)
@@ -124,8 +124,8 @@ YYDEBUG = {0:s}
 YYERROR_VERBOSE = {1:s}
 {2:s}{3:s}{4:s}# GENERATE END
 '''.format(
-              'True' if _ast[0].debug else 'False',
-              'True' if _ast[0].error_verbose else 'False',
+              'True' if _ast.children[0].debug else 'False',
+              'True' if _ast.children[0].error_verbose else 'False',
               ''.join(
                 [
                   '''def yy_action{0:d}():
@@ -232,7 +232,7 @@ YYERROR_VERBOSE = {1:s}
             '''# GENERATE SECTION3 BEGIN
 {0:s}# GENERATE END
 '''.format(
-              '' if len(_ast) < 3 else ast_text_to_python(_ast[2], '')
+              '' if len(_ast.children) < 3 else ast_text_to_python(_ast.children[2], '')
             )
           )
         else:
index e1d1424..a32e4b4 100644 (file)
@@ -276,11 +276,11 @@ prologue_declaration
       lex_yy_code.unput($2)
       lex_yy_code.sc_context = lex_yy_code.SC_SYMBOL_ACTION # CODE_PROPS_SYMBOL_ACTION
       lex_yy_code.yylex(t_def.AST.Text)
-      assert isinstance(yy_element_stack[-1][0], t_def.AST.Section1.InitialAction)
-      assert isinstance(yy_element_stack[-1][0][0], t_def.AST.Text)
-      tail = element.get_text(yy_element_stack[-1][0], 1)
-      yy_element_stack[-1][0][0] = lex_yy_code.yy_element_space
-      element.set_text(yy_element_stack[-1][0], 1, tail)
+      assert isinstance(yy_element_stack[-1].children[0], t_def.AST.Section1.InitialAction)
+      assert isinstance(yy_element_stack[-1].children[0].children[0], t_def.AST.Text)
+      tail = element.get_text(yy_element_stack[-1].children[0], 1)
+      yy_element_stack[-1].children[0].children[0] = lex_yy_code.yy_element_space
+      element.set_text(yy_element_stack[-1].children[0], 1, tail)
     }
   | %space (?E{t_def.AST.Section1.Language}"%language" STRING)
   | %space (?E{t_def.AST.Section1.NamePrefix}"%name-prefix" STRING)
@@ -318,11 +318,11 @@ grammar_declaration
       lex_yy_code.unput($2)
       lex_yy_code.sc_context = lex_yy_code.SC_SYMBOL_ACTION # CODE_PROPS_SYMBOL_ACTION
       lex_yy_code.yylex(t_def.AST.Text)
-      assert isinstance(yy_element_stack[-1][0], t_def.AST.Section1Or2.CodeProps)
-      assert isinstance(yy_element_stack[-1][0][0], t_def.AST.Text)
-      tail = element.get_text(yy_element_stack[-1][0], 1)
-      yy_element_stack[-1][0][0] = lex_yy_code.yy_element_space
-      element.set_text(yy_element_stack[-1][0], 1, tail)
+      assert isinstance(yy_element_stack[-1].children[0], t_def.AST.Section1Or2.CodeProps)
+      assert isinstance(yy_element_stack[-1].children[0].children[0], t_def.AST.Text)
+      tail = element.get_text(yy_element_stack[-1].children[0], 1)
+      yy_element_stack[-1].children[0].children[0] = lex_yy_code.yy_element_space
+      element.set_text(yy_element_stack[-1].children[0], 1, tail)
     }
   | %space (?E{t_def.AST.Section1Or2.DefaultPrec, value = True}"%default-prec")
   | %space (?E{t_def.AST.Section1Or2.DefaultPrec}"%no-default-prec")
@@ -330,46 +330,46 @@ grammar_declaration
   | %space (?E{t_def.AST.Section1Or2.Code}"%code" (?E{t_def.AST.ID}) %space (?E{t_def.AST.BracedCode}"{...}") )
     {
       # most egregious (leftover from when we used to run code scanner on it):
-      assert isinstance(yy_element_stack[-1][0], t_def.AST.Section1Or2.Code)
-      assert isinstance(yy_element_stack[-1][0][1], t_def.AST.BracedCode)
-      assert isinstance(yy_element_stack[-1][0][1][0], t_def.AST.Text)
+      assert isinstance(yy_element_stack[-1].children[0], t_def.AST.Section1Or2.Code)
+      assert isinstance(yy_element_stack[-1].children[0].children[1], t_def.AST.BracedCode)
+      assert isinstance(yy_element_stack[-1].children[0].children[1].children[0], t_def.AST.Text)
       element.set_text(
-        yy_element_stack[-1][0][1][0],
+        yy_element_stack[-1].children[0].children[1].children[0],
         0,
-        element.get_text(yy_element_stack[-1][0][1][0], 0)[1:-1] # remove { }
+        element.get_text(yy_element_stack[-1].children[0].children[1].children[0], 0)[1:-1] # remove { }
       )
       element.set_text(
-        yy_element_stack[-1][0][1],
+        yy_element_stack[-1].children[0].children[1],
         0,
-        element.get_text(yy_element_stack[-1][0][1], 0) + '{'
+        element.get_text(yy_element_stack[-1].children[0].children[1], 0) + '{'
       )
       element.set_text(
-        yy_element_stack[-1][0][1],
+        yy_element_stack[-1].children[0].children[1],
         1,
-        '}' + element.get_text(yy_element_stack[-1][0][1], 1)
+        '}' + element.get_text(yy_element_stack[-1].children[0].children[1], 1)
       )
     }
   /* the BracedCode should be removed altogether, put here for compatibility */
   | %space (?E{t_def.AST.Section1Or2.Code}"%code" ID %space (?E{t_def.AST.BracedCode}"{...}") )
     {
       # most egregious (leftover from when we used to run code scanner on it):
-      assert isinstance(yy_element_stack[-1][0], t_def.AST.Section1Or2.Code)
-      assert isinstance(yy_element_stack[-1][0][1], t_def.AST.BracedCode)
-      assert isinstance(yy_element_stack[-1][0][1][0], t_def.AST.Text)
+      assert isinstance(yy_element_stack[-1].children[0], t_def.AST.Section1Or2.Code)
+      assert isinstance(yy_element_stack[-1].children[0].children[1], t_def.AST.BracedCode)
+      assert isinstance(yy_element_stack[-1].children[0].children[1].children[0], t_def.AST.Text)
       element.set_text(
-        yy_element_stack[-1][0][1][0],
+        yy_element_stack[-1].children[0].children[1].children[0],
         0,
-        element.get_text(yy_element_stack[-1][0][1][0], 0)[1:-1] # remove { }
+        element.get_text(yy_element_stack[-1].children[0].children[1].children[0], 0)[1:-1] # remove { }
       )
       element.set_text(
-        yy_element_stack[-1][0][1],
+        yy_element_stack[-1].children[0].children[1],
         0,
-        element.get_text(yy_element_stack[-1][0][1], 0) + '{'
+        element.get_text(yy_element_stack[-1].children[0].children[1], 0) + '{'
       )
       element.set_text(
-        yy_element_stack[-1][0][1],
+        yy_element_stack[-1].children[0].children[1],
         1,
-        '}' + element.get_text(yy_element_stack[-1][0][1], 1)
+        '}' + element.get_text(yy_element_stack[-1].children[0].children[1], 1)
       )
     }
   ;
@@ -409,23 +409,23 @@ grammar_declaration
   : %space (?E{t_def.AST.Section1Or2.Union}"%union" union_name %space (?E{t_def.AST.BracedCode}"{...}") )
     {
       # most egregious (leftover from when we used to run code scanner on it):
-      assert isinstance(yy_element_stack[-1][0], t_def.AST.Section1Or2.Union)
-      assert isinstance(yy_element_stack[-1][0][1], t_def.AST.BracedCode)
-      assert isinstance(yy_element_stack[-1][0][1][0], t_def.AST.Text)
+      assert isinstance(yy_element_stack[-1].children[0], t_def.AST.Section1Or2.Union)
+      assert isinstance(yy_element_stack[-1].children[0].children[1], t_def.AST.BracedCode)
+      assert isinstance(yy_element_stack[-1].children[0].children[1].children[0], t_def.AST.Text)
       element.set_text(
-        yy_element_stack[-1][0][1][0],
+        yy_element_stack[-1].children[0].children[1].children[0],
         0,
-        element.get_text(yy_element_stack[-1][0][1][0], 0)[1:-1] # remove { }
+        element.get_text(yy_element_stack[-1].children[0].children[1].children[0], 0)[1:-1] # remove { }
       )
       element.set_text(
-        yy_element_stack[-1][0][1],
+        yy_element_stack[-1].children[0].children[1],
         0,
-        element.get_text(yy_element_stack[-1][0][1], 0) + '{'
+        element.get_text(yy_element_stack[-1].children[0].children[1], 0) + '{'
       )
       element.set_text(
-        yy_element_stack[-1][0][1],
+        yy_element_stack[-1].children[0].children[1],
         1,
-        '}' + element.get_text(yy_element_stack[-1][0][1], 1)
+        '}' + element.get_text(yy_element_stack[-1].children[0].children[1], 1)
       )
     }
   ;
@@ -566,11 +566,11 @@ rhs
       lex_yy_code.unput($2)
       lex_yy_code.sc_context = lex_yy_code.SC_RULE_ACTION # CODE_PROPS_RULE_ACTION
       lex_yy_code.yylex(t_def.AST.Text)
-      assert isinstance(yy_element_stack[-1][0], t_def.AST.Production.Action)
-      assert isinstance(yy_element_stack[-1][0][0], t_def.AST.Text)
-      tail = element.get_text(yy_element_stack[-1][0], 1)
-      yy_element_stack[-1][0][0] = lex_yy_code.yy_element_space
-      element.set_text(yy_element_stack[-1][0], 1, tail)
+      assert isinstance(yy_element_stack[-1].children[0], t_def.AST.Production.Action)
+      assert isinstance(yy_element_stack[-1].children[0].children[0], t_def.AST.Text)
+      tail = element.get_text(yy_element_stack[-1].children[0], 1)
+      yy_element_stack[-1].children[0].children[0] = lex_yy_code.yy_element_space
+      element.set_text(yy_element_stack[-1].children[0], 1, tail)
     }
   | rhs "%?{...}"
     {
@@ -590,11 +590,11 @@ rhs
       lex_yy_code.unput($2[4:-1])
       lex_yy_code.sc_context = lex_yy_code.SC_RULE_ACTION # CODE_PROPS_RULE_ACTION
       lex_yy_code.yylex(t_def.AST.Text)
-      assert isinstance(yy_element_stack[-1][0], t_def.AST.Production.GroupElement)
-      assert isinstance(yy_element_stack[-1][0][0], t_def.AST.Text)
-      tail = element.get_text(yy_element_stack[-1][0], 1)
-      yy_element_stack[-1][0][0] = lex_yy_code.yy_element_space
-      element.set_text(yy_element_stack[-1][0], 1, tail)
+      assert isinstance(yy_element_stack[-1].children[0], t_def.AST.Production.GroupElement)
+      assert isinstance(yy_element_stack[-1].children[0].children[0], t_def.AST.Text)
+      tail = element.get_text(yy_element_stack[-1].children[0], 1)
+      yy_element_stack[-1].children[0].children[0] = lex_yy_code.yy_element_space
+      element.set_text(yy_element_stack[-1].children[0], 1, tail)
     }
   /* Nick added %space */
   | rhs %space (?E{t_def.AST.Production.Space}"%space")
index 978568b..98608bc 100644 (file)
--- a/piyacc.t
+++ b/piyacc.t
@@ -250,7 +250,7 @@ def post_process(
   last_grouped_pos
 ):
   assert production.precedence_terminal == -1
-  _, production.precedence_terminal = self[0].post_process(
+  _, production.precedence_terminal = self.children[0].post_process(
     _ast,
     section,
     character_to_symbol,
@@ -278,7 +278,7 @@ def post_process(
 ):
   _ast.n_productions += int(last_action) # midrule action production
   production.n_symbols += int(last_action) + 1 # midrule action symbol
-  _, self.symbol = self[0].post_process(
+  _, self.symbol = self.children[0].post_process(
     _ast,
     section,
     character_to_symbol,
@@ -307,7 +307,7 @@ def post_process(
   has_space,
   last_grouped_pos
 ):
-  for i in self[1:]:
+  for i in self.children[1:]:
     last_action, has_space, last_grouped_pos = i.post_process(
       _ast,
       section,
@@ -357,7 +357,7 @@ def post_process(
   last_action = False
   has_space = False
   last_grouped_pos = 0
-  for i in self:
+  for i in self.children:
     last_action, has_space, last_grouped_pos = i.post_process(
       _ast,
       section,
@@ -393,17 +393,17 @@ def post_process(
   string_to_symbol,
   name_to_tag
 ):
-  name = self[0].get_text()
+  name = self.children[0].get_text()
   if len(name) == 0: # do the same as Section1.Prologue
     (
       _ast.before_union_text
     if len(_ast.union_text) == 0 else
       _ast.after_union_text
-    ).append(self[1][0])
+    ).append(self.children[1].children[0])
   elif name == 'top':
-    _ast.top_text.append(self[1][0])
+    _ast.top_text.append(self.children[1].children[0])
   elif name == 'requires':
-    _ast.requires_text.append(self[1][0])
+    _ast.requires_text.append(self.children[1].children[0])
   else:
     assert False
 @method(AST.Section1Or2.CodeProps)
@@ -416,7 +416,7 @@ def post_process(
   string_to_symbol,
   name_to_tag
 ):
-  for i in self[1:]:
+  for i in self.children[1:]:
     _, j = i.post_process(
       _ast,
       section,
@@ -430,7 +430,7 @@ def post_process(
     )
     tag_or_symbol = _ast.symbols[j] if j >= 0 else _ast.tags[~j]
     assert tag_or_symbol.code_props[self._type] is None
-    tag_or_symbol.code_props[self._type] = self[0]
+    tag_or_symbol.code_props[self._type] = self.children[0]
 @method(AST.Section1Or2.NTerm)
 def post_process(
   self,
@@ -442,7 +442,7 @@ def post_process(
   name_to_tag
 ):
   _tag = -1
-  for i in self:
+  for i in self.children:
     _tag, _ = i.post_process(
       _ast,
       section,
@@ -465,7 +465,7 @@ def post_process(
   name_to_tag
 ):
   _tag = -1
-  for i in self:
+  for i in self.children:
     _tag, _ = i.post_process(
       _ast,
       section,
@@ -488,7 +488,7 @@ def post_process(
   string_to_symbol,
   name_to_tag
 ):
-  _, _ast.start_nonterminal = self[0].post_process(
+  _, _ast.start_nonterminal = self.children[0].post_process(
     _ast,
     section,
     character_to_symbol,
@@ -510,7 +510,7 @@ def post_process(
   name_to_tag
 ):
   _tag = -1
-  for i in self:
+  for i in self.children:
     _tag, _ = i.post_process(
       _ast,
       section,
@@ -533,7 +533,7 @@ def post_process(
   name_to_tag
 ):
   _tag = -1
-  for i in self:
+  for i in self.children:
     _tag, _ = i.post_process(
       _ast,
       section,
@@ -555,11 +555,11 @@ def post_process(
   string_to_symbol,
   name_to_tag
 ):
-  name = self[0].get_text()
+  name = self.children[0].get_text()
   if len(name):
     assert len(_ast.union_name) == 0
     _ast.union_name = name
-  _ast.union_text.append(self[1][0])
+  _ast.union_text.append(self.children[1].children[0])
 @method(AST.Section1Or2)
 def post_process(
   self,
@@ -569,7 +569,7 @@ def post_process(
   string_to_symbol,
   name_to_tag
 ):
-  for i in self:
+  for i in self.children:
     i.post_process(
       _ast,
       self,
@@ -599,14 +599,14 @@ def post_process(
   string_to_symbol,
   name_to_tag
 ):
-  name = self[0].get_text()
+  name = self.children[0].get_text()
   value = (
     ''
-  if len(self) < 2 else
+  if len(self.children) < 2 else
     (
-      self[1]
-    if isinstance(self[1], AST.ID) else
-      self[1][0] # String or BracedCode
+      self.children[1]
+    if isinstance(self.children[1], AST.ID) else
+      self.children[1].children[0] # String or BracedCode
     ).get_text()
   )
   if name == 'api.prefix':
@@ -656,7 +656,7 @@ def post_process(
   string_to_symbol,
   name_to_tag
 ):
-  assert len(self) == 0
+  assert len(self.children) == 0
   section.defines = True
 @method(AST.Section1.ErrorVerbose)
 def post_process(
@@ -690,8 +690,8 @@ def post_process(
   string_to_symbol,
   name_to_tag
 ):
-  assert isinstance(self[0], AST.Text) # temporary
-  _ast.initial_action_text.append(self[0])
+  assert isinstance(self.children[0], AST.Text) # temporary
+  _ast.initial_action_text.append(self.children[0])
 @method(AST.Section1.Locations)
 def post_process(
   self,
@@ -713,7 +713,7 @@ def post_process(
   string_to_symbol,
   name_to_tag
 ):
-  section.name_prefix = self[0][0].get_text()
+  section.name_prefix = self.children[0].children[0].get_text()
 @method(AST.Section1.Prologue)
 def post_process(
   self,
@@ -728,7 +728,7 @@ def post_process(
     _ast.before_union_text
   if len(_ast.union_text) == 0 else
     _ast.after_union_text
-  ).append(self[0])
+  ).append(self.children[0])
 @method(AST.Section1.PureParser)
 def post_process(
   self,
@@ -808,7 +808,7 @@ def post_process(
   string_to_symbol,
   name_to_tag
 ):
-  _, lhs_nonterminal = self[0].post_process(
+  _, lhs_nonterminal = self.children[0].post_process(
     _ast,
     section,
     character_to_symbol,
@@ -821,7 +821,7 @@ def post_process(
   )
   if _ast.first_nonterminal == -1:
     _ast.first_nonterminal = lhs_nonterminal
-  for i in self[1:]:
+  for i in self.children[1:]:
     i.post_process(
       _ast,
       section,
@@ -858,7 +858,7 @@ def post_process(
   _tag,
   precedence
 ):
-  name = self[0].get_text()
+  name = self.children[0].get_text()
   if name in name_to_tag:
     _tag = name_to_tag[name]
   else:
@@ -881,8 +881,8 @@ def post_process(
   _tag,
   precedence
 ):
-  if isinstance(self[0], AST.Char):
-    character = ord(self[0][0].get_text())
+  if isinstance(self.children[0], AST.Char):
+    character = ord(self.children[0].children[0].get_text())
     assert character != 0 # would conflict with YYEOF
     if character in character_to_symbol:
       symbol = character_to_symbol[character]
@@ -896,8 +896,8 @@ def post_process(
           character_set = [character, character + 1]
         )
       )
-  elif isinstance(self[0], AST.ID):
-    name = self[0].get_text()
+  elif isinstance(self.children[0], AST.ID):
+    name = self.children[0].get_text()
     if name in name_to_symbol:
       symbol = name_to_symbol[name]
       assert self.user_token != 0
@@ -924,8 +924,8 @@ def post_process(
           character_set = []
         )
       )
-  elif isinstance(self[0], AST.String):
-    string = self[0][0].get_text()
+  elif isinstance(self.children[0], AST.String):
+    string = self.children[0].children[0].get_text()
     symbol = string_to_symbol[string] # must already exist
   else:
     assert False
@@ -935,8 +935,8 @@ def post_process(
     _ast.symbols[symbol].character_set = (
       [self.user_token, self.user_token + 1]
     )
-  if len(self) >= 2:
-    string = self[1][0].get_text()
+  if len(self.children) >= 2:
+    string = self.children[1].children[0].get_text()
     assert string not in string_to_symbol
     string_to_symbol[string] = symbol
   # insert information from the calling contexxt
@@ -1006,14 +1006,14 @@ def post_process(self):
   # perform the semantic analysis pass
   self.first_nonterminal = -1
   self.start_nonterminal = -1
-  self[0].post_process(
+  self.children[0].post_process(
     self,
     character_to_symbol,
     name_to_symbol,
     string_to_symbol,
     name_to_tag
   )
-  self[1].post_process(
+  self.children[1].post_process(
     self,
     character_to_symbol,
     name_to_symbol,
@@ -1073,7 +1073,7 @@ def add_to_symbols(
         (False, [], True, 0, last_action)
       )
     )
-  for i in self[0]:
+  for i in self.children[0].children:
     if isinstance(i, AST.Text.StackLocation):
       i.offset = -len(symbols)
     elif isinstance(i, AST.Text.StackReference):
@@ -1084,7 +1084,7 @@ def add_to_symbols(
       ):
         i.tag_name = tag_names[i.index - 1]
       i.offset = -len(symbols)
-  return self[0]
+  return self.children[0]
 @method(AST.Production.SymbolRef)
 def add_to_symbols(
   self,
@@ -1131,7 +1131,7 @@ def add_to_symbols(
   symbols,
   tag_names
 ):
-  for i in self[0]:
+  for i in self.children[0].children:
     if isinstance(i, AST.Text.StackLocation):
       i.offset = -production.n_symbols
     elif isinstance(i, AST.Text.StackReference):
@@ -1142,7 +1142,7 @@ def add_to_symbols(
       ):
         i.tag_name = tag_names[i.index - 1]
       i.offset = -production.n_symbols
-  for i in self[1:]:
+  for i in self.children[1:]:
     last_action = i.add_to_symbols(
       _ast,
       production,
@@ -1198,7 +1198,7 @@ def add_to_groups(
   last_grouped_pos
 ):
   pos1 = pos
-  for i in self[:0:-1]:
+  for i in self.children[:0:-1]:
     first_action, pos, last_grouped_pos = i.add_to_groups(
       _ast,
       production,
@@ -1207,7 +1207,7 @@ def add_to_groups(
       pos,
       last_grouped_pos
     )
-  groups.append((pos, pos1, self[0]))
+  groups.append((pos, pos1, self.children[0]))
   pos = pos1 - 1
   return first_action, pos, pos
 @method(AST.Production.Space)
@@ -1228,7 +1228,7 @@ def add_to_lr1(self, _ast, _lr1):
   last_action = None
   symbols = []
   tag_names = []
-  for i in self:
+  for i in self.children:
     last_action = i.add_to_symbols(
       _ast,
       self,
@@ -1239,7 +1239,7 @@ def add_to_lr1(self, _ast, _lr1):
     )
   assert len(symbols) == self.n_symbols
   if last_action is not None:
-    for i in last_action:
+    for i in last_action.children:
       if (
         isinstance(i, AST.Text.ValueReference) and
         len(i.tag_name) == 0
@@ -1255,7 +1255,7 @@ def add_to_lr1(self, _ast, _lr1):
   first_action = False # have not had first action yet
   pos = int(self.has_space) - int(self.take_space_right)
   last_grouped_pos = pos # says last position where a group has started
-  for i in self[::-1]:
+  for i in self.children[::-1]:
     first_action, pos, last_grouped_pos = i.add_to_groups(
       _ast,
       self,
@@ -1345,10 +1345,10 @@ def get_text(self, python = False):
   return ''.join(
     [
       j
-      for i in range(len(self))
-      for j in [element.get_text(self, i), self[i].get_text(python)]
+      for i in range(len(self.children))
+      for j in [element.get_text(self, i), self.children[i].get_text(python)]
     ] +
-    [element.get_text(self, len(self))]
+    [element.get_text(self, len(self.children))]
   )
 del get_text
 
index 66c8b8d..89abf70 100644 (file)
@@ -436,8 +436,9 @@ eqopt    ([[:space:]]*=)?
 
     # total kludge: put back all whitespace/comments after the ID, and rescan
     # (this will mess up the position tracking, need to revisit and fix later)
-    unput(element.get_text(yy_element_space, len(yy_element_space)))
-    element.set_text(yy_element_space, len(yy_element_space), '')
+    assert len(yy_element_space.text) == len(yy_element_space.children) + 1
+    unput(yy_element_space.text[-1])
+    yy_element_space.text[-1] = ''
 
     markup_pop_token() # element.Element
     BEGIN(SC_RETURN_BRACKETED_ID if bracketed_id_str else INITIAL)
@@ -1001,41 +1002,41 @@ def unexpected_newline(start, token_end):
 # try to use more complex regular expressions to match all in one go:
 
 def markup_flush(n):
-  assert len(yy_element_space.text) == len(yy_element_space) + 1
-  assert len(yy_element_token.text) == len(yy_element_token) + 1
+  assert len(yy_element_space.text) == len(yy_element_space.children) + 1
+  assert len(yy_element_token.text) == len(yy_element_token.children) + 1
   yy_element_space.text[-1] += yy_element_token.text[0][:n]
   yy_element_token.text[0] = yy_element_token.text[0][n:]
 
 def markup_yyless(n):
-  assert len(yy_element_space.text) == len(yy_element_space) + 1
-  assert len(yy_element_token.text) == len(yy_element_token) + 1
+  assert len(yy_element_space.text) == len(yy_element_space.children) + 1
+  assert len(yy_element_token.text) == len(yy_element_token.children) + 1
   yyless(n)
   yy_element_token.text[0] = yy_element_token.text[0][:n]
 
 def markup_push(factory, *args, **kwargs):
   global yy_element_space
-  assert len(yy_element_space.text) == len(yy_element_space) + 1
-  assert len(yy_element_token.text) == len(yy_element_token) + 1
+  assert len(yy_element_space.text) == len(yy_element_space.children) + 1
+  assert len(yy_element_token.text) == len(yy_element_token.children) + 1
   markup_stack.append(yy_element_space)
   yy_element_space = factory(*args, **kwargs)
 
 def markup_pop():
   global yy_element_space
-  assert len(yy_element_space.text) == len(yy_element_space) + 1
-  assert len(yy_element_token.text) == len(yy_element_token) + 1
+  assert len(yy_element_space.text) == len(yy_element_space.children) + 1
+  assert len(yy_element_token.text) == len(yy_element_token.children) + 1
   _element = yy_element_space
   yy_element_space = markup_stack.pop()
-  yy_element_space.append(_element)
+  yy_element_space.children.append(_element)
   yy_element_space.text.append('')
 
 def markup_pop_token():
   global yy_element_space, yy_element_token
 
   # append yy_element_token contents onto yy_element_space
-  assert len(yy_element_space.text) == len(yy_element_space) + 1
-  assert len(yy_element_token.text) == len(yy_element_token) + 1
+  assert len(yy_element_space.text) == len(yy_element_space.children) + 1
+  assert len(yy_element_token.text) == len(yy_element_token.children) + 1
   yy_element_space.text[-1] += yy_element_token.text[0]
-  yy_element_space.extend(yy_element_token[:])
+  yy_element_space.children.extend(yy_element_token.children)
   yy_element_space.text.extend(yy_element_token.text[1:])
 
   # exchange, so that space is now prepended onto token
index 4ec8675..2c19629 100644 (file)
@@ -136,7 +136,7 @@ def yy_group_element(pos0, pos1, stack, factory, *args, **kwargs):
   del _element.text[:]
   for pos2, pos3, i in reversed(stack):
     _element.text.append(yy_group_text[pos0:pos2])
-    _element.append(i)
+    _element.children.append(i)
     pos0 = pos3
   _element.text.append(yy_group_text[pos0:pos1])
   return _element
@@ -343,14 +343,14 @@ def yylex(factory = element.Element, *args, **kwargs):
       raise Exception('scanner jammed')
 
     # append yy_element_token contents onto yy_element_space
-    assert len(yy_element_space.text) == len(yy_element_space) + 1
-    assert len(yy_element_token.text) == len(yy_element_token) + 1
+    assert len(yy_element_space.text) == len(yy_element_space.children) + 1
+    assert len(yy_element_token.text) == len(yy_element_token.children) + 1
     yy_element_space.text[-1] += yy_element_token.text[0]
-    yy_element_space.extend(yy_element_token[:])
+    yy_element_space.children.extend(yy_element_token.children)
     yy_element_space.text.extend(yy_element_token.text[1:])
  
     # clear yy_element_token for next yytext or EOF action
     del yy_element_token.text[1:]
-    del yy_element_token[:]
+    del yy_element_token.children[:]
 
 # GENERATE SECTION3
index 7516faa..160da64 100755 (executable)
@@ -27,5 +27,5 @@ _ast = y_tab.yyparse(t_def.AST)
 element.serialize(_ast, sys.stdout)
 #element.serialize(_ast, 'a.xml', 'utf-8')
 #_ast = element.deserialize('a.xml', t_def.factory, 'utf-8')
-for i in _ast:
+for i in _ast.children:
   sys.stdout.write('{0:g}\n'.format(i.eval()))
index a3cd22f..8c6110d 100644 (file)
@@ -67,22 +67,22 @@ def eval(self):
   raise NotImplementedException()
 @method(AST.Num)
 def eval(self):
-  mantissa = self[0].get_text()
-  fraction = self[1].get_text() if len(self) >= 2 else ''
+  mantissa = self.children[0].get_text()
+  fraction = self.children[1].get_text() if len(self.children) >= 2 else ''
   return int(mantissa + fraction) * 10 ** -len(fraction)
 @method(AST.Add)
 def eval(self):
-  return self[0].eval() + self[1].eval()
+  return self.children[0].eval() + self.children[1].eval()
 @method(AST.Sub)
 def eval(self):
-  return self[0].eval() - self[1].eval()
+  return self.children[0].eval() - self.children[1].eval()
 @method(AST.Mul)
 def eval(self):
-  return self[0].eval() * self[1].eval()
+  return self.children[0].eval() * self.children[1].eval()
 @method(AST.Div)
 def eval(self):
-  return self[0].eval() / self[1].eval()
+  return self.children[0].eval() / self.children[1].eval()
 @method(AST.Neg)
 def eval(self):
-  return -self[0].eval()
+  return -self.children[0].eval()
 del eval