Make syntax error call yyerror() rather than raising a Python exception
[piyacc.git] / skel_lex_yy.py
index 2c19629..ad1fa13 100644 (file)
 # special exception.
 
 import bisect
-import element
 import sys
+from ndcode.piyacc import element
+
+# this can be redefined in SECTION1
+def YY_AT_BOL():
+  return yy_buffer_stack[-1].at_bol
+
+def yy_set_bol(at_bol):
+  yy_buffer_stack[-1].at_bol = at_bol
+
+def YY_USER_ACTION():
+  pass
+
+def YY_RULE_START():
+  # note that this should also be done after yyless() and REJECT(),
+  # and state should be saved in case they result in a null string,
+  # however, it doesn't seem to be in flex, maintain compatibility:
+  if len(yytext):
+    yy_set_bol(yytext[-1] == '\n')
+  YY_USER_ACTION()
 
 # GENERATE SECTION1
 
@@ -118,11 +136,7 @@ def yy_rule_start():
   yytext = yy_group_text[:yy_group_stack[-1]]
   yytext_len = yy_group_stack[-1]
   del yy_group_stack[-2:]
-  # note that this should also be done after yyless() and REJECT(),
-  # and state should be saved in case they result in a null string,
-  # however, it doesn't seem to be in flex, maintain compatibility:
-  if len(yytext):
-    yy_buffer_stack[-1].at_bol = yytext[-1] == '\n'
+  YY_RULE_START()
   yy_element_stack.append([])
 
 def yy_group_end():
@@ -131,8 +145,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])
@@ -157,15 +171,9 @@ def yy_pop_state():
   global yystart
   yystart = yystart_stack.pop()
 
-def YY_AT_BOL():
-  return yy_buffer_stack[-1].at_bol
-
-def yy_set_bol(at_bol):
-  yy_buffer_stack[-1].at_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 +190,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 +334,7 @@ def yylex(factory = element.Element, *args, **kwargs):
         0,
         yytext_len,
         yy_element_stack.pop(),
-        factory,
+        _class,
         *args,
         **kwargs
       )