eval_context.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef EVAL_CONTEXT_H
  15. #define EVAL_CONTEXT_H
  16. #include <string>
  17. #include <map>
  18. #include <eval/parser.h>
  19. #include <eval/eval_context_decl.h>
  20. #include <exceptions/exceptions.h>
  21. // Tell Flex the lexer's prototype ...
  22. #define YY_DECL isc::eval::EvalParser::symbol_type yylex (EvalContext& driver)
  23. // ... and declare it for the parser's sake.
  24. YY_DECL;
  25. namespace isc {
  26. namespace eval {
  27. /// @brief Evaluation error exception raised when trying to parse an axceptions.
  28. class EvalParseError : public isc::Exception {
  29. public:
  30. EvalParseError(const char* file, size_t line, const char* what) :
  31. isc::Exception(file, line, what) { };
  32. };
  33. /// @brief Evaluation context, an interface to the expression evaluation.
  34. class EvalContext
  35. {
  36. public:
  37. /// @brief Default constructor.
  38. EvalContext();
  39. /// @brief destructor
  40. virtual ~EvalContext();
  41. /// @brief Parsed expression (output tokens are stored here)
  42. isc::dhcp::Expression expression;
  43. /// @brief Method called before scanning starts on a string.
  44. void scanStringBegin();
  45. /// @brief Method called after the last tokens are scanned from a string.
  46. void scanStringEnd();
  47. /// @brief Run the parser on the string specified.
  48. ///
  49. /// @param str string to be written
  50. /// @return true on success.
  51. bool parseString(const std::string& str);
  52. /// @brief The name of the file being parsed.
  53. /// Used later to pass the file name to the location tracker.
  54. std::string file_;
  55. /// @brief The string being parsed.
  56. std::string string_;
  57. /// @brief Error handler
  58. ///
  59. /// @param loc location within the parsed file when experienced a problem.
  60. /// @param what string explaining the nature of the error.
  61. void error(const isc::eval::location& loc, const std::string& what);
  62. /// @brief Error handler
  63. ///
  64. /// This is a simplified error reporting tool for possible future
  65. /// cases when the EvalParser is not able to handle the packet.
  66. void error(const std::string& what);
  67. private:
  68. /// @brief Flag determining scanner debugging.
  69. bool trace_scanning_;
  70. /// @brief Flag determing parser debugging.
  71. bool trace_parsing_;
  72. };
  73. }; // end of isc::eval namespace
  74. }; // end of isc namespace
  75. #endif