changeset 8701:1652e39b934e

handle command names in declaration lists
author John W. Eaton <jwe@octave.org>
date Mon, 09 Feb 2009 12:23:12 -0500
parents 314be237cd5b
children 3c4628550318
files src/ChangeLog src/lex.h src/lex.l src/parse.y
diffstat 4 files changed, 30 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Feb 09 13:05:35 2009 +0100
+++ b/src/ChangeLog	Mon Feb 09 12:23:12 2009 -0500
@@ -1,3 +1,12 @@
+2009-02-09  John W. Eaton  <jwe@octave.org>
+
+	* lex.l (lexical_feedback::looking_at_decl_list): New data member.
+	* lex.l (lexical_feedback::init): Initialize it.
+	(handle_identifier): Also force local variable if looking_at_decl_list.
+	* parse.y (parsing_decl_list): New non-terminal.
+	(declaration): Use it.  Set lexer_flags.looking_at_decl_list to
+	false after parsing the declaration.
+
 2009-02-09  Jaroslav Hajek  <highegg@gmail.com>
 
 	* TEMPLATE-INST/Array-tc.cc: Reflect changes in octave_sort.
--- a/src/lex.h	Mon Feb 09 13:05:35 2009 +0100
+++ b/src/lex.h	Mon Feb 09 12:23:12 2009 -0500
@@ -92,6 +92,10 @@
   // TRUE means we're parsing the parameter list for a function.
   bool looking_at_parameter_list;
 
+  // TRUE means we're parsing a declaration list (global or
+  // persistent).
+  bool looking_at_decl_list;
+
   // TRUE means we are looking at the initializer expression for a
   // parameter list element.
   bool looking_at_initializer_expression;
--- a/src/lex.l	Mon Feb 09 13:05:35 2009 +0100
+++ b/src/lex.l	Mon Feb 09 12:23:12 2009 -0500
@@ -2768,6 +2768,7 @@
   if (is_command_name (tok) && ! is_variable (tok))
     {
       if (next_tok_is_eq
+	  || lexer_flags.looking_at_decl_list
 	  || lexer_flags.looking_at_return_list
 	  || (lexer_flags.looking_at_parameter_list
 	      && ! lexer_flags.looking_at_initializer_expression))
@@ -2841,9 +2842,10 @@
   // Not initiallly looking at a function handle.
   looking_at_function_handle = 0;
 
-  // Not parsing a function return or parameter list.
+  // Not parsing a function return, parameter, or declaration list.
   looking_at_return_list = false;
   looking_at_parameter_list = false;
+  looking_at_decl_list = false;
 
   // Not looking at an argument list initializer expression.
   looking_at_initializer_expression = false;
--- a/src/parse.y	Mon Feb 09 13:05:35 2009 +0100
+++ b/src/parse.y	Mon Feb 09 12:23:12 2009 -0500
@@ -929,10 +929,20 @@
 // Declaration statemnts
 // =====================
 
-declaration	: GLOBAL decl1
-		  { $$ = make_decl_command (GLOBAL, $1, $2); }
-		| STATIC decl1
-		  { $$ = make_decl_command (STATIC, $1, $2); }
+parsing_decl_list
+		: // empty
+		  { lexer_flags.looking_at_decl_list = true; }
+
+declaration	: GLOBAL parsing_decl_list decl1
+		  {
+		    $$ = make_decl_command (GLOBAL, $1, $3);
+		    lexer_flags.looking_at_decl_list = false;
+		  }
+		| STATIC parsing_decl_list decl1
+		  {
+		    $$ = make_decl_command (STATIC, $1, $3);
+		    lexer_flags.looking_at_decl_list = false;
+		  }
 		;
 
 decl1		: decl2