diff libinterp/parse-tree/lex.ll @ 16164:c5bfdc4c0963

move end_of_input flag from octve_parser class to octave_lexer class * lex.h, lex.ll, parse.h, oct-parse.yy, toplev.cc (octave_lexer::end_of_input): Move data member from octave_parser. Change all uses. * lex.h, lex.ll (octave_lexer::handle_end_of_input): New function. (<<EOF>>): Use it. ({CCHAR}, .): USe it instead of simply returning END_OF_INPUT token. * lex.ll (octave_lexer::xunput): Don't unput EOF.
author John W. Eaton <jwe@octave.org>
date Fri, 01 Mar 2013 07:10:31 -0500
parents 7eb614760ddb
children cb80b1d062b1
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll	Thu Feb 28 12:07:23 2013 -0800
+++ b/libinterp/parse-tree/lex.ll	Fri Mar 01 07:10:31 2013 -0500
@@ -612,19 +612,7 @@
 %}
 
 <<EOF>> {
-    LEXER_DEBUG ("<<EOF>>");
-
-    if (curr_lexer->block_comment_nesting_level != 0)
-      {
-        warning ("block comment open at end of input");
-
-        if ((reading_fcn_file || reading_script_file || reading_classdef_file)
-            && ! curr_fcn_file_name.empty ())
-          warning ("near line %d of file '%s.m'",
-                   curr_lexer->input_line_number, curr_fcn_file_name.c_str ());
-      }
-
-    TOK_RETURN (END_OF_INPUT);
+   return curr_lexer->handle_end_of_input ();
   }
 
 %{
@@ -776,7 +764,7 @@
     int tok = curr_lexer->process_comment (false, eof);
 
     if (eof)
-      TOK_RETURN (END_OF_INPUT);
+      return curr_lexer->handle_end_of_input ();
     else if (tok > 0)
       COUNT_TOK_AND_RETURN (tok);
   }
@@ -975,7 +963,7 @@
         return LEXICAL_ERROR;
       }
     else
-      TOK_RETURN (END_OF_INPUT);
+      return curr_lexer->handle_end_of_input ();
   }
 
 %%
@@ -1451,6 +1439,28 @@
   return status;
 }
 
+int
+octave_lexer::handle_end_of_input (void)
+{
+  // FIXME -- we need this because of the way TOK_RETURN is defined.  DO
+  // something better than that...
+  OCTAVE_YYG;
+
+  LEXER_DEBUG ("<<EOF>>");
+
+  if (block_comment_nesting_level != 0)
+    {
+      warning ("block comment open at end of input");
+
+      if ((reading_fcn_file || reading_script_file || reading_classdef_file)
+          && ! curr_fcn_file_name.empty ())
+        warning ("near line %d of file '%s.m'",
+                 input_line_number, curr_fcn_file_name.c_str ());
+    }
+
+  TOK_RETURN (END_OF_INPUT);
+}
+
 char *
 octave_lexer::flex_yytext (void)
 {
@@ -1525,17 +1535,20 @@
 void
 octave_lexer::xunput (char c, char *buf)
 {
-  if (lexer_debug_flag)
+  if (c != EOF)
     {
-      std::cerr << "U: ";
-      display_character (c);
-      std::cerr << std::endl;
+      if (lexer_debug_flag)
+        {
+          std::cerr << "U: ";
+          display_character (c);
+          std::cerr << std::endl;
+        }
+
+      if (c == '\n')
+        input_line_number--;
+
+      yyunput (c, buf, scanner);
     }
-
-  if (c == '\n')
-    input_line_number--;
-
-  yyunput (c, buf, scanner);
 }
 
 void