BIND 10 #2369: InputSource helper class for MasterLexer
BIND 10 Development
do-not-reply at isc.org
Fri Oct 19 05:44:38 UTC 2012
#2369: InputSource helper class for MasterLexer
-------------------------------------+-------------------------------------
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, no dependency.
This is a helper internal class for `MasterLexer`, and represents
state of a single source of the entire zone data to be parsed.
Normally this means the master zone file, but `MasterLexer` can
have multiple `InputSource`s if $INCLUDE is used. The source can
also be generic input stream (std::istream).
This is a port of BIND 9's lib/isc/lex.c:inputsource{}, but is defined
as a separate class to improve data integrity and testability.
It's essentially private to `MasterLexer`, but we'll define it in
a semi-public header file (not installed) so tests can directly refer
to the definition. To clarify it's not really public, define it some
specific sub-namespace, like master_lexer_internal.
A tentative class definition is:
{{{#!cpp
namespace master_lexer_internal {
class InputSource {
public:
InputSource(std::istream& input, const std::string& name);
// if buffer_ is empty, read 1 byte from input_, push_back it to
buffer_.
// extract c = buffer_[buffer_pos_], ++buffer_pos_, return c.
// EOF case is a bit tricky. See BIND 9's lex.c.
int getNextChar();
// "forget" the most recent character, c (decrease buffer_pos_ by 1).
// doesn't touch buffer_. if c == EOF, just reset at_eof_ to false.
// if c == '\n' decrease line_ by 1.
void ungetChar(int c);
// "forget" everything in the buffer_. set buffer_pos_ to 0.
// doesn't touch buffer_. set at_eof to false. line_ = saved_line_.
void ungetAll();
bool isAtEOF() const { return (at_eof_); }
size_t getCurrentLine() const { return (line_); }
void saveLine() { saved_line_ = line_; }
const std::string name_; // filename or "stream-%p"
private:
size_t line_; // current line number in this source
(file)
size_t saved_line_; // lexer save line_ when it starts using the
source
bool at_eof_; // set to true if lexer reaches the "end of file" of
this src
std::istream& input_; // given via the constructor
// temporary copy of data read from input_
vector<char> buffer_;
// normally == buffer_.size(), but can be smaller if ungetChar() or
// ungetAll() is called.
size_t buffer_pos_;
};
}
}}}
--
Ticket URL: <http://bind10.isc.org/ticket/2369>
BIND 10 Development <http://bind10.isc.org>
BIND 10 Development
More information about the bind10-tickets
mailing list