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

BIND 10 Development do-not-reply at isc.org
Sat Oct 20 16:35:01 UTC 2012


#2372: define State class for MasterLexer, base part
-------------------------------------+-------------------------------------
                   Reporter:         |                 Owner:  UnAssigned
  jinmei                             |                Status:  new
                       Type:  task   |             Milestone:  New Tasks
                   Priority:         |            Resolution:
  medium                             |             Sensitive:  0
                  Component:         |           Sub-Project:  DNS
  libdns++                           |  Estimated Difficulty:  0
                   Keywords:         |           Total Hours:  0
            Defect Severity:  N/A    |
Feature Depending on Ticket:         |
  loadzone-ng                        |
        Add Hours to Ticket:  0      |
                  Internal?:  0      |
-------------------------------------+-------------------------------------
Description changed by jinmei:

Old description:

> Subtask of #2368.  See #2371.  This defines the state class
> of `MasterLexer`.  To test this, we'll probably need to introduce a
> base class of `MasterLexer` or template (that way, this task is
> mostly dependency free).
>
> 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
>     }
> };
> }}}

New description:

 Subtask of #2368.  See #2371.  This defines the state class
 of `MasterLexer`.  To test this, we'll probably need to introduce a
 base class of `MasterLexer` or template (that way, this task is
 mostly dependency free).

 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 derived classes
 corresponding to the "ID" enum shown below.

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

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

     // 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 (others will also have to be defined with empty content for
 testing).  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;
             lexer.token_ = MasterToken(EOF);
             return (NULL); // "DONE"
         }
         if (c == '\r') {
             return (State::getInstance(CRLF));
         }
         if (isdigit(c)) {
             lexer.last_was_eol_ = false;
             return (State::getInstance(NUMBER));
         }
         // and so on
     }
 };
 }}}

 Further, add implementation of `MasterLexer::isCommentStart()`.  It
 corresponds to the following part of BIND 9:
 {{{#!c
                 if (lex->comment_ok && !no_comments) {
                         if (!escaped && c == ';' &&
                             ((lex->comments &
 ISC_LEXCOMMENT_DNSMASTERFILE)
                              != 0)) {
                                 saved_state = state;
                                 state = lexstate_eatline;
                                 no_comments = ISC_TRUE;
                                 continue;
                         } else if {
                         } else if {
                         }
                 }
 }}}
 (we don't need the else-if part.  Check for
 ISC_LEXCOMMENT_DNSMASTERFILE isn't necessary either; we only handle
 that case.  we can assume comment_ok is always true).

--

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


More information about the bind10-tickets mailing list