Get non-groups Python skeleton working, seems it wasn't tested at all before
authorNick Downing <nick@ndcode.org>
Tue, 17 May 2022 08:44:08 +0000 (18:44 +1000)
committerNick Downing <nick@ndcode.org>
Tue, 17 May 2022 08:44:08 +0000 (18:44 +1000)
ndcode/pilex/skel/skel_py.py

index 888303f..e2451c1 100644 (file)
@@ -261,23 +261,24 @@ def yylex():
         # character available
         yy_state_buf.append(yy_current_state)
         yy_c = ord(block.text[block_pos])
+        block_pos += 1
         #print('yy_c', yy_c)
         while yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state:
           yy_current_state = yy_def[yy_current_state];
         yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
         if yy_base[yy_current_state] != 0:
-          block_pos += 1
           continue # goto yy_match
 
       # we get here when either there is EOF and had some characters, or
       # we had a character which makes DFA stuck -- do best action we can
       break # goto yy_find_action
 
-    # if the following assertion fails there is a hole in state machine,
-    # this is not supposed to happen due to the automatic catch-all rule
-    yy_state_ptr = len(yy_state_buf) - 1
-    assert yy_state_ptr >= 0
-    yy_current_state = yy_state_buf[yy_state_ptr]
+    # yy_find_action:
+    # we seem to detect the jam one character earlier than flex does (when
+    # we've processed the last character of the maximal length string rather
+    # than when we try to process another character after that), and hence
+    # we do not need to back up one character here, unlike flex's algorithm
+    yy_state_ptr = len(yy_state_buf)
     yy_lp = yy_accept[yy_current_state]
 
     # take most recent data from block for yytext
@@ -287,7 +288,6 @@ def yylex():
       match += block.text[block_pos - i:block_pos]
     assert len(match) == yy_state_ptr
 
-    # yy_find_action:
     # the following variables are used to handle trailing context
     # suppose there is a rule like: foo/bar
     # then state after 3 characters will be given YY_TRAILING_MASK
@@ -303,68 +303,68 @@ def yylex():
 
     # find_rule:
     # we branch to this label when backing up (i.e. reject)
-    while True: # until we find what rule matched
-      if yy_lp < yy_accept[yy_current_state + 1]:
-        yy_act = yy_acclist[yy_lp]
-        if (yy_act & YY_TRAILING_HEAD_MASK) or yy_looking_for_trail_begin:
-          if yy_act == yy_looking_for_trail_begin:
-            yy_looking_for_trail_begin = 0
-            yy_act &= ~YY_TRAILING_HEAD_MASK
+    while True:
+      #print('find_rule')
+      while True: # until we find what rule matched
+        if yy_lp < yy_accept[yy_current_state + 1]:
+          yy_act = yy_acclist[yy_lp]
+          if (yy_act & YY_TRAILING_HEAD_MASK) or yy_looking_for_trail_begin:
+            if yy_act == yy_looking_for_trail_begin:
+              yy_looking_for_trail_begin = 0
+              yy_act &= ~YY_TRAILING_HEAD_MASK
+              break
+          elif yy_act & YY_TRAILING_MASK:
+            yy_looking_for_trail_begin = (
+              (yy_act & ~YY_TRAILING_MASK) | YY_TRAILING_HEAD_MASK
+            )
+            yy_full_state_ptr = yy_state_ptr
+            yy_full_lp = yy_lp
+          else:
+            yy_full_state_ptr = yy_state_ptr
+            yy_full_lp = yy_lp
             break
-        elif yy_act & YY_TRAILING_MASK:
-          yy_looking_for_trail_begin = (
-            (yy_act & ~YY_TRAILING_MASK) | YY_TRAILING_HEAD_MASK
-          )
-          yy_full_state_ptr = yy_state_ptr
-          yy_full_lp = yy_lp
+          yy_lp += 1
         else:
-          yy_full_state_ptr = yy_state_ptr
-          yy_full_lp = yy_lp
-          break
-        yy_lp += 1
+          # if the following assertion fails there is a hole in state machine,
+          # this is not supposed to happen due to the automatic catch-all rule
+          yy_state_ptr -= 1
+          assert yy_state_ptr >= 0
+          yy_current_state = yy_state_buf[yy_state_ptr]
+          yy_lp = yy_accept[yy_current_state]
+  
+      # at this point yy_state_ptr == number of chars needed
+      # truncate or extend yytext from match, counting added/removed newlines
+      if len(yytext) < yy_state_ptr:
+        i = match.find('\n', len(yytext), yy_state_ptr)
+        while i >= 0:
+          yylineno += 1
+          i = match.find('\n', i + 1, yy_state_ptr)
       else:
-        # if the following assertion fails there is a hole in state machine,
-        # this is not supposed to happen due to the automatic catch-all rule
-        yy_state_ptr -= 1
-        assert yy_state_ptr >= 0
+        i = yytext.find('\n', yy_state_ptr)
+        while i >= 0:
+          yylineno -= 1
+          i = yytext.find('\n', i + 1)
+      yytext = match[:yy_state_ptr]
+  
+      try:
+        yytext_len = len(yytext) # this is used by yycommit()
+        token = yy_actions[yy_act]()
+        yycommit() # user cannot call REJECT() / yyless() anymore
+        yyin = yy_buffer_stack[-1].file_in = yyin # user may modify
+        return token
+      except YYReject:
+        yy_state_ptr = yy_full_state_ptr
         yy_current_state = yy_state_buf[yy_state_ptr]
-        yy_lp = yy_accept[yy_current_state]
-
-    # at this point yy_state_ptr == number of chars needed
-    # truncate or extend yytext from match, counting added/removed newlines
-    if len(yytext) < yy_state_ptr:
-      i = match.find('\n', len(yytext), yy_state_ptr)
-      while i >= 0:
-        yylineno += 1
-        i = match.find('\n', i + 1, yy_state_ptr)
-    else:
-      i = yytext.find('\n', yy_state_ptr)
-      while i >= 0:
-        yylineno -= 1
-        i = yytext.find('\n', i + 1)
-    yytext = match[:yy_state_ptr]
-
-    try:
-      yytext_len = len(yytext) # this is used by yycommit()
-      token = yy_actions[yy_act]()
-      yycommit() # user cannot call REJECT() / yyless() anymore
-      yyin = yy_buffer_stack[-1].file_in = yyin # user may modify
-      return token
-    except YYReject:
-      yy_state_ptr = yy_full_state_ptr
-      yy_current_state = yy_state_buf[yy_state_ptr]
-      yy_lp = yy_full_lp + 1
+        yy_lp = yy_full_lp + 1
+        # goto find_rule
+      except YYContinue:
+        yycommit() # user cannot call REJECT() / yyless() anymore
+        break # goto start
+      except YYTerminate:
+        yycommit() # user cannot call REJECT() / yyless() anymore
+        yyin = yy_buffer_stack[-1].file_in = yyin # user may modify
+        return 0
       # goto find_rule
-    except YYContinue:
-      yycommit() # user cannot call REJECT() / yyless() anymore
-      break # goto start
-    except YYTerminate:
-      yycommit() # user cannot call REJECT() / yyless() anymore
-      yyin = yy_buffer_stack[-1].file_in = yyin # user may modify
-      return 0
-
-    # goto find_rule
-
-  # goto start
+    # goto start
 
 # GENERATE SECTION3