17#include <boost/noncopyable.hpp>
18#include <boost/shared_ptr.hpp>
22namespace master_lexer_internal {
109 "called with invalid type: " << type);
128 MasterToken(
const char* str_beg,
size_t str_len,
bool quoted =
false) :
130 val_.str_region_.beg = str_beg;
131 val_.str_region_.len = str_len;
139 val_.number_ = number;
151 val_.error_code_ = error_code;
169 "Token::getStringRegion() for non string-variant type");
171 return (val_.str_region_);
210 "Token::getString() for non string-variant type");
212 ret.assign(val_.str_region_.beg,
213 val_.str_region_.beg + val_.str_region_.len);
223 "Token::getNumber() for non number type");
225 return (val_.number_);
233 if (type_ !=
ERROR) {
235 "Token::getErrorCode() for non error type");
237 return (val_.error_code_);
325 isc::dns::
Exception(file, line, error_token.getErrorText().c_str()),
387 bool pushSource(
const char* filename, std::string* error = 0);
640 bool eol_ok =
false);
660 struct MasterLexerImpl;
661 boost::shared_ptr<MasterLexerImpl> impl_;
671 static_cast<unsigned>(o1) |
static_cast<unsigned>(o2)));
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
Exception thrown from a wrapper version of MasterLexer::getNextToken() for non fatal errors.
LexerError(const char *file, size_t line, MasterToken error_token)
Exception thrown when we fail to read from the input stream or file.
ReadError(const char *file, size_t line, const char *what)
Tokenizer for parsing DNS master files.
Options
Options for getNextToken.
@ QSTRING
recognize quoted string
@ NUMBER
recognize numeric text as integer
@ INITIAL_WS
recognize begin-of-line spaces after an end-of-line
MasterLexer()
The constructor.
void ungetToken()
Return the last token back to the lexer.
size_t getSourceCount() const
Get number of sources inside the lexer.
bool pushSource(const char *filename, std::string *error=0)
Open a file and make it the current input source of MasterLexer.
size_t getTotalSourceSize() const
Return the total size of pushed sources.
std::string getSourceName() const
Return the name of the current input source name.
const MasterToken & getNextToken(Options options=NONE)
Parse and return another token from the input.
const MasterToken & getNextToken(MasterToken::Type expect, bool eol_ok=false)
Parse the input for the expected type of token.
size_t getPosition() const
Return the position of lexer in the pushed sources so far.
void popSource()
Stop using the most recently opened input source (file or stream).
void pushSource(std::istream &input)
Make the given stream the current input source of MasterLexer.
~MasterLexer()
The destructor.
static const size_t SOURCE_SIZE_UNKNOWN
Special value for input source size meaning "unknown".
size_t getSourceLine() const
Return the input source line number.
MasterToken(ErrorCode error_code)
Constructor for error type of token.
ErrorCode getErrorCode() const
Return the error code of a error type token.
ErrorCode
Enumeration for lexer error codes.
@ NO_TOKEN_PRODUCED
No token was produced.
@ UNEXPECTED_END
The lexer reaches the end of line or file unexpectedly.
@ BAD_NUMBER
Number is expected but not recognized.
@ NOT_STARTED
The lexer is just initialized and has no token.
@ MAX_ERROR_CODE
Max integer corresponding to valid error codes.
@ NUMBER_OUT_OF_RANGE
Number was out of range.
@ UNBALANCED_PAREN
Unbalanced parentheses detected.
@ UNBALANCED_QUOTES
Unbalanced quotations detected.
@ UNEXPECTED_QUOTES
Unexpected quotes character detected.
MasterToken(const char *str_beg, size_t str_len, bool quoted=false)
Constructor for string and quoted-string types of token.
uint32_t getNumber() const
Return the value of a string-variant token as a string object.
void getString(std::string &ret) const
Fill in a string with the value of a string-variant token.
std::string getString() const
Return the value of a string-variant token as a string object.
Type
Enumeration for token types.
@ INITIAL_WS
White spaces at the beginning of a line after an end of line or at the beginning of file (if asked.
@ NOVALUE_TYPE_MAX
Max integer corresponding to no-value (type only) types.
@ ERROR
Error detected in getting a token.
@ NUMBER
A decimal number (unsigned 32-bit)
@ END_OF_LINE
End of line detected.
@ QSTRING
A single string quoted by double-quotes (").
@ END_OF_FILE
End of file detected.
Type getType() const
Return the token type.
const StringRegion & getStringRegion() const
Return the value of a string-variant token.
MasterToken(uint32_t number)
Constructor for number type of token.
std::string getErrorText() const
Return a textual description of the error of a error type token.
MasterToken(Type type)
Constructor for non-value type of token.
Tokenization state for MasterLexer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
MasterLexer::Options operator|(MasterLexer::Options o1, MasterLexer::Options o2)
Operator to combine MasterLexer options.
Defines the logger used by the top-level component of kea-lfc.
A simple representation of a range of a string.
size_t len
The length of the string in bytes.
const char * beg
The start address of the string.