eval_context.h 3.11 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// 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.

15
16
#ifndef EVAL_CONTEXT_H
#define EVAL_CONTEXT_H
17
18
19
#include <string>
#include <map>
#include <eval/parser.h>
20
#include <eval/eval_context_decl.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
21
#include <exceptions/exceptions.h>
22
23

// Tell Flex the lexer's prototype ...
24
#define YY_DECL isc::eval::EvalParser::symbol_type yylex (EvalContext& driver)
25
26
27
28

// ... and declare it for the parser's sake.
YY_DECL;

29
30
31
namespace isc {
namespace eval {

Tomek Mrugalski's avatar
Tomek Mrugalski committed
32
/// @brief Evaluation error exception raised when trying to parse an axceptions.
33
class EvalParseError : public isc::Exception {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
34
public:
35
    EvalParseError(const char* file, size_t line, const char* what) :
Tomek Mrugalski's avatar
Tomek Mrugalski committed
36
37
38
39
        isc::Exception(file, line, what) { };
};


40
/// @brief Evaluation context, an interface to the expression evaluation.
41
class EvalContext
42
43
{
public:
44
45
46
47
48
49
50
51
    /// @brief Default constructor.
    EvalContext();

    /// @brief destructor
    virtual ~EvalContext();

    /// @brief Parsed expression (output tokens are stored here)
    isc::dhcp::Expression expression;
52

53
54
55
56
57
    /// @brief Method called before scanning starts on a string.
    void scanStringBegin();

    /// @brief Method called after the last tokens are scanned from a string.
    void scanStringEnd();
58
59
60
61
    
    /// @brief Run the parser on the string specified.
    ///
    /// @param str string to be written
62
63
    /// @return true on success.
    bool parseString(const std::string& str);
64

65
66
    /// @brief The name of the file being parsed.
    /// Used later to pass the file name to the location tracker.
67
    std::string file_;
68

69
70
71
    /// @brief The string being parsed.
    std::string string_;

72
73
    /// @brief Error handler
    ///
74
    /// @param loc location within the parsed file when experienced a problem.
75
    /// @param what string explaining the nature of the error.
76
    void error(const isc::eval::location& loc, const std::string& what);
77

78
79
80
81
82
    /// @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);
83

84
85
86
87
88
    /// @brief Fatal error handler
    ///
    /// This is for should not happen but fatal errors
    static void fatal(const std::string& what);

89
90
91
 private:
    /// @brief Flag determining scanner debugging.
    bool trace_scanning_;
92

93
94
95
    /// @brief Flag determing parser debugging.
    bool trace_parsing_;
  
96
};
97
98
99
100
101

}; // end of isc::eval namespace
}; // end of isc namespace

#endif