Fawkes API
Fawkes Development Version
pddl_parser.cpp
1
/***************************************************************************
2
* pddl_parser.cpp
3
*
4
* Created: Fri 19 May 2017 11:10:01 CEST
5
* Copyright 2017 Matthias Loebach
6
* Till Hofmann
7
****************************************************************************/
8
9
/* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Library General Public License for more details.
18
*
19
* Read the full text in the LICENSE.GPL file in the doc directory.
20
*/
21
22
#include "pddl_parser.h"
23
24
#include <fstream>
25
#include <streambuf>
26
27
namespace
pddl_parser {
28
29
/** @class PddlParser <pddl_parser/pddl_parser.h>
30
* Parse a PDDL domain file or problem.
31
* This class parses a domain/problem into a structured representation of
32
* the domain, which can then be used by other components.
33
* @see pddl_ast.h
34
*/
35
36
/** @class PddlParserException <pddl_parser/pddl_parser.h>
37
* Exception thrown by the parser if an error occurs during parsing.
38
*/
39
40
/** Parse the PDDL domain.
41
* @param pddl_domain The PDDL domain as string (not a path)
42
* @return A Domain object that contains the parsed domain.
43
* @see Domain
44
*/
45
Domain
46
PddlParser::parseDomain
(
const
std::string pddl_domain)
47
{
48
typedef
std::string::const_iterator iterator_type;
49
typedef
pddl_parser::grammar::domain_parser<iterator_type>
grammar;
50
typedef
pddl_parser::grammar::pddl_skipper<iterator_type>
skipper;
51
52
grammar g;
53
skipper s;
54
Domain
dom;
55
56
std::string::const_iterator iter = pddl_domain.begin();
57
std::string::const_iterator end = pddl_domain.end();
58
bool
r = phrase_parse(iter, end, g, s, dom);
59
60
if
(!r) {
61
throw
PddlParserException
(
"Parsing PDDL domain string failed!"
);
62
}
63
64
return
dom;
65
}
66
67
/** Parse the PDDL problem.
68
* @param pddl_problem The problem as string (not a path)
69
* @return A Problem object that contains the parsed problem.
70
* @see Problem
71
*/
72
Problem
73
PddlParser::parseProblem
(
const
std::string pddl_problem)
74
{
75
typedef
std::string::const_iterator iterator_type;
76
typedef
pddl_parser::grammar::problem_parser<iterator_type>
grammar;
77
typedef
pddl_parser::grammar::pddl_skipper<iterator_type>
skipper;
78
79
grammar g;
80
skipper s;
81
Problem
prob;
82
83
std::string::const_iterator iter = pddl_problem.begin();
84
std::string::const_iterator end = pddl_problem.end();
85
bool
r = phrase_parse(iter, end, g, s, prob);
86
87
if
(!r) {
88
throw
PddlParserException
(
"Parsing PDDL problem string failed!"
);
89
}
90
91
return
prob;
92
}
93
94
}
// namespace pddl_parser
pddl_parser::Domain
A structured representation of a PDDL domain.
Definition:
pddl_ast.h:99
pddl_parser::Problem
A structured representation of a PDDL problem.
Definition:
pddl_ast.h:120
pddl_parser::grammar::problem_parser
A Boost QI parser for a PDDL problem.
Definition:
pddl_grammar.h:158
pddl_parser::PddlParser::parseDomain
static Domain parseDomain(const std::string pddl_domain)
Parse the PDDL domain.
Definition:
pddl_parser.cpp:46
pddl_parser::grammar::pddl_skipper
A skipper for PDDL files.
Definition:
pddl_grammar.h:36
pddl_parser::PddlParser::parseProblem
static Problem parseProblem(const std::string pddl_problem)
Parse the PDDL problem.
Definition:
pddl_parser.cpp:73
pddl_parser::grammar::domain_parser
A Boost QI parser for a PDDL domain.
Definition:
pddl_grammar.h:50
pddl_parser::PddlParserException
Exception thrown by the parser if an error occurs during parsing.
Definition:
pddl_parser.h:47
src
libs
pddl_parser
pddl_parser.cpp
Generated by
1.8.20