Pass python flag into AST.post_process(), to generate correct default actions
authorNick Downing <nick@ndcode.org>
Tue, 17 May 2022 07:29:41 +0000 (17:29 +1000)
committerNick Downing <nick@ndcode.org>
Tue, 17 May 2022 07:29:41 +0000 (17:29 +1000)
ndcode/pilex/cli.py
ndcode/pilex/pilex.t

index 46e8ac5..e616d6f 100755 (executable)
@@ -78,7 +78,7 @@ def main():
       _ast = y_tab.yyparse(t_def.AST)
   #element.serialize(_ast, 'a.xml', 'utf-8')
   #_ast = element.deserialize('a.xml', t_def.factory, 'utf-8')
-  _ast.post_process()
+  _ast.post_process(python)
   #element.serialize(_ast, 'b.xml', 'utf-8')
   #_ast = element.deserialize('b.xml', t_def.factory, 'utf-8')
   (generate_py if python else generate_flex)(
index e27c013..bd056ae 100644 (file)
@@ -890,7 +890,7 @@ def post_process(
     self.children[2] # action
   )
 @method(AST)
-def post_process(self):
+def post_process(self, python):
   # variables that will be serialized
   self.start_conditions = [
     AST.StartCondition(
@@ -903,7 +903,13 @@ def post_process(self):
   ]
   self.actions_text = []
   self.eof_actions_text = [
-    AST.Text(text = ['\t\t\t\tyyterminate();\n'])
+    AST.Text(
+      text = [
+        '\t\t\t\tyyterminate()\n'
+      if python else
+        '\t\t\t\tyyterminate();\n'
+      ]
+    )
   ]
   self.flex_rules = []
   self.n_groups = 0
@@ -928,9 +934,17 @@ def post_process(self):
   self.actions_text.append(
     AST.Text(
       text = [
-        'ECHO;\n'
+        (
+          'ECHO()\n'
+        if python else
+          'ECHO;\n'
+        )
       if self.children[0].default else
-        'YY_FATAL_ERROR( "flex scanner jammed" );\n'
+        (
+          'YY_FATAL_ERROR( "flex scanner jammed" )\n'
+        if python else
+          'YY_FATAL_ERROR( "flex scanner jammed" );\n'
+        )
       ]
     )
   )