comparison src/lex.l @ 4867:c7f9ea142fda

[project @ 2004-04-20 19:41:11 by jwe]
author jwe
date Tue, 20 Apr 2004 19:41:11 +0000
parents e941e1470d7b
children 1242acab4246
comparison
equal deleted inserted replaced
4866:3cb99ace0edb 4867:c7f9ea142fda
227 // file. 227 // file.
228 228
229 static void fixup_column_count (char *s); 229 static void fixup_column_count (char *s);
230 static void do_comma_insert_check (void); 230 static void do_comma_insert_check (void);
231 static int is_plot_keyword (const std::string& s); 231 static int is_plot_keyword (const std::string& s);
232 static int is_keyword (const std::string& s); 232 static int is_keyword_token (const std::string& s);
233 static void prep_for_function (void); 233 static void prep_for_function (void);
234 static void prep_for_nested_function (void); 234 static void prep_for_nested_function (void);
235 static std::string plot_style_token (const std::string& s); 235 static std::string plot_style_token (const std::string& s);
236 static symbol_record *lookup_identifier (const std::string& s); 236 static symbol_record *lookup_identifier (const std::string& s);
237 static std::string grab_help_text (void); 237 static std::string grab_help_text (void);
1159 } 1159 }
1160 1160
1161 // Handle keywords. Return -1 if the keyword should be ignored. 1161 // Handle keywords. Return -1 if the keyword should be ignored.
1162 1162
1163 static int 1163 static int
1164 is_keyword (const std::string& s) 1164 is_keyword_token (const std::string& s)
1165 { 1165 {
1166 int l = input_line_number; 1166 int l = input_line_number;
1167 int c = current_input_column; 1167 int c = current_input_column;
1168 1168
1169 if (lexer_flags.plotting) 1169 if (lexer_flags.plotting)
2470 2470
2471 // If we have a regular keyword, or a plot STYLE, return it. 2471 // If we have a regular keyword, or a plot STYLE, return it.
2472 // Keywords can be followed by identifiers (TOK_RETURN handles 2472 // Keywords can be followed by identifiers (TOK_RETURN handles
2473 // that). 2473 // that).
2474 2474
2475 int kw_token = is_keyword (tok); 2475 int kw_token = is_keyword_token (tok);
2476 2476
2477 if (kw_token) 2477 if (kw_token)
2478 { 2478 {
2479 if (kw_token < 0) 2479 if (kw_token < 0)
2480 return kw_token; 2480 return kw_token;
2651 2651
2652 // Quote marks strings intially. 2652 // Quote marks strings intially.
2653 quote_is_transpose = false; 2653 quote_is_transpose = false;
2654 } 2654 }
2655 2655
2656 bool
2657 is_keyword (const std::string& s)
2658 {
2659 return octave_kw_lookup (s.c_str (), s.length ()) != 0;
2660 }
2661
2656 DEFCMD (iskeyword, args, , 2662 DEFCMD (iskeyword, args, ,
2657 "-*- texinfo -*-\n\ 2663 "-*- texinfo -*-\n\
2658 @deftypefn {Built-in Function} {} iskeyword (@var{name})\n\ 2664 @deftypefn {Built-in Function} {} iskeyword (@var{name})\n\
2659 Return true if @var{name} is an Octave keyword. If @var{name}\n\ 2665 Return true if @var{name} is an Octave keyword. If @var{name}\n\
2660 is omitted, return a list of keywords.\n\ 2666 is omitted, return a list of keywords.\n\
2662 { 2668 {
2663 octave_value retval; 2669 octave_value retval;
2664 2670
2665 int argc = args.length () + 1; 2671 int argc = args.length () + 1;
2666 2672
2667 string_vector argv = args.make_argv ("help"); 2673 string_vector argv = args.make_argv ("iskeyword");
2668 2674
2669 if (error_state) 2675 if (error_state)
2670 return retval; 2676 return retval;
2671 2677
2672 if (argc == 1) 2678 if (argc == 1)
2678 2684
2679 retval = Cell (lst.qsort ()); 2685 retval = Cell (lst.qsort ());
2680 } 2686 }
2681 else if (argc == 2) 2687 else if (argc == 2)
2682 { 2688 {
2683 std::string s = argv[1]; 2689 retval = is_keyword (argv[1]);
2684
2685 retval = (octave_kw_lookup (s.c_str (), s.length ()) != 0);
2686 } 2690 }
2687 else 2691 else
2688 print_usage ("iskeyword"); 2692 print_usage ("iskeyword");
2689 2693
2690 return retval; 2694 return retval;