2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-05 16:35:23 +00:00
Files
kea/src/lib/eval/eval_context.h

91 lines
2.9 KiB
C
Raw Normal View History

// 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.
#ifndef EVAL_CONTEXT_H
#define EVAL_CONTEXT_H
#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 ...
#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) { };
};
/// @brief Evaluation context, an interface to the expression evaluation.
class EvalContext
2015-10-28 20:13:59 +01:00
{
public:
/// @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
/// @brief Method called before scanning starts.
void scanBegin();
2015-10-28 20:13:59 +01: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
/// @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
/// @brief The name of the file being parsed.
/// Used later to pass the file name to the location tracker.
std::string file;
/// @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
/// @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
private:
/// @brief Flag determining scanner debugging.
bool trace_scanning_;
2015-10-28 20:13:59 +01:00
/// @brief Flag determing parser debugging.
bool trace_parsing_;
2015-10-28 20:13:59 +01:00
};
#endif // ! EVALCONTEXT_HH