34 template <
typename GUM_SCALAR >
39 text =
replace(text,
"Syntax error",
"Error");
41 text =
replace(text,
"LABEL_OR_STAR_LIST",
"declaration");
43 text =
replace(text,
"ARRAY_REFERENCE_SLOT",
"declaration");
44 text =
replace(text,
"FLOAT_AS_LABEL",
"declaration");
45 text =
replace(text,
"FLOAT_OR_INT",
"declaration");
46 text =
replace(text,
"INTEGER_AS_FLOAT",
"declaration");
47 text =
replace(text,
"INTEGER_AS_LABEL",
"declaration");
48 text =
replace(text,
"INT_TYPE_DECLARATION",
"declaration");
49 text =
replace(text,
"LABEL_OR_INT",
"declaration");
50 text =
replace(text,
"LABEL_OR_STAR",
"declaration");
51 text =
replace(text,
"NAMED_CLASS_ELEMENT",
"declaration");
52 text =
replace(text,
"REAL_TYPE_DECLARATION",
"declaration");
54 text =
replace(text,
"AGGREGATE_PARENTS",
"declaration");
55 text =
replace(text,
"CLASS_BODY",
"declaration");
56 text =
replace(text,
"CLASS_DECLARATION",
"declaration");
57 text =
replace(text,
"CLASS_ELEMENT",
"declaration");
58 text =
replace(text,
"CLASS_PARAMETER",
"declaration");
59 text =
replace(text,
"CLASS_UNIT",
"declaration");
60 text =
replace(text,
"FLOAT_LIST",
"declaration");
61 text =
replace(text,
"FORMULA_LIST",
"declaration");
62 text =
replace(text,
"IDENTIFIER_LIST",
"declaration");
63 text =
replace(text,
"IMPORT_BODY",
"declaration");
64 text =
replace(text,
"IMPORT_DECLARATION",
"declaration");
65 text =
replace(text,
"IMPORT_UNIT",
"declaration");
66 text =
replace(text,
"INTERFACE_BODY",
"declaration");
67 text =
replace(text,
"INTERFACE_DECLARATION",
"declaration");
68 text =
replace(text,
"INTERFACE_UNIT",
"declaration");
69 text =
replace(text,
"LABEL_LIST",
"declaration");
70 text =
replace(text,
"PARAMETER_LIST",
"declaration");
71 text =
replace(text,
"PREFIXED_LABEL",
"declaration");
72 text =
replace(text,
"RAW_CPT",
"declaration");
73 text =
replace(text,
"REFERENCE_SLOT",
"declaration");
74 text =
replace(text,
"RULE_CPT",
"declaration");
75 text =
replace(text,
"SYSTEM_BODY",
"declaration");
76 text =
replace(text,
"SYSTEM_DECLARATION",
"declaration");
77 text =
replace(text,
"SYSTEM_UNIT",
"declaration");
78 text =
replace(text,
"TYPE_DECLARATION",
"declaration");
79 text =
replace(text,
"TYPE_LABEL",
"declaration");
80 text =
replace(text,
"TYPE_UNIT",
"declaration");
81 text =
replace(text,
"TYPE_VALUE_LIST",
"declaration");
83 text =
replace(text,
"AGGREGATE",
"declaration");
84 text =
replace(text,
"ARRAY",
"declaration");
85 text =
replace(text,
"ATTRIBUTE",
"declaration");
86 text =
replace(text,
"CAST",
"declaration");
87 text =
replace(text,
"CHAIN",
"declaration");
88 text =
replace(text,
"CLASS",
"declaration");
89 text =
replace(text,
"FLOAT",
"declaration");
90 text =
replace(text,
"FORMULA",
"declaration");
91 text =
replace(text,
"IDENTIFIER",
"declaration");
92 text =
replace(text,
"INT",
"declaration");
93 text =
replace(text,
"INTEGER",
"declaration");
94 text =
replace(text,
"INTERFACE",
"declaration");
95 text =
replace(text,
"LABEL",
"declaration");
96 text =
replace(text,
"LINK",
"declaration");
97 text =
replace(text,
"MAP",
"declaration");
98 text =
replace(text,
"PARAMETER",
"declaration");
99 text =
replace(text,
"REAL",
"declaration");
100 text =
replace(text,
"RULE",
"declaration");
101 text =
replace(text,
"TYPE",
"declaration");
102 text =
replace(text,
"UNIT",
"declaration");
107 template <
typename GUM_SCALAR >
116 template <
typename GUM_SCALAR >
120 inputstr.seekg(0, inputstr.end);
121 int length = int(inputstr.tellg());
122 inputstr.seekg(0, inputstr.beg);
124 auto str = std::string();
125 str.resize(length,
' ');
126 auto begin = &*str.begin();
128 inputstr.read(begin, length);
138 template <
typename GUM_SCALAR >
140 __prm(new
PRM< GUM_SCALAR >()),
145 template <
typename GUM_SCALAR >
147 __prm(&prm), __o3_prm(
std::unique_ptr<
O3PRM >(new
O3PRM())) {
151 template <
typename GUM_SCALAR >
154 __o3_prm(
std::unique_ptr<
O3PRM >(new
O3PRM(*(src.__o3_prm)))),
155 __class_path(src.__class_path), __imported(src.__imported),
156 __errors(src.__errors) {
160 template <
typename GUM_SCALAR >
162 __prm(
std::move(src.__prm)), __o3_prm(
std::move(src.__o3_prm)),
163 __class_path(
std::move(src.__class_path)),
164 __imported(
std::move(src.__imported)),
165 __errors(
std::move(src.__errors)) {
169 template <
typename GUM_SCALAR >
174 template <
typename GUM_SCALAR >
177 if (
this == &src) {
return *
this; }
179 __o3_prm = std::unique_ptr< O3PRM >(
new O3PRM(*(src.
__o3_prm)));
186 template <
typename GUM_SCALAR >
189 if (
this == &src) {
return *
this; }
190 __prm = std::move(src.__prm);
191 __o3_prm = std::move(src.__o3_prm);
192 __class_path = std::move(src.__class_path);
193 __imported = std::move(src.__imported);
194 __errors = std::move(src.__errors);
198 template <
typename GUM_SCALAR >
200 __class_path = std::vector< std::string >();
202 size_t j = class_path.find(
';');
204 while (j != std::string::npos) {
205 addClassPath(class_path.substr(i, j - i));
208 if (i < class_path.size()) {
209 j = class_path.find(
';', i);
211 j = std::string::npos;
215 if (i < class_path.size()) {
216 addClassPath(class_path.substr(i, std::string::npos));
220 template <
typename GUM_SCALAR >
222 auto path = class_path;
223 if (path[path.size() - 1] !=
'/') { path.append(
"/"); }
226 if (!dir.isValid()) {
227 __errors.addException(
"could not resolve class path", path);
229 __class_path.push_back(std::move(path));
233 template <
typename GUM_SCALAR >
235 return __errors.error(i).line;
238 template <
typename GUM_SCALAR >
240 return __errors.error(i).column;
243 template <
typename GUM_SCALAR >
245 return widen(__errors.error(i).filename);
248 template <
typename GUM_SCALAR >
250 return __errors.error(i).is_error;
253 template <
typename GUM_SCALAR >
255 return __errors.error(i).msg;
258 template <
typename GUM_SCALAR >
261 for (
Idx i = 0; i < __errors.count(); ++i) {
262 auto err = __errors.error(i);
263 if (err.is_error) { o << __print(err) << std::endl; }
267 template <
typename GUM_SCALAR >
269 std::ostream& o)
const {
270 for (
Idx i = 0; i < __errors.count(); ++i) {
271 auto err = __errors.error(i);
272 o << __print(err) << std::endl;
276 template <
typename GUM_SCALAR >
279 __errors.syntheticResults(o);
282 template <
typename GUM_SCALAR >
284 return __errors.error_count;
287 template <
typename GUM_SCALAR >
289 return __errors.warning_count;
292 template <
typename GUM_SCALAR >
298 template <
typename GUM_SCALAR >
300 std::stringstream sBuff(str);
301 __readStream(sBuff,
"");
302 return __errors.count();
305 template <
typename GUM_SCALAR >
307 const std::string& module) {
309 auto lastSlashIndex = file.find_last_of(
'/');
311 auto dir =
Directory(file.substr(0, lastSlashIndex + 1));
313 if (!dir.isValid()) {
314 __errors.addException(
"could not find file", file);
315 return __errors.count();
318 auto basename = file.substr(lastSlashIndex + 1);
321 std::ifstream input(absFilename);
322 if (input.is_open()) {
323 __readStream(input, file, module);
325 __errors.addException(
"could not open file", file);
328 return __errors.count();
333 return __errors.count();
335 __errors.addException(
"unknown error", file);
336 return __errors.count();
340 template <
typename GUM_SCALAR >
342 std::ostream& output,
343 std::string module) {
344 __readStream(input,
"", module);
346 showElegantErrorsAndWarnings(output);
349 template <
typename GUM_SCALAR >
352 const std::string& filename,
353 const std::string& module) {
354 auto sBuff = __readStream(input);
355 auto buffer = std::unique_ptr< unsigned char[] >(
356 new unsigned char[sBuff.length() + 1]);
357 strcpy((
char*)buffer.get(), sBuff.c_str());
358 auto s =
o3prm_scanner(buffer.get(), int(sBuff.length() + 1), filename);
360 p.set_prm(__o3_prm.get());
361 p.set_prefix(module);
363 __errors += p.errors();
366 template <
typename GUM_SCALAR >
369 const std::string& module) {
373 auto module_path = module;
374 std::replace(module_path.begin(), module_path.end(),
'.',
'/');
379 auto imported =
false;
380 for (
const auto& cp : __class_path) {
381 auto file_path = cp + path +
".o3prm";
382 std::ifstream file(file_path);
384 if (file.is_open()) {
385 __parseStream(file, file_path, i.
import().
label());
390 file_path = cp + module + path +
".o3prm";
391 std::ifstream file2(file_path);
393 if (file2.is_open()) {
394 __parseStream(file2, file_path, module +
"." + i.
import().
label());
402 std::stringstream msg;
403 msg <<
"Import error: could not resolve import " << i.
import().
label();
404 __errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
409 template <
typename GUM_SCALAR >
410 INLINE std::vector< const O3Import* >
412 auto copy = std::vector< const O3Import* >();
413 for (
const auto& i : __o3_prm->imports()) {
414 if (!__imported.exists(i->import().label())) { copy.push_back(i.get()); }
419 template <
typename GUM_SCALAR >
421 const std::string& file,
422 std::string module) {
423 if (module.size() > 0 && module.back() !=
'.') { module.append(
"."); }
425 __parseStream(input, file, module);
427 auto imports = __copyImports();
429 for (
auto i : imports) {
430 __parseImport(*i, module);
432 imports = __copyImports();
433 }
while (imports.size() > 0);
436 if (__errors.error_count == 0) {
441 auto interface_factory =
446 auto system_factory =
450 type_factory.build();
451 interface_factory.buildInterfaces();
452 class_factory.buildClasses();
453 interface_factory.buildElements();
454 class_factory.buildImplementations();
455 class_factory.buildParameters();
456 class_factory.buildReferenceSlots();
457 class_factory.declareAttributes();
458 class_factory.declareAggregates();
459 class_factory.completeAggregates();
460 class_factory.completeAttributes();
461 system_factory.build();
463 if (__errors.count() == 0) {
464 __errors.addException(
"an unknown error occured", file);
469 __errors.addException(
"an unknown exception occured", file);
std::string __clean(std::string text) const
Builds gum::prm::PRMType from gum::prm::o3prm::O3Type, gum::prm::o3prm::O3IntType and gum::prm::o3prm...
Cross-platform directory utility.
std::string msg
The gum::ParseError message.
void __readStream(std::istream &input, const std::string &file, std::string module="")
gum::prm::o3prm::Parser o3prm_parser
std::string filename
The file of this gum::ParseError, default is "".
std::vector< std::string > __class_path
This class is used to represent parsing errors for the different parser implemented in aGrUM...
std::unique_ptr< O3PRM > __o3_prm
gum::prm::o3prm::Scanner o3prm_scanner
This class is used contain and manipulate gum::ParseError.
gum is the global namespace for all aGrUM entities
The O3Import is part of the AST of the O3PRM language.
Builds gum::prm::PRMSystem from gum::prm::o3prm::O3System.
This class read O3PRM files and creates the corresponding gum::prm::PRM.
Bulds gum::prm:PRMInterface from gum::prm::o3prm::O3Interface.
Resolves names for the different O3PRM factories.
Headers for the O3prmReader class.
DatabaseTable readFile(const std::string &filename)
Idx line
The line of this gum::ParseError.
std::wstring widen(const std::string &str)
Cast a std::string into a std::wstring.
Base class for all aGrUM's exceptions.
Builds gum::prm::Class from gum::prm::o3prm::O3Class.
Set< std::string > __imported
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
std::string __print(const ParseError &err) const
std::string absolutePath() const
Returns directory absolute path.
std::string replace(const std::string &s, const std::string &val, const std::string &new_val)
not usable for gcc 4.8 std::vector<std::string> split( const std::string& orig, const std::string& de...
Size Idx
Type for indexes.
The O3PRM is part of the AST of the O3PRM language.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Idx column
The column of this gum::ParseError, default is 0.
const std::string errorContent() const
Returns the message content.
PRM< GUM_SCALAR > * __prm
#define GUM_ERROR(type, msg)