changeset 4867:c7f9ea142fda

[project @ 2004-04-20 19:41:11 by jwe]
author jwe
date Tue, 20 Apr 2004 19:41:11 +0000
parents 3cb99ace0edb
children 0d7b436d0e87
files src/lex.h src/lex.l src/ls-mat-ascii.cc
diffstat 3 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/lex.h	Tue Apr 20 16:03:47 2004 +0000
+++ b/src/lex.h	Tue Apr 20 19:41:11 2004 +0000
@@ -46,6 +46,9 @@
 // Delete a buffer (for unwind-prot).
 extern void delete_input_buffer (void *buf);
 
+// Is the given string a keyword?
+extern bool is_keyword (const std::string& s);
+
 // For communication between the lexer and parser.
 
 class
--- a/src/lex.l	Tue Apr 20 16:03:47 2004 +0000
+++ b/src/lex.l	Tue Apr 20 19:41:11 2004 +0000
@@ -229,7 +229,7 @@
 static void fixup_column_count (char *s);
 static void do_comma_insert_check (void);
 static int is_plot_keyword (const std::string& s);
-static int is_keyword (const std::string& s);
+static int is_keyword_token (const std::string& s);
 static void prep_for_function (void);
 static void prep_for_nested_function (void);
 static std::string plot_style_token (const std::string& s);
@@ -1161,7 +1161,7 @@
 // Handle keywords.  Return -1 if the keyword should be ignored.
 
 static int
-is_keyword (const std::string& s)
+is_keyword_token (const std::string& s)
 {
   int l = input_line_number;
   int c = current_input_column;
@@ -2472,7 +2472,7 @@
   // Keywords can be followed by identifiers (TOK_RETURN handles
   // that).
 
-  int kw_token = is_keyword (tok);
+  int kw_token = is_keyword_token (tok);
 
   if (kw_token)
     {
@@ -2653,6 +2653,12 @@
   quote_is_transpose = false;
 }
 
+bool
+is_keyword (const std::string& s)
+{
+  return octave_kw_lookup (s.c_str (), s.length ()) != 0;
+}
+
 DEFCMD (iskeyword, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {} iskeyword (@var{name})\n\
@@ -2664,7 +2670,7 @@
 
   int argc = args.length () + 1;
 
-  string_vector argv = args.make_argv ("help");
+  string_vector argv = args.make_argv ("iskeyword");
 
   if (error_state)
     return retval;
@@ -2680,9 +2686,7 @@
     }
   else if (argc == 2)
     {
-      std::string s = argv[1];
-
-      retval = (octave_kw_lookup (s.c_str (), s.length ()) != 0);
+      retval = is_keyword (argv[1]);
     }
   else
     print_usage ("iskeyword");
--- a/src/ls-mat-ascii.cc	Tue Apr 20 16:03:47 2004 +0000
+++ b/src/ls-mat-ascii.cc	Tue Apr 20 19:41:11 2004 +0000
@@ -49,6 +49,7 @@
 #include "defun.h"
 #include "error.h"
 #include "gripes.h"
+#include "lex.h"
 #include "load-save.h"
 #include "oct-obj.h"
 #include "oct-map.h"
@@ -209,7 +210,7 @@
   else
     varname = filename;
 
-  pos = varname.find ('.');
+  pos = varname.rfind ('.');
 
   if (pos != NPOS)
     varname = varname.substr (0, pos);
@@ -222,7 +223,7 @@
 	varname[i] = '_';
     }
 
-  if (! isalpha (varname[0]))
+  if (is_keyword (varname) || ! isalpha (varname[0]))
     varname.insert (0, "X");
 
   if (valid_identifier (varname))