comparison libinterp/parse-tree/lex.h @ 17693:efbe746f8fa8

eliminate octave_comment_buffer singleton * lex.h (octave_base_lexer::comment_buffer): New class adapted from octave_comment_buffer class. No longer a singleton class. (octave_base_lexer::comment_buffer::reset): New function. (octave_base_lexer::reset): Call comment_buf.reset. (octave_base_lexer::comment_buf): New data member. (octave_base_lexer::get_comment): New function. * comment-list.h, comment-list.cc (octave_comment_buffer): Delete. Change all uses of octave_comment_buffer to use local comment_buf object instead. * parse.h (octave_base_parser::make_statement): New member function. * oct-parse.in.yy (make_statement): Delete. Change all uses of make_statement to use the member function instead. (safe_fclose): Don't extract and delete comment list here.
author John W. Eaton <jwe@octave.org>
date Fri, 18 Oct 2013 21:00:33 -0400
parents 531473481084
children f79bf671a493
comparison
equal deleted inserted replaced
17692:38cf56b77274 17693:efbe746f8fa8
491 const char *pos; 491 const char *pos;
492 size_t chars_left; 492 size_t chars_left;
493 bool eof; 493 bool eof;
494 }; 494 };
495 495
496 // Collect comment text.
497
498 class
499 comment_buffer
500 {
501 public:
502
503 comment_buffer (void) : comment_list (0) { }
504
505 ~comment_buffer (void) { delete comment_list; }
506
507 void append (const std::string& s, octave_comment_elt::comment_type t)
508 {
509 if (! comment_list)
510 comment_list = new octave_comment_list ();
511
512 comment_list->append (s, t);
513 }
514
515 // Caller is expected to delete the returned value.
516
517 octave_comment_list *get_comment (void)
518 {
519 octave_comment_list *retval = comment_list;
520
521 comment_list = 0;
522
523 return retval;
524 }
525
526 void reset (void)
527 {
528 delete comment_list;
529
530 comment_list = 0;
531 }
532
533 private:
534
535 octave_comment_list *comment_list;
536 };
537
496 octave_base_lexer (void) 538 octave_base_lexer (void)
497 : lexical_feedback (), scanner (0), input_buf () 539 : lexical_feedback (), scanner (0), input_buf (), comment_buf ()
498 { 540 {
499 init (); 541 init ();
500 } 542 }
501 543
502 virtual ~octave_base_lexer (void); 544 virtual ~octave_base_lexer (void);
542 void handle_number (void); 584 void handle_number (void);
543 585
544 void handle_continuation (void); 586 void handle_continuation (void);
545 587
546 void finish_comment (octave_comment_elt::comment_type typ); 588 void finish_comment (octave_comment_elt::comment_type typ);
589
590 octave_comment_list *get_comment (void) { return comment_buf.get_comment (); }
547 591
548 int handle_close_bracket (int bracket_type); 592 int handle_close_bracket (int bracket_type);
549 593
550 bool looks_like_command_arg (void); 594 bool looks_like_command_arg (void);
551 595
580 // Internal state of the flex-generated lexer. 624 // Internal state of the flex-generated lexer.
581 void *scanner; 625 void *scanner;
582 626
583 // Object that reads and buffers input. 627 // Object that reads and buffers input.
584 input_buffer input_buf; 628 input_buffer input_buf;
629
630 // Object that collects comment text.
631 comment_buffer comment_buf;
585 632
586 virtual void increment_promptflag (void) = 0; 633 virtual void increment_promptflag (void) = 0;
587 634
588 virtual void decrement_promptflag (void) = 0; 635 virtual void decrement_promptflag (void) = 0;
589 636