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

BIND 10 Development do-not-reply at isc.org
Tue Nov 6 06:10:10 UTC 2012


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

Comment (by jinmei):

 trac2372 is ready for review.

 I ended up slightly different implementation than what was proposed in
 the ticket description, mainly:
 - there's no explicit "Start" state.  The first transition from the
   imaginary "start"  is done in the static method `State::start()`.
 - there's no `EatLine` state.  This state was intended to skip all
   comments toward the end-of-line or end-of-file, but I found it
   simpler to implement this transition as an ordinary helper method.

 The proposed `isCommentStart()` method was unified to the imaginary
 `EatLine` state and implemented as `MasterLexerImpl::skipComment()`.

 The major part of this branch other than the basic concept is the
 `State::start()` method.  It's basically a straightforward port of
 the corresponding part of BIND 9's lex.c:isc_lex_gettoken():
 {{{#!c
                 switch (state) {
                 case lexstate_start:
                         if (c == EOF) {
 ...
                         } else {
                                 lex->last_was_eol = ISC_FALSE;
                                 state = lexstate_string;
                                 goto no_read;
                         }
                         break;
 }}}
 (and the comment handling above the switch).  But I found it could be
 much simplified (and hopefully more readable/understandable), so I
 refactored several things:

 - The BIND 9 version keeps the original option and restores it after
   closing all parentheses.  After a closer look at it I found it
   wasn't necessary: we can control that based on the value of
   "paren_count", and behave differently whether we are in a pair of
   parentheses.
 - Likewise, I found we didn't need to keep the original state before
   starting comment handling and restore it after that, because we now
   don't change the state for comment handling.
 - For the same reason, we don't need the "no_comments" variable.

 The branch also contains the state transition from the "CRLF" state,
 which should be a more straightforward port and easy to understand.

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


More information about the bind10-tickets mailing list