1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- // 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.
- #include <eval/eval_context.h>
- #include <eval/parser.h>
- #include <exceptions/exceptions.h>
- #include <fstream>
- EvalContext::EvalContext()
- : trace_scanning_(false), trace_parsing_(false)
- {
- }
- EvalContext::~EvalContext()
- {
- }
- int
- EvalContext::parseFile(const std::string &filename)
- {
- file = filename;
- scanBegin();
- isc::eval::EvalParser parser(*this);
- parser.set_debug_level(trace_parsing_);
- int res = parser.parse();
- scanEnd();
- return res;
- }
- int
- EvalContext::parseString(const std::string& str)
- {
- /// @todo: Is there any way for the parser to read from a stream,
- /// rather than a file? It would be better to use stringstream,
- /// but it seems that the lexer operates on FILE* interface.
- // Put the content into a file and then open that file for reading.
- remove("/tmp/eval");
- std::fstream f("/tmp/eval", std::ios::out);
- if (!f.good()) {
- isc_throw(isc::Unexpected, "Can't write /tmp/eval file");
- }
- f << str;
- f.close();
- return (parseFile("/tmp/eval"));
- }
- void
- EvalContext::error(const isc::eval::location& l, const std::string& m)
- {
- isc_throw(EvalError, l << ": " << m);
- }
- void
- EvalContext::error (const std::string& m)
- {
- isc_throw(EvalError, m);
- }
|