comparison libinterp/parse-tree/lex.ll @ 16254:b8a2df776118 classdef

maint: periodic merge of default to classdef
author John W. Eaton <jwe@octave.org>
date Mon, 11 Mar 2013 14:04:05 -0400
parents d8c0f46efaf0 a89cf57ba3a5
children b28062b977fd
comparison
equal deleted inserted replaced
16252:6a3c6c921daa 16254:b8a2df776118
483 %} 483 %}
484 484
485 ^{S}*{CCHAR}\{{S}*{NL} { 485 ^{S}*{CCHAR}\{{S}*{NL} {
486 curr_lexer->lexer_debug ("^{S}*{CCHAR}\{{S}*{NL}"); 486 curr_lexer->lexer_debug ("^{S}*{CCHAR}\{{S}*{NL}");
487 487
488 int tok = 0; 488 yyless (0);
489 489
490 if (curr_lexer->start_state () == LINE_COMMENT_START) 490 if (curr_lexer->start_state () == LINE_COMMENT_START)
491 { 491 {
492 if (! curr_lexer->comment_text.empty ()) 492 if (! curr_lexer->comment_text.empty ())
493 tok = curr_lexer->finish_comment (octave_comment_elt::full_line); 493 curr_lexer->finish_comment (octave_comment_elt::full_line);
494 494
495 curr_lexer->pop_start_state (); 495 curr_lexer->pop_start_state ();
496 } 496 }
497 497
498 curr_lexer->push_start_state (BLOCK_COMMENT_START); 498 curr_lexer->push_start_state (BLOCK_COMMENT_START);
499 499
500 yyless (0);
501
502 if (tok > 0)
503 return curr_lexer->count_token (tok);
504 } 500 }
505 501
506 <BLOCK_COMMENT_START>^{S}*{CCHAR}\{{S}*{NL} { 502 <BLOCK_COMMENT_START>^{S}*{CCHAR}\{{S}*{NL} {
507 curr_lexer->lexer_debug ("<BLOCK_COMMENT_START>^{S}*{CCHAR}\{{S}*{NL}"); 503 curr_lexer->lexer_debug ("<BLOCK_COMMENT_START>^{S}*{CCHAR}\{{S}*{NL}");
508 504
525 curr_lexer->lexer_debug ("<BLOCK_COMMENT_START>^{S}*{CCHAR}\\}{S}*{NL}"); 521 curr_lexer->lexer_debug ("<BLOCK_COMMENT_START>^{S}*{CCHAR}\\}{S}*{NL}");
526 522
527 curr_lexer->input_line_number++; 523 curr_lexer->input_line_number++;
528 curr_lexer->current_input_column = 1; 524 curr_lexer->current_input_column = 1;
529 525
530 int tok = 0;
531
532 if (curr_lexer->block_comment_nesting_level > 1) 526 if (curr_lexer->block_comment_nesting_level > 1)
533 curr_lexer->comment_text = "\n"; 527 curr_lexer->comment_text = "\n";
534 else 528 else
535 tok = curr_lexer->finish_comment (octave_comment_elt::block); 529 curr_lexer->finish_comment (octave_comment_elt::block);
536 530
537 curr_lexer->block_comment_nesting_level--; 531 curr_lexer->block_comment_nesting_level--;
538 curr_lexer->pop_start_state (); 532 curr_lexer->pop_start_state ();
539
540 if (tok > 0)
541 return curr_lexer->count_token (tok);
542 } 533 }
543 534
544 %{ 535 %{
545 // Body of a block comment. 536 // Body of a block comment.
546 %} 537 %}
582 break; 573 break;
583 } 574 }
584 575
585 curr_lexer->comment_text += &yytext[i]; 576 curr_lexer->comment_text += &yytext[i];
586 577
587 int tok = 0;
588
589 if (! full_line_comment) 578 if (! full_line_comment)
590 { 579 {
591 tok = curr_lexer->finish_comment (octave_comment_elt::end_of_line); 580 curr_lexer->finish_comment (octave_comment_elt::end_of_line);
592 581
593 curr_lexer->pop_start_state (); 582 curr_lexer->pop_start_state ();
594
595 if (curr_lexer->start_state () == COMMAND_START)
596 {
597 // Allow the actions for the end of a COMMAND line to be
598 // executed next.
599
600 tok = 0;
601 curr_lexer->xunput ('\n');
602 }
603 } 583 }
604
605 if (tok > 0)
606 return curr_lexer->count_token (tok);
607 } 584 }
608 585
609 %{ 586 %{
610 // End of a block of full-line comments. 587 // End of a block of full-line comments.
611 %} 588 %}
613 <LINE_COMMENT_START>{ANY_INCLUDING_NL} { 590 <LINE_COMMENT_START>{ANY_INCLUDING_NL} {
614 curr_lexer->lexer_debug ("<LINE_COMMENT_START>{ANY_INCLUDING_NL}"); 591 curr_lexer->lexer_debug ("<LINE_COMMENT_START>{ANY_INCLUDING_NL}");
615 592
616 curr_lexer->xunput (yytext[0]); 593 curr_lexer->xunput (yytext[0]);
617 594
618 int tok = curr_lexer->finish_comment (octave_comment_elt::full_line); 595 curr_lexer->finish_comment (octave_comment_elt::full_line);
619 596
620 curr_lexer->pop_start_state (); 597 curr_lexer->pop_start_state ();
621
622 if (tok > 0)
623 return curr_lexer->count_token (tok);
624 } 598 }
625 599
626 %{ 600 %{
627 // Imaginary numbers. 601 // Imaginary numbers.
628 %} 602 %}
658 %{ 632 %{
659 // Continuation lines. Allow comments after continuations. 633 // Continuation lines. Allow comments after continuations.
660 %} 634 %}
661 635
662 {CONT}{S}*{NL} | 636 {CONT}{S}*{NL} |
663 {CONT}{S}*{COMMENT} { 637 {CONT}{S}*{CCHAR}.*{NL} {
664 curr_lexer->lexer_debug ("{CONT}{S}*{NL}|{CONT}{S}*{COMMENT}"); 638 curr_lexer->lexer_debug ("{CONT}{S}*{NL}|{CONT}{S}*{CCHAR}.*{NL}");
665 639
666 if (yytext[0] == '\\') 640 curr_lexer->handle_continuation ();
667 curr_lexer->gripe_matlab_incompatible_continuation ();
668 curr_lexer->scan_for_comments (yytext);
669 curr_lexer->decrement_promptflag ();
670 curr_lexer->input_line_number++;
671 curr_lexer->current_input_column = 1;
672 } 641 }
673 642
674 %{ 643 %{
675 // End of file. 644 // End of file.
676 %} 645 %}
1415 } 1384 }
1416 1385
1417 return retval; 1386 return retval;
1418 } 1387 }
1419 1388
1420 int
1421 lexical_feedback::finish_comment (octave_comment_elt::comment_type typ)
1422 {
1423 bool copyright = looks_like_copyright (comment_text);
1424
1425 if (nesting_level.none () && help_text.empty ()
1426 && ! comment_text.empty () && ! copyright)
1427 help_text = comment_text;
1428
1429 if (copyright)
1430 typ = octave_comment_elt::copyright;
1431
1432 octave_comment_buffer::append (comment_text, typ);
1433
1434 comment_text = "";
1435
1436 quote_is_transpose = false;
1437 convert_spaces_to_comma = true;
1438 at_beginning_of_statement = true;
1439
1440 if (nesting_level.none ())
1441 return '\n';
1442 else if (nesting_level.is_bracket_or_brace ())
1443 // FIXME -- this result will be different if the comment follows a
1444 // continuation token.
1445 return ';';
1446 else
1447 return 0;
1448 }
1449
1450 void 1389 void
1451 octave_lexer::input_buffer::fill (const std::string& input, bool eof_arg) 1390 octave_lexer::input_buffer::fill (const std::string& input, bool eof_arg)
1452 { 1391 {
1453 buffer = input; 1392 buffer = input;
1454 chars_left = buffer.length (); 1393 chars_left = buffer.length ();
2352 current_input_column)); 2291 current_input_column));
2353 2292
2354 current_input_column += flex_yyleng (); 2293 current_input_column += flex_yyleng ();
2355 2294
2356 do_comma_insert_check (); 2295 do_comma_insert_check ();
2296 }
2297
2298 void
2299 octave_lexer::handle_continuation (void)
2300 {
2301 char *yytxt = flex_yytext ();
2302 int yylng = flex_yyleng ();
2303
2304 size_t offset = 1;
2305 if (yytxt[0] == '\\')
2306 gripe_matlab_incompatible_continuation ();
2307 else
2308 offset = 3;
2309
2310 bool have_space = false;
2311 while (offset < yylng)
2312 {
2313 char c = yytxt[offset];
2314 if (c == ' ' || c == '\t')
2315 {
2316 have_space = true;
2317 offset++;
2318 }
2319 else
2320 break;
2321 }
2322
2323 bool have_comment = false;
2324 while (offset < yylng)
2325 {
2326 char c = yytxt[offset];
2327 if (c == '#' || c == '%')
2328 {
2329 have_comment = true;
2330 offset++;
2331 }
2332 else
2333 break;
2334 }
2335
2336 if (have_comment)
2337 {
2338 comment_text = &yytxt[offset];
2339
2340 finish_comment (octave_comment_elt::end_of_line, true);
2341 }
2342
2343 decrement_promptflag ();
2344 input_line_number++;
2345 current_input_column = 1;
2346 }
2347
2348 void
2349 octave_lexer::finish_comment (octave_comment_elt::comment_type typ,
2350 bool looking_at_continuation)
2351 {
2352 bool copyright = looks_like_copyright (comment_text);
2353
2354 if (nesting_level.none () && help_text.empty ()
2355 && ! comment_text.empty () && ! copyright)
2356 help_text = comment_text;
2357
2358 if (copyright)
2359 typ = octave_comment_elt::copyright;
2360
2361 octave_comment_buffer::append (comment_text, typ);
2362
2363 comment_text = "";
2364
2365 quote_is_transpose = false;
2366 convert_spaces_to_comma = true;
2367 at_beginning_of_statement = true;
2368
2369 if (! looking_at_continuation)
2370 xunput ('\n');
2357 } 2371 }
2358 2372
2359 // We have seen a backslash and need to find out if it should be 2373 // We have seen a backslash and need to find out if it should be
2360 // treated as a continuation character. If so, this eats it, up to 2374 // treated as a continuation character. If so, this eats it, up to
2361 // and including the new line character. 2375 // and including the new line character.