Change file reading to not re-attempt read from any stream once EOF is reached
authorNick Downing <nick@ndcode.org>
Sat, 12 Jan 2019 01:45:59 +0000 (12:45 +1100)
committerNick Downing <nick@ndcode.org>
Sat, 12 Jan 2019 01:46:51 +0000 (12:46 +1100)
skel/skel_py.py
skel/skel_py_element.py

index 816aaf1..38e2951 100644 (file)
@@ -126,7 +126,6 @@ def yylex():
     block = block_prev.next
     if block is not None:
       block_pos = block.pos
-    file_in = yyin
 
     action = yy_dfa_start_action[yystart]
     while action != -1:
@@ -168,14 +167,19 @@ def yylex():
         assert yy_dfa_states[state][2] == [0]
         break
 
+      yy_buffer_stack[-1].file_in = yyin
       while block is None or block_pos >= len(block.text):
         if block is None:
-          text = file_in.readline()
+          file_in = yy_buffer_stack[buffer_ptr].file_in
+          text = '' if file_in is None else file_in.readline()
           if len(text):
             block = YYBufferBlock(None, 0, text)
             block_pos = 0
             block_prev.next = block
           else:
+            # do not re-attempt read once EOF is reached
+            yy_buffer_stack[buffer_ptr].file_in = None
+            yyin = yy_buffer_stack[-1].file_in
             buffer_ptr -= 1
             if buffer_ptr < 0:
               break # EOF
@@ -183,7 +187,6 @@ def yylex():
             block = block_prev.next
             if block is not None:
               block_pos = block.pos
-            file_in = yy_buffer_stack[buffer_ptr].file_in
         else:
           i = match_len - len(match)
           if i:
index 0b0edf5..f1d0faf 100644 (file)
@@ -149,7 +149,6 @@ def yylex():
     block = block_prev.next
     if block is not None:
       block_pos = block.pos
-    file_in = yyin
 
     action = yy_dfa_start_action[yystart]
     while action != -1:
@@ -191,14 +190,19 @@ def yylex():
         assert yy_dfa_states[state][2] == [0]
         break
 
+      yy_buffer_stack[-1].file_in = yyin
       while block is None or block_pos >= len(block.text):
         if block is None:
-          text = file_in.readline()
+          file_in = yy_buffer_stack[buffer_ptr].file_in
+          text = '' if file_in is None else file_in.readline()
           if len(text):
             block = YYBufferBlock(None, 0, text)
             block_pos = 0
             block_prev.next = block
           else:
+            # do not re-attempt read once EOF is reached
+            yy_buffer_stack[buffer_ptr].file_in = None
+            yyin = yy_buffer_stack[-1].file_in
             buffer_ptr -= 1
             if buffer_ptr < 0:
               break # EOF
@@ -206,7 +210,6 @@ def yylex():
             block = block_prev.next
             if block is not None:
               block_pos = block.pos
-            file_in = yy_buffer_stack[buffer_ptr].file_in
         else:
           i = match_len - len(match)
           if i: