comparison src/lex.l @ 4241:71209cc7ad4a

[project @ 2002-12-26 00:24:10 by jwe]
author jwe
date Thu, 26 Dec 2002 00:24:10 +0000
parents 8627d992beb8
children eef64f3f9a4c
comparison
equal deleted inserted replaced
4240:8627d992beb8 4241:71209cc7ad4a
2518 current_input_column += yyleng; 2518 current_input_column += yyleng;
2519 2519
2520 return NAME; 2520 return NAME;
2521 } 2521 }
2522 2522
2523 // Print a warning if a function file that defines a function has
2524 // anything other than comments and whitespace following the END token
2525 // that matches the FUNCTION statement.
2526
2527 void
2528 check_for_garbage_after_fcn_def (void)
2529 {
2530 // By making a newline be the next character to be read, we will
2531 // force the parser to return after reading the function. Calling
2532 // unput with EOF does not work.
2533
2534 std::string comment_buf;
2535
2536 bool in_comment = false;
2537 bool beginning_of_comment = true;
2538
2539 int lineno = input_line_number;
2540
2541 int c = 0;
2542
2543 while ((c = yyinput ()) != EOF)
2544 {
2545 switch (c)
2546 {
2547 case ' ':
2548 case '\t':
2549 case ';':
2550 case ',':
2551 if (in_comment)
2552 {
2553 comment_buf += static_cast<char> (c);
2554 beginning_of_comment = false;
2555 }
2556 break;
2557
2558 case '%':
2559 case '#':
2560 if (in_comment)
2561 {
2562 if (! beginning_of_comment)
2563 comment_buf += static_cast<char> (c);
2564 }
2565 else
2566 {
2567 maybe_gripe_matlab_incompatible_comment (c);
2568 in_comment = true;
2569 beginning_of_comment = true;
2570 }
2571 break;
2572
2573 case '\n':
2574 if (in_comment)
2575 {
2576 comment_buf += static_cast<char> (c);
2577 octave_comment_buffer::append (comment_buf);
2578 comment_buf.resize (0);
2579 in_comment = false;
2580 beginning_of_comment = false;
2581 }
2582 break;
2583
2584 case '\r':
2585 if (in_comment)
2586 comment_buf += static_cast<char> (c);
2587 c = yyinput ();
2588 if (c == EOF)
2589 break;
2590 else if (c == '\n')
2591 {
2592 if (in_comment)
2593 {
2594 comment_buf += static_cast<char> (c);
2595 octave_comment_buffer::append (comment_buf);
2596 comment_buf.resize (0);
2597 in_comment = false;
2598 beginning_of_comment = false;
2599 }
2600 break;
2601 }
2602
2603 // Fall through...
2604
2605 default:
2606 if (in_comment)
2607 {
2608 comment_buf += static_cast<char> (c);
2609 beginning_of_comment = false;
2610 break;
2611 }
2612 else
2613 {
2614 warning ("ignoring trailing garbage after end of function\n\
2615 near line %d of file `%s.m'", lineno, curr_fcn_file_name.c_str ());
2616
2617 unput ('\n');
2618 return;
2619 }
2620 }
2621 }
2622
2623 if (! comment_buf.empty ())
2624 octave_comment_buffer::append (comment_buf);
2625
2626 unput ('\n');
2627 }
2628
2629 void 2523 void
2630 lexical_feedback::init (void) 2524 lexical_feedback::init (void)
2631 { 2525 {
2632 // Not initially defining a matrix list. 2526 // Not initially defining a matrix list.
2633 bracketflag = 0; 2527 bracketflag = 0;