Fawkes API  Fawkes Development Version
main.cpp
1 /***************************************************************************
2  * main.cpp - PDDL Parser
3  *
4  * Created: Fri 13 Oct 2017 14:50:44 CEST 14:50
5  * Copyright 2017 Matthias Loebach
6  * Till Hofmann <hofmann@kbsg.rwth-aachen.de>
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/pddl_parser.h>
23 
24 #include <fstream>
25 #include <iostream>
26 
27 int
28 main()
29 {
30  std::ifstream t("domain.pddl");
31  std::string str;
32 
33  t.seekg(0, std::ios::end);
34  str.reserve(t.tellg());
35  t.seekg(0, std::ios::beg);
36 
37  str.assign((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
38 
40  try {
43  std::cout << "Error occurred during parsing: " << e.what_no_backtrace() << std::endl;
44  return 1;
45  }
46 
47  std::cout << "success" << std::endl;
48 
49  std::cout << dom.name << std::endl;
50  std::cout << "requirements:" << std::endl;
51  for (std::string s : dom.requirements) {
52  std::cout << "\t" << s << std::endl;
53  }
54  std::cout << "types:" << std::endl;
55  for (std::pair<std::string, std::string> p : dom.types) {
56  std::cout << "\t" << p.first << " - " << p.second << std::endl;
57  }
58  std::cout << "constants:" << std::endl;
59  for (std::pair<std::vector<std::string>, std::string> p : dom.constants) {
60  std::cout << "\t";
61  for (std::string s : p.first) {
62  std::cout << s << " ";
63  }
64  std::cout << "- " << p.second << std::endl;
65  }
66  std::cout << "predicates:" << std::endl;
67  for (std::pair<std::string, std::vector<std::pair<std::string, std::string>>> p1 :
68  dom.predicates) {
69  std::cout << "\t" << p1.first << std::endl;
70  for (std::pair<std::string, std::string> p2 : p1.second) {
71  std::cout << "\t\t" << p2.first << ":" << p2.second << std::endl;
72  }
73  }
74  std::cout << "actions:" << std::endl;
75  for (auto a : dom.actions) {
76  std::cout << "\t" << a.name << std::endl;
77  for (std::pair<std::string, std::string> p : a.action_params) {
78  std::cout << "\t\t" << p.first << ":" << p.second << std::endl;
79  }
80  }
81 }
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
Definition: exception.cpp:663
Exception thrown by the parser if an error occurs during parsing.
Definition: pddl_parser.h:47
static Domain parseDomain(const std::string pddl_domain)
Parse the PDDL domain.
Definition: pddl_parser.cpp:46
A structured representation of a PDDL domain.
Definition: pddl_ast.h:99
std::vector< Action > actions
A list of actions defined in the domain.
Definition: pddl_ast.h:113
std::string name
The name of the domain.
Definition: pddl_ast.h:101
pairs_multi_consts constants
A typed list of constants defined in the domain.
Definition: pddl_ast.h:107
pairs_type types
A list of types with their super types.
Definition: pddl_ast.h:105
std::vector< predicate_type > predicates
A list of predicate names in the domain, including the types of their arguments.
Definition: pddl_ast.h:111
std::vector< std::string > requirements
A list of PDDL features required by the domain.
Definition: pddl_ast.h:103