2015-11-05 00:34:12 +09:00
|
|
|
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
2015-10-28 20:37:12 +01:00
|
|
|
#ifndef EVAL_CONTEXT_H
|
|
|
|
#define EVAL_CONTEXT_H
|
2015-11-05 00:34:12 +09:00
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <eval/parser.h>
|
2015-11-05 00:43:56 +09:00
|
|
|
#include <exceptions/exceptions.h>
|
2015-10-28 20:13:59 +01:00
|
|
|
|
|
|
|
// Tell Flex the lexer's prototype ...
|
2015-11-05 00:34:12 +09:00
|
|
|
#define YY_DECL isc::eval::EvalParser::symbol_type yylex (EvalContext& driver)
|
2015-10-28 20:13:59 +01:00
|
|
|
|
|
|
|
// ... and declare it for the parser's sake.
|
|
|
|
YY_DECL;
|
|
|
|
|
2015-11-05 00:43:56 +09:00
|
|
|
/// @brief Evaluation error exception raised when trying to parse an axceptions.
|
|
|
|
class EvalError : public isc::exceptions::Exception {
|
|
|
|
public:
|
|
|
|
EvalError(const char* file, size_t line, const char* what) :
|
|
|
|
isc::Exception(file, line, what) { };
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-11-05 00:34:12 +09:00
|
|
|
/// @brief Evaluation context, an interface to the expression evaluation.
|
2015-10-28 20:37:12 +01:00
|
|
|
class EvalContext
|
2015-10-28 20:13:59 +01:00
|
|
|
{
|
|
|
|
public:
|
2015-11-05 00:34:12 +09:00
|
|
|
/// @brief Default constructor.
|
|
|
|
EvalContext();
|
|
|
|
|
|
|
|
/// @brief destructor
|
|
|
|
virtual ~EvalContext();
|
|
|
|
|
|
|
|
/// @brief Parsed expression (output tokens are stored here)
|
|
|
|
isc::dhcp::Expression expression;
|
2015-10-28 20:13:59 +01:00
|
|
|
|
2015-11-05 00:34:12 +09:00
|
|
|
/// @brief Method called before scanning starts.
|
|
|
|
void scanBegin();
|
2015-10-28 20:13:59 +01:00
|
|
|
|
2015-11-05 00:34:12 +09:00
|
|
|
/// @brief Method called after the last tokens are scanned.
|
|
|
|
void scanEnd();
|
|
|
|
|
|
|
|
/// @brief Runs the parser on specified file.
|
|
|
|
///
|
|
|
|
/// @param filename
|
|
|
|
/// Return 0 on success.
|
|
|
|
int parseFile(const std::string& filename);
|
2015-10-28 20:13:59 +01:00
|
|
|
|
2015-11-05 00:34:12 +09:00
|
|
|
/// @brief Run the parser on the string specified.
|
|
|
|
///
|
|
|
|
/// @param str string to be written
|
|
|
|
int parseString(const std::string& str);
|
2015-10-28 20:13:59 +01:00
|
|
|
|
2015-11-05 00:34:12 +09:00
|
|
|
/// @brief The name of the file being parsed.
|
|
|
|
/// Used later to pass the file name to the location tracker.
|
|
|
|
std::string file;
|
2015-10-28 20:37:12 +01:00
|
|
|
|
2015-11-05 00:34:12 +09:00
|
|
|
/// @brief Error handler
|
|
|
|
///
|
|
|
|
/// @param l location within the parsed file when experienced a problem.
|
|
|
|
/// @param what string explaining the nature of the error.
|
|
|
|
void error(const isc::eval::location& l, const std::string& what);
|
2015-10-28 20:13:59 +01:00
|
|
|
|
2015-11-05 00:34:12 +09:00
|
|
|
/// @brief Error handler
|
|
|
|
///
|
|
|
|
/// This is a simplified error reporting tool for possible future
|
|
|
|
/// cases when the EvalParser is not able to handle the packet.
|
|
|
|
void error(const std::string& what);
|
2015-10-28 20:13:59 +01:00
|
|
|
|
2015-11-05 00:34:12 +09:00
|
|
|
private:
|
|
|
|
/// @brief Flag determining scanner debugging.
|
|
|
|
bool trace_scanning_;
|
2015-10-28 20:13:59 +01:00
|
|
|
|
2015-11-05 00:34:12 +09:00
|
|
|
/// @brief Flag determing parser debugging.
|
|
|
|
bool trace_parsing_;
|
|
|
|
|
2015-10-28 20:13:59 +01:00
|
|
|
};
|
2015-10-28 20:37:12 +01:00
|
|
|
#endif // ! EVALCONTEXT_HH
|