22 #include "pddl_parser.h"
27 namespace pddl_parser {
48 PddlParser::getErrorContext(
const iterator_type &start_it,
49 const iterator_type &end_it,
50 const iterator_type ¤t_it)
52 auto line = get_current_line(start_it, current_it, end_it);
53 std::string line_str = std::string(line.begin(), line.end());
54 std::replace(begin(line_str), end(line_str),
'\t',
' ');
55 std::ostringstream error_msg;
56 error_msg <<
" line:" << get_line(current_it) <<
", col:" << get_column(line.begin(), current_it)
58 while (!line.empty() && std::strchr(
"\r\n", *line.begin()))
59 line.advance_begin(1);
60 error_msg << line_str <<
"\n";
61 error_msg << std::string(std::distance(line.begin(), current_it),
' ')
62 <<
"^ --- parsing halted here\n";
63 return error_msg.str();
81 iterator_type iter(pddl_domain.begin());
82 iterator_type end(pddl_domain.end());
86 r = phrase_parse(iter, end, g, s, dom);
87 }
catch (qi::expectation_failure<iterator_type>
const &e) {
88 using boost::spirit::basic_info_walker;
89 std::stringstream expectation;
90 boost::spirit::simple_printer<std::stringstream> pr(expectation);
91 basic_info_walker<boost::spirit::simple_printer<std::stringstream>> walker(pr, e.what_.tag, 0);
92 boost::apply_visitor(walker, e.what_.value);
94 + expectation.str() +
" at " + getErrorContext(iter, end, e.first),
97 e.prepend(
"Semantic Error: ");
98 e.append(getErrorContext(iter, end, e.pos).c_str());
125 iterator_type iter(pddl_problem.begin());
126 iterator_type end(pddl_problem.end());
129 r = phrase_parse(iter, end, g, s, prob);
130 }
catch (qi::expectation_failure<iterator_type>
const &e) {
132 + getErrorContext(iter, end, e.first),
Exception thrown by the parser if an error occurs during parsing.
static Domain parseDomain(const std::string &pddl_domain)
Parse the PDDL domain.
static Problem parseProblem(const std::string &pddl_problem)
Parse the PDDL problem.
Exception thrown by the parser if an error occurs during semantic checks during parsing.
Exception thrown by the parser if there is a syntax error.
A structured representation of a PDDL domain.
A structured representation of a PDDL problem.
A Boost QI parser for a PDDL domain.
A skipper for PDDL files.
A Boost QI parser for a PDDL problem.