Update to pitree.git commit 71dd736
authorNick Downing <nick@ndcode.org>
Tue, 29 Jan 2019 09:49:17 +0000 (20:49 +1100)
committerNick Downing <nick@ndcode.org>
Tue, 29 Jan 2019 09:55:54 +0000 (20:55 +1100)
generate_py.py
pilex.t
regex.t
skel/skel_py_element.py
skel_lex_yy.py
tests_ast/cal_py.t

index 0ad3707..718a148 100644 (file)
@@ -92,14 +92,16 @@ def generate_py(_ast, _element, home_dir, skel_file, out_file):
     groups = i.groups0 + i.groups1
     group_rules_text.append(
       regex.Text(
-        text = '''global yy_groups, yy_groups_by_name, yy_action
+        [
+          '''global yy_groups, yy_groups_by_name, yy_action
 yy_groups = [yy_group_text[:yy_group_stack[-1]]{0:s}]
 yy_groups_by_name = {{}}
 yy_action = yy_action{1:d}
 '''.format(
-          ', None' * len(groups),
-          i.action
-        )
+            ', None' * len(groups),
+            i.action
+          )
+        ]
       )
     )
     group_actions_text.extend(
@@ -108,7 +110,8 @@ yy_action = yy_action{1:d}
           groups[j].children[0]
         if isinstance(groups[j], regex.RegexGroupAction) else
           regex.Text(
-            text = '''yy_groups[{0:d}] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
+            [
+              '''yy_groups[{0:d}] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
 yy_element = yy_group_element(
   yy_group_stack[-1],
   yy_group_stack[-2],
@@ -120,28 +123,33 @@ yy_element_stack[-1].append(
 )
 del yy_group_stack[-2:]
 '''.format(
-              j + 1,
-              groups[j].children[0].get_text()
-            )
+                j + 1,
+                groups[j].children[0].get_text()
+              )
+            ]
           )
         if isinstance(groups[j], regex.RegexGroupElement) else
           regex.Text(
-            text = '''yy_temp = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
+            [
+              '''yy_temp = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
 yy_groups[{0:d}] = yy_temp
 yy_groups_by_name['{1:s}'] = yy_temp
 del yy_group_stack[-2:]
 '''.format(
-              j + 1,
-              groups[j].children[0].get_text()
-            )
+                j + 1,
+                groups[j].children[0].get_text()
+              )
+            ]
           )
         if isinstance(groups[j], regex.RegexGroupName) else
           regex.Text(
-            text = '''yy_groups[{0:d}] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
+            [
+              '''yy_groups[{0:d}] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
 del yy_group_stack[-2:]
 '''.format(
-              j + 1
-            )
+                j + 1
+              )
+            ]
           )
         )
         for j in range(len(groups))
@@ -157,13 +165,15 @@ del yy_group_stack[-2:]
   )
   group_rules_text.append(
     regex.Text(
-      text = '''global yy_groups, yy_groups_by_name, yy_action
+      [
+        '''global yy_groups, yy_groups_by_name, yy_action
 yy_groups = [yy_group_text[:yy_group_stack[-1]]]
 yy_groups_by_name = {{}}
 yy_action = yy_action{0:d}
 '''.format(
-        _ast.default_action
-      )
+          _ast.default_action
+        )
+      ]
     )
   )
 
diff --git a/pilex.t b/pilex.t
index 1d0d336..d2cf631 100644 (file)
--- a/pilex.t
+++ b/pilex.t
@@ -220,7 +220,12 @@ class AST {
 %%
 
 def factory(tag, *args, **kwargs):
-  return tag_to_class.get(tag, regex.factory)(tag, attrib, *args, **kwargs)
+  _class = tag_to_class.get(tag)
+  return (
+    regex.factory(tag, *args, **kwargs)
+  if _class is None else
+    _class(*args, **kwargs)
+  )
 
 @method(Item)
 def post_process(
@@ -898,7 +903,7 @@ def post_process(self):
   ]
   self.actions_text = []
   self.eof_actions_text = [
-    AST.Text(text = '\t\t\t\tyyterminate();\n')
+    AST.Text(['\t\t\t\tyyterminate();\n'])
   ]
   self.flex_rules = []
   self.n_groups = 0
@@ -922,11 +927,11 @@ def post_process(self):
   self.default_action = len(self.actions_text)
   self.actions_text.append(
     AST.Text(
-      text = (
+      [
         'ECHO;\n'
       if self.children[0].default else
         'YY_FATAL_ERROR( "flex scanner jammed" );\n'
-      )
+      ]
     )
   )
 del post_process
diff --git a/regex.t b/regex.t
index f404f93..7608205 100644 (file)
--- a/regex.t
+++ b/regex.t
@@ -64,7 +64,7 @@ class RegexGroupElement: RegexGroup {
 n_characters = 0x100
 
 def factory(tag, *args, **kwargs):
-  return tag_to_class.get(tag, element.Element)(tag, *args, **kwargs)
+  return tag_to_class[tag](*args, **kwargs)
 
 @method(Regex)
 def post_process(self, groups, caseless = False):
index 2c19629..688fc95 100644 (file)
@@ -131,8 +131,8 @@ def yy_group_end():
 def yy_group_end_element():
   yy_element_stack.append([])
 
-def yy_group_element(pos0, pos1, stack, factory, *args, **kwargs):
-  _element = factory(*args, **kwargs)
+def yy_group_element(pos0, pos1, stack, _class, *args, **kwargs):
+  _element = _class(*args, **kwargs)
   del _element.text[:]
   for pos2, pos3, i in reversed(stack):
     _element.text.append(yy_group_text[pos0:pos2])
@@ -165,7 +165,7 @@ def yy_set_bol(at_bol):
 
 # GENERATE SECTION2
 
-def yylex(factory = element.Element, *args, **kwargs):
+def yylex(_class = element.Element, *args, **kwargs):
   global \
     yyin, \
     yy_threads0, \
@@ -182,8 +182,8 @@ def yylex(factory = element.Element, *args, **kwargs):
 
   # GENERATE SECTION2INITIAL
 
-  yy_element_space = factory(*args, **kwargs)
-  yy_element_token = factory(*args, **kwargs)
+  yy_element_space = _class(*args, **kwargs)
+  yy_element_token = _class(*args, **kwargs)
   while True:
     while yytext_len:
       block = yy_buffer_stack[-1].next
@@ -326,7 +326,7 @@ def yylex(factory = element.Element, *args, **kwargs):
         0,
         yytext_len,
         yy_element_stack.pop(),
-        factory,
+        _class,
         *args,
         **kwargs
       )
index 2c19629..688fc95 100644 (file)
@@ -131,8 +131,8 @@ def yy_group_end():
 def yy_group_end_element():
   yy_element_stack.append([])
 
-def yy_group_element(pos0, pos1, stack, factory, *args, **kwargs):
-  _element = factory(*args, **kwargs)
+def yy_group_element(pos0, pos1, stack, _class, *args, **kwargs):
+  _element = _class(*args, **kwargs)
   del _element.text[:]
   for pos2, pos3, i in reversed(stack):
     _element.text.append(yy_group_text[pos0:pos2])
@@ -165,7 +165,7 @@ def yy_set_bol(at_bol):
 
 # GENERATE SECTION2
 
-def yylex(factory = element.Element, *args, **kwargs):
+def yylex(_class = element.Element, *args, **kwargs):
   global \
     yyin, \
     yy_threads0, \
@@ -182,8 +182,8 @@ def yylex(factory = element.Element, *args, **kwargs):
 
   # GENERATE SECTION2INITIAL
 
-  yy_element_space = factory(*args, **kwargs)
-  yy_element_token = factory(*args, **kwargs)
+  yy_element_space = _class(*args, **kwargs)
+  yy_element_token = _class(*args, **kwargs)
   while True:
     while yytext_len:
       block = yy_buffer_stack[-1].next
@@ -326,7 +326,7 @@ def yylex(factory = element.Element, *args, **kwargs):
         0,
         yytext_len,
         yy_element_stack.pop(),
-        factory,
+        _class,
         *args,
         **kwargs
       )
index 0dea63b..276bc28 100644 (file)
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-%{
-  import element
-%}
-
 %%
 
 class Text;
@@ -38,8 +34,8 @@ class AST {
 
 %%
 
-def factory(tag, attrib = {}, *args, **kwargs):
-  return tag_to_class.get(tag, element.Element)(tag, attrib, *args, **kwargs)
+def factory(tag, *args, **kwargs):
+  return tag_to_class[tag](*args, **kwargs)
 
 @method(Text)
 def get_text(self):