-
Notifications
You must be signed in to change notification settings - Fork 1
/
pddl_check.cpp
81 lines (77 loc) · 2.73 KB
/
pddl_check.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/***************************************************************************
* pddl_check.cpp - Check a PDDL domain for syntax errors
*
* Created: Wed 8 Dec 18:54:25 CET 2021
* Copyright 2021 Till Hofmann <hofmann@kbsg.rwth-aachen.de>
****************************************************************************/
/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* Read the full text in the LICENSE.md file.
*/
#include "pddl_parser/pddl_ast.h"
#include "pddl_parser/pddl_parser.h"
#include <boost/program_options.hpp>
#include <boost/program_options/options_description.hpp>
#include <filesystem>
#include <fstream>
#include <ostream>
#include <spdlog/spdlog.h>
namespace {
std::string read_file(const std::filesystem::path &path) {
std::ifstream f;
f.open(path);
std::ostringstream sstr;
sstr << f.rdbuf();
return sstr.str();
}
} // namespace
int main(int argc, const char *const argv[]) {
boost::program_options::options_description options("Allowed options");
std::filesystem::path domain_path;
std::filesystem::path problem_path;
using boost::program_options::value;
// clang-format off
options.add_options()
("help,h", "Print help message")
("domain", value(&domain_path), "The path to the domain file")
("problem", value(&problem_path), "The path to the problem file")
;
// clang-format on
boost::program_options::variables_map variables;
boost::program_options::store(
boost::program_options::parse_command_line(argc, argv, options),
variables);
boost::program_options::notify(variables);
if (variables.count("help")) {
std::cout << options;
return 0;
}
bool success = true;
if (!domain_path.empty()) {
try {
pddl_parser::PddlParser::parseDomain(read_file(domain_path));
std::cout << "Successfully parsed domain " << domain_path << '\n';
} catch (std::exception &e) {
std::cerr << "Failed to parse domain:\n" << e.what();
success = false;
}
}
if (!problem_path.empty()) {
try {
pddl_parser::PddlParser::parseProblem(read_file(problem_path));
std::cout << "Successfully parsed problem " << problem_path << '\n';
} catch (std::exception &e) {
std::cerr << "Failed to parse problem:\n" << e.what();
success = false;
}
}
return success ? 0 : 1;
}