Make syntax error call yyerror() rather than raising a Python exception master
authorNick Downing <nick@ndcode.org>
Mon, 25 Dec 2023 06:50:55 +0000 (17:50 +1100)
committerNick Downing <nick@ndcode.org>
Mon, 25 Dec 2023 06:52:34 +0000 (17:52 +1100)
ndcode/piyacc/parse-gram.y
ndcode/piyacc/skel/skel_py.py
ndcode/piyacc/skel/skel_py_element.py
skel_y_tab.py

index 87f1c97..d100820 100644 (file)
@@ -712,10 +712,11 @@ def lloc_default(loc, stack, n):
 #  if strverscmp(version, '3.0.5') > 0:
 #    complain(loc, complaint, 'require bison %s, but have %s', version, '3.0.5')
 #    exit(63)
-#
-#def gram_error(loc, msg):
-#  complain(loc, complaint, '%s', msg)
-#
+
+# was gram_error(), due to use of %define api.prefix
+def yyerror(loc, msg):
+  state.complain(loc, state.complaint, msg)
+
 #def token_name(type):
 #  return yytname[YYTRANSLATE(type)]
 #
index 3a263ab..ace03aa 100644 (file)
@@ -92,7 +92,8 @@ def yyparse():
         bisect.bisect_right(yy_lr1dfa_states[state][0], yychar)
       ]
       if action == -1:
-        raise Exception('syntax error')
+        yyerror(yylloc, 'syntax error')
+        assert False # error recovery is not implemented yet
       if (action & 1) == 0:
         yystack.append((action >> 1, yylval, yylloc.copy()))
         #print('shift', yystack[-1][0])
index 40726b2..d534337 100644 (file)
@@ -105,7 +105,8 @@ def yyparse(factory, *args, **kwargs):
         bisect.bisect_right(yy_lr1dfa_states[state][0], yychar)
       ]
       if action == -1:
-        raise Exception('syntax error')
+        yyerror(yylloc, 'syntax error')
+        assert False # error recovery is not implemented yet
       if (action & 1) == 0:
         # push space then AST element contiguously onto yy_element_stack
         # even numbered elements are spaces, odd numbered elements are AST
index 4f7d953..e33be3a 100644 (file)
@@ -101,7 +101,8 @@ def yyparse(factory, *args, **kwargs):
         bisect.bisect_right(yy_lr1dfa_states[state][0], yychar)
       ]
       if action == -1:
-        raise Exception('syntax error')
+        yyerror(yylloc, 'syntax error')
+        assert False # error recovery is not implemented yet
       if (action & 1) == 0:
         yystack.append((state, yylval, yylloc.copy()))