Make element groups also behave as numbered groups (so that element constructor can...
authorNick Downing <nick@ndcode.org>
Sat, 26 Jan 2019 22:32:01 +0000 (09:32 +1100)
committerNick Downing <nick@ndcode.org>
Sat, 26 Jan 2019 22:32:01 +0000 (09:32 +1100)
generate_py.py

index 231c36c..e8b027f 100644 (file)
@@ -92,42 +92,38 @@ yy_action = yy_action{1:d}
           groups[j][0]
         if isinstance(groups[j], regex.RegexGroupAction) else
           regex.Text(
-            text = '''_element = yy_group_element(
+            text = '''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],
   yy_element_stack.pop(),
-  {0:s}
+  {1:s}
 )
 yy_element_stack[-1].append(
-  (yy_group_stack[-1], yy_group_stack[-2], _element)
+  (yy_group_stack[-1], yy_group_stack[-2], yy_element)
 )
 del yy_group_stack[-2:]
 '''.format(
+              j + 1,
               groups[j][0].get_text()
             )
           )
         if isinstance(groups[j], regex.RegexGroupElement) else
           regex.Text(
-            text = '''if yy_groups[{0:d}] is None:
-  yy_groups[{1:d}] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
-  if '{2:s}' not in yy_groups_by_name:
-    yy_groups_by_name['{3:s}'] = yy_groups[{4:d}]
+            text = '''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,
-              j + 1,
-              groups[j][0].get_text(),
-              groups[j][0].get_text(),
-              j + 1
+              groups[j][0].get_text()
             )
           )
         if isinstance(groups[j], regex.RegexGroupName) else
           regex.Text(
-            text = '''if yy_groups[{0:d}] is None:
-  yy_groups[{1:d}] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
+            text = '''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
             )
           )