BIND 10 #2372: define State class for MasterLexer, base part

BIND 10 Development do-not-reply at isc.org
Fri Oct 19 06:35:26 UTC 2012


#2372: define State class for MasterLexer, base part
-------------------------------------+-------------------------------------
            Reporter:  jinmei        |                        Owner:
                Type:  task          |  UnAssigned
            Priority:  medium        |                       Status:  new
           Component:  libdns++      |                    Milestone:  New
           Sensitive:  0             |  Tasks
         Sub-Project:  DNS           |                     Keywords:
Estimated Difficulty:  0             |              Defect Severity:  N/A
         Total Hours:  0             |  Feature Depending on Ticket:
                                     |  loadzone-ng
                                     |          Add Hours to Ticket:  0
                                     |                    Internal?:  0
-------------------------------------+-------------------------------------
 Subtask of #2368.  See #2371.  This defines the state class
 of `MasterLexer`.

 It's essentially private to `MasterLexer`, but we want to test them
 directly, so define it as semi-public, in the master_lexer_internal
 namespace.

 For the state transition, first understand the overall logic flow
 of BIND 9's isc_lex_gettoken().  Attached drawing may also help.

 This is the base class of the state.  We'll have the following
 derived classes.

 {{{#!cpp
 class master_lexer_internal::State {
     // correspond specific state and derived class.
     enum ID { Start, CRLF, String, QuotedString, Number, EatLine, Done };

     // Handle the current state, and return next state.  'Done' class
     // throws.
     virtual State* handle(MasterLexer& lexer) const = 0;

     // Return whether state transition is completed.  By default false,
     // only 'Done' class returns true.
     virtual bool isCompleted() const { return (false); }

     // We use singleton instances.  This returns pre-generated instance.
     static State* getInstance(ID id);
 };
 }}}

 In this ticket, we define the base class and Start, CRLF, EatLine, and
 Done classes.  For details of the state transition, see
 isc_lex_gettoken().  Sample implementation of Start is like this:

 {{{#!cpp
 class MasterLexer::Start : public MasterLexerState {
     virtual void handle(MasterLexer& lexer) const {
         const int c = lexer.source->getNextChar();
         if (lexer.isCommentStart(lexer, c, this)) {
             return (State::getInstance(EAT_LINE));
         }
         if (c == EOF) {
             lexer.last_was_eol_ = false;
             return (State::getInstance(DONE));
         }
         if (c == '\r') {
             return (State::getInstance(CRLF));
         }
         if (isdigit(c)) {
             lexer.last_was_eol_ = false;
             return (State::getInstance(NUMBER));
         }
         // and so on
     }
 };
 }}}

-- 
Ticket URL: <http://bind10.isc.org/ticket/2372>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development


More information about the bind10-tickets mailing list