comparison libinterp/parse-tree/lex.ll @ 16106:031117f4db7c

use enum for values returned by eat_continuation and eat_whitespace * lex.ll, lex.h (lexical_feedback::whitespace_type): New enum. (yum_yum): Delete typedef. (ATE_NOTHING, ATE_SPACE_OR_TAB, ATE_NEWLINE): Replace with NO_WHITESPACE, SPACE_OR_TAB, NEWLINE values from lexical_feedback::whitespace_type enum. When result of eat_continuation is used as a logical test for whitespace or no whitespace, compare to lexical_feedback::NO_WHITESPACE to produce bool value.
author John W. Eaton <jwe@octave.org>
date Mon, 25 Feb 2013 23:48:32 -0500
parents b7de58feb2d3
children 7302f8a4df83
comparison
equal deleted inserted replaced
16105:b7de58feb2d3 16106:031117f4db7c
220 // one of the macros defined there uses token_stack. 220 // one of the macros defined there uses token_stack.
221 // 221 //
222 // FIXME -- this should really be static, but that causes 222 // FIXME -- this should really be static, but that causes
223 // problems on some systems. 223 // problems on some systems.
224 std::stack <token*> token_stack; 224 std::stack <token*> token_stack;
225
226 // Did eat_whitespace() eat a space or tab, or a newline, or both?
227
228 typedef int yum_yum;
229
230 const yum_yum ATE_NOTHING = 0;
231 const yum_yum ATE_SPACE_OR_TAB = 1;
232 const yum_yum ATE_NEWLINE = 2;
233 225
234 static bool Vdisplay_tokens = false; 226 static bool Vdisplay_tokens = false;
235 227
236 static unsigned int Vtoken_count = 0; 228 static unsigned int Vtoken_count = 0;
237 229
259 static int handle_meta_identifier (void); 251 static int handle_meta_identifier (void);
260 static int handle_identifier (void); 252 static int handle_identifier (void);
261 static bool have_continuation (bool trailing_comments_ok = true); 253 static bool have_continuation (bool trailing_comments_ok = true);
262 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); 254 static bool have_ellipsis_continuation (bool trailing_comments_ok = true);
263 static void scan_for_comments (const char *); 255 static void scan_for_comments (const char *);
264 static yum_yum eat_whitespace (void); 256 static int eat_whitespace (void);
265 static yum_yum eat_continuation (void); 257 static int eat_continuation (void);
266 static int octave_read (char *buf, unsigned int max_size); 258 static int octave_read (char *buf, unsigned int max_size);
267 static void maybe_warn_separator_insert (char sep); 259 static void maybe_warn_separator_insert (char sep);
268 static void gripe_single_quote_string (void); 260 static void gripe_single_quote_string (void);
269 static void gripe_matlab_incompatible (const std::string& msg); 261 static void gripe_matlab_incompatible (const std::string& msg);
270 static void maybe_gripe_matlab_incompatible_comment (char c); 262 static void maybe_gripe_matlab_incompatible_comment (char c);
394 386
395 lexer_flags.looking_for_object_index = true; 387 lexer_flags.looking_for_object_index = true;
396 lexer_flags.at_beginning_of_statement = false; 388 lexer_flags.at_beginning_of_statement = false;
397 389
398 int c = yytext[yyleng-1]; 390 int c = yytext[yyleng-1];
399 int cont_is_spc = eat_continuation (); 391 bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE);
400 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); 392 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t');
401 int tok_to_return = handle_close_bracket (spc_gobbled, ']'); 393 int tok_to_return = handle_close_bracket (spc_gobbled, ']');
402 394
403 if (spc_gobbled) 395 if (spc_gobbled)
404 xunput (' ', yytext); 396 xunput (' ', yytext);
420 412
421 lexer_flags.looking_for_object_index = true; 413 lexer_flags.looking_for_object_index = true;
422 lexer_flags.at_beginning_of_statement = false; 414 lexer_flags.at_beginning_of_statement = false;
423 415
424 int c = yytext[yyleng-1]; 416 int c = yytext[yyleng-1];
425 int cont_is_spc = eat_continuation (); 417 bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE);
426 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); 418 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t');
427 int tok_to_return = handle_close_bracket (spc_gobbled, '}'); 419 int tok_to_return = handle_close_bracket (spc_gobbled, '}');
428 420
429 if (spc_gobbled) 421 if (spc_gobbled)
430 xunput (' ', yytext); 422 xunput (' ', yytext);
450 lexer_flags.looking_for_object_index = false; 442 lexer_flags.looking_for_object_index = false;
451 lexer_flags.at_beginning_of_statement = false; 443 lexer_flags.at_beginning_of_statement = false;
452 444
453 if (! lexer_flags.looking_at_object_index.front ()) 445 if (! lexer_flags.looking_at_object_index.front ())
454 { 446 {
455 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) 447 if ((tmp & lexical_feedback::NEWLINE) == lexical_feedback::NEWLINE)
456 { 448 {
457 maybe_warn_separator_insert (';'); 449 maybe_warn_separator_insert (';');
458 450
459 xunput (';', yytext); 451 xunput (';', yytext);
460 } 452 }
487 479
488 if (! (postfix_un_op || bin_op || sep_op) 480 if (! (postfix_un_op || bin_op || sep_op)
489 && lexer_flags.nesting_level.is_bracket_or_brace () 481 && lexer_flags.nesting_level.is_bracket_or_brace ()
490 && lexer_flags.convert_spaces_to_comma) 482 && lexer_flags.convert_spaces_to_comma)
491 { 483 {
492 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) 484 if ((tmp & lexical_feedback::NEWLINE) == lexical_feedback::NEWLINE)
493 { 485 {
494 maybe_warn_separator_insert (';'); 486 maybe_warn_separator_insert (';');
495 487
496 xunput (';', yytext); 488 xunput (';', yytext);
497 } 489 }
1029 // that we insert a comma ahead of it. 1021 // that we insert a comma ahead of it.
1030 1022
1031 void 1023 void
1032 do_comma_insert_check (void) 1024 do_comma_insert_check (void)
1033 { 1025 {
1034 int spc_gobbled = eat_continuation (); 1026 bool spc_gobbled = (eat_continuation () != lexical_feedback::NO_WHITESPACE);
1035 1027
1036 int c = text_yyinput (); 1028 int c = text_yyinput ();
1037 1029
1038 xunput (c, yytext); 1030 xunput (c, yytext);
1039 1031
2209 if (! comment_buf.empty ()) 2201 if (! comment_buf.empty ())
2210 octave_comment_buffer::append (comment_buf); 2202 octave_comment_buffer::append (comment_buf);
2211 } 2203 }
2212 2204
2213 // Discard whitespace, including comments and continuations. 2205 // Discard whitespace, including comments and continuations.
2214 //
2215 // Return value is logical OR of the following values:
2216 //
2217 // ATE_NOTHING : no spaces to eat
2218 // ATE_SPACE_OR_TAB : space or tab in input
2219 // ATE_NEWLINE : bare new line in input
2220 2206
2221 // FIXME -- we need to handle block comments here. 2207 // FIXME -- we need to handle block comments here.
2222 2208
2223 static yum_yum 2209 static int
2224 eat_whitespace (void) 2210 eat_whitespace (void)
2225 { 2211 {
2226 yum_yum retval = ATE_NOTHING; 2212 int retval = lexical_feedback::NO_WHITESPACE;
2227 2213
2228 std::string comment_buf; 2214 std::string comment_buf;
2229 2215
2230 bool in_comment = false; 2216 bool in_comment = false;
2231 bool beginning_of_comment = false; 2217 bool beginning_of_comment = false;
2243 if (in_comment) 2229 if (in_comment)
2244 { 2230 {
2245 comment_buf += static_cast<char> (c); 2231 comment_buf += static_cast<char> (c);
2246 beginning_of_comment = false; 2232 beginning_of_comment = false;
2247 } 2233 }
2248 retval |= ATE_SPACE_OR_TAB; 2234 retval |= lexical_feedback::SPACE_OR_TAB;
2249 break; 2235 break;
2250 2236
2251 case '\n': 2237 case '\n':
2252 retval |= ATE_NEWLINE; 2238 retval |= lexical_feedback::NEWLINE;
2253 if (in_comment) 2239 if (in_comment)
2254 { 2240 {
2255 comment_buf += static_cast<char> (c); 2241 comment_buf += static_cast<char> (c);
2256 octave_comment_buffer::append (comment_buf); 2242 octave_comment_buffer::append (comment_buf);
2257 comment_buf.resize (0); 2243 comment_buf.resize (0);
2500 return false; 2486 return false;
2501 } 2487 }
2502 2488
2503 // See if we have a continuation line. If so, eat it and the leading 2489 // See if we have a continuation line. If so, eat it and the leading
2504 // whitespace on the next line. 2490 // whitespace on the next line.
2505 // 2491
2506 // Return value is the same as described for eat_whitespace(). 2492 static int
2507
2508 static yum_yum
2509 eat_continuation (void) 2493 eat_continuation (void)
2510 { 2494 {
2511 int retval = ATE_NOTHING; 2495 int retval = lexical_feedback::NO_WHITESPACE;
2512 2496
2513 int c = text_yyinput (); 2497 int c = text_yyinput ();
2514 2498
2515 if ((c == '.' && have_ellipsis_continuation ()) 2499 if ((c == '.' && have_ellipsis_continuation ())
2516 || (c == '\\' && have_continuation ())) 2500 || (c == '\\' && have_continuation ()))
3163 3147
3164 std::string tok = strip_trailing_whitespace (yytext); 3148 std::string tok = strip_trailing_whitespace (yytext);
3165 3149
3166 int c = yytext[yyleng-1]; 3150 int c = yytext[yyleng-1];
3167 3151
3168 int cont_is_spc = eat_continuation (); 3152 bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE);
3169 3153
3170 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); 3154 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t');
3171 3155
3172 // If we are expecting a structure element, avoid recognizing 3156 // If we are expecting a structure element, avoid recognizing
3173 // keywords and other special names and return STRUCT_ELT, which is 3157 // keywords and other special names and return STRUCT_ELT, which is