36 template <
typename GUM_SCALAR >
41 text =
replace(text,
"Syntax error",
"Error");
43 text =
replace(text,
"LABEL_OR_STAR_LIST",
"declaration");
45 text =
replace(text,
"ARRAY_REFERENCE_SLOT",
"declaration");
46 text =
replace(text,
"FLOAT_AS_LABEL",
"declaration");
47 text =
replace(text,
"FLOAT_OR_INT",
"declaration");
48 text =
replace(text,
"INTEGER_AS_FLOAT",
"declaration");
49 text =
replace(text,
"INTEGER_AS_LABEL",
"declaration");
50 text =
replace(text,
"INT_TYPE_DECLARATION",
"declaration");
51 text =
replace(text,
"LABEL_OR_INT",
"declaration");
52 text =
replace(text,
"LABEL_OR_STAR",
"declaration");
53 text =
replace(text,
"NAMED_CLASS_ELEMENT",
"declaration");
54 text =
replace(text,
"REAL_TYPE_DECLARATION",
"declaration");
56 text =
replace(text,
"AGGREGATE_PARENTS",
"declaration");
57 text =
replace(text,
"CLASS_BODY",
"declaration");
58 text =
replace(text,
"CLASS_DECLARATION",
"declaration");
59 text =
replace(text,
"CLASS_ELEMENT",
"declaration");
60 text =
replace(text,
"CLASS_PARAMETER",
"declaration");
61 text =
replace(text,
"CLASS_UNIT",
"declaration");
62 text =
replace(text,
"FLOAT_LIST",
"declaration");
63 text =
replace(text,
"FORMULA_LIST",
"declaration");
64 text =
replace(text,
"IDENTIFIER_LIST",
"declaration");
65 text =
replace(text,
"IMPORT_BODY",
"declaration");
66 text =
replace(text,
"IMPORT_DECLARATION",
"declaration");
67 text =
replace(text,
"IMPORT_UNIT",
"declaration");
68 text =
replace(text,
"INTERFACE_BODY",
"declaration");
69 text =
replace(text,
"INTERFACE_DECLARATION",
"declaration");
70 text =
replace(text,
"INTERFACE_UNIT",
"declaration");
71 text =
replace(text,
"LABEL_LIST",
"declaration");
72 text =
replace(text,
"PARAMETER_LIST",
"declaration");
73 text =
replace(text,
"PREFIXED_LABEL",
"declaration");
74 text =
replace(text,
"RAW_CPT",
"declaration");
75 text =
replace(text,
"REFERENCE_SLOT",
"declaration");
76 text =
replace(text,
"RULE_CPT",
"declaration");
77 text =
replace(text,
"SYSTEM_BODY",
"declaration");
78 text =
replace(text,
"SYSTEM_DECLARATION",
"declaration");
79 text =
replace(text,
"SYSTEM_UNIT",
"declaration");
80 text =
replace(text,
"TYPE_DECLARATION",
"declaration");
81 text =
replace(text,
"TYPE_LABEL",
"declaration");
82 text =
replace(text,
"TYPE_UNIT",
"declaration");
83 text =
replace(text,
"TYPE_VALUE_LIST",
"declaration");
85 text =
replace(text,
"AGGREGATE",
"declaration");
86 text =
replace(text,
"ARRAY",
"declaration");
87 text =
replace(text,
"ATTRIBUTE",
"declaration");
88 text =
replace(text,
"CAST",
"declaration");
89 text =
replace(text,
"CHAIN",
"declaration");
90 text =
replace(text,
"CLASS",
"declaration");
91 text =
replace(text,
"FLOAT",
"declaration");
92 text =
replace(text,
"FORMULA",
"declaration");
93 text =
replace(text,
"IDENTIFIER",
"declaration");
94 text =
replace(text,
"INT",
"declaration");
95 text =
replace(text,
"INTEGER",
"declaration");
96 text =
replace(text,
"INTERFACE",
"declaration");
97 text =
replace(text,
"LABEL",
"declaration");
98 text =
replace(text,
"LINK",
"declaration");
99 text =
replace(text,
"MAP",
"declaration");
100 text =
replace(text,
"PARAMETER",
"declaration");
101 text =
replace(text,
"REAL",
"declaration");
102 text =
replace(text,
"RULE",
"declaration");
103 text =
replace(text,
"TYPE",
"declaration");
104 text =
replace(text,
"UNIT",
"declaration");
109 template <
typename GUM_SCALAR >
118 template <
typename GUM_SCALAR >
122 inputstr.seekg(0, inputstr.end);
123 int length = int(inputstr.tellg());
124 inputstr.seekg(0, inputstr.beg);
126 auto str = std::string();
127 str.resize(length,
' ');
128 auto begin = &*str.begin();
130 inputstr.read(begin, length);
140 template <
typename GUM_SCALAR >
142 __prm(new
PRM< GUM_SCALAR >()),
147 template <
typename GUM_SCALAR >
149 __prm(&prm), __o3_prm(
std::unique_ptr<
O3PRM >(new
O3PRM())) {
153 template <
typename GUM_SCALAR >
156 __o3_prm(
std::unique_ptr<
O3PRM >(new
O3PRM(*(src.__o3_prm)))),
157 __class_path(src.__class_path), __imported(src.__imported),
158 __errors(src.__errors) {
162 template <
typename GUM_SCALAR >
164 __prm(
std::move(src.__prm)), __o3_prm(
std::move(src.__o3_prm)),
165 __class_path(
std::move(src.__class_path)),
166 __imported(
std::move(src.__imported)),
167 __errors(
std::move(src.__errors)) {
171 template <
typename GUM_SCALAR >
176 template <
typename GUM_SCALAR >
179 if (
this == &src) {
return *
this; }
181 __o3_prm = std::unique_ptr< O3PRM >(
new O3PRM(*(src.
__o3_prm)));
188 template <
typename GUM_SCALAR >
191 if (
this == &src) {
return *
this; }
192 __prm = std::move(src.__prm);
193 __o3_prm = std::move(src.__o3_prm);
194 __class_path = std::move(src.__class_path);
195 __imported = std::move(src.__imported);
196 __errors = std::move(src.__errors);
200 template <
typename GUM_SCALAR >
202 __class_path = std::vector< std::string >();
204 size_t j = class_path.find(
';');
206 while (j != std::string::npos) {
207 addClassPath(class_path.substr(i, j - i));
210 if (i < class_path.size()) {
211 j = class_path.find(
';', i);
213 j = std::string::npos;
217 if (i < class_path.size()) {
218 addClassPath(class_path.substr(i, std::string::npos));
222 template <
typename GUM_SCALAR >
224 auto path = class_path;
225 if (path[path.size() - 1] !=
'/') { path.append(
"/"); }
228 if (!dir.isValid()) {
229 __errors.addException(
"could not resolve class path", path);
231 __class_path.push_back(std::move(path));
235 template <
typename GUM_SCALAR >
237 return __errors.error(i).line;
240 template <
typename GUM_SCALAR >
242 return __errors.error(i).column;
245 template <
typename GUM_SCALAR >
247 return widen(__errors.error(i).filename);
250 template <
typename GUM_SCALAR >
252 return __errors.error(i).is_error;
255 template <
typename GUM_SCALAR >
257 return __errors.error(i).msg;
260 template <
typename GUM_SCALAR >
263 for (
Idx i = 0; i < __errors.count(); ++i) {
264 auto err = __errors.error(i);
265 if (err.is_error) { o << __print(err) << std::endl; }
269 template <
typename GUM_SCALAR >
271 std::ostream& o)
const {
272 for (
Idx i = 0; i < __errors.count(); ++i) {
273 auto err = __errors.error(i);
274 o << __print(err) << std::endl;
278 template <
typename GUM_SCALAR >
281 __errors.syntheticResults(o);
284 template <
typename GUM_SCALAR >
286 return __errors.error_count;
289 template <
typename GUM_SCALAR >
291 return __errors.warning_count;
294 template <
typename GUM_SCALAR >
300 template <
typename GUM_SCALAR >
302 std::stringstream sBuff(str);
303 __readStream(sBuff,
"");
304 return __errors.count();
307 template <
typename GUM_SCALAR >
309 const std::string& module) {
311 auto lastSlashIndex = file.find_last_of(
'/');
313 auto dir =
Directory(file.substr(0, lastSlashIndex + 1));
315 if (!dir.isValid()) {
316 __errors.addException(
"could not find file", file);
317 return __errors.count();
320 auto basename = file.substr(lastSlashIndex + 1);
323 std::ifstream input(absFilename);
324 if (input.is_open()) {
325 __readStream(input, file, module);
327 __errors.addException(
"could not open file", file);
330 return __errors.count();
335 return __errors.count();
337 __errors.addException(
"unknown error", file);
338 return __errors.count();
342 template <
typename GUM_SCALAR >
344 std::ostream& output,
345 std::string module) {
346 __readStream(input,
"", module);
348 showElegantErrorsAndWarnings(output);
351 template <
typename GUM_SCALAR >
354 const std::string& filename,
355 const std::string& module) {
356 auto sBuff = __readStream(input);
357 auto buffer = std::unique_ptr< unsigned char[] >(
358 new unsigned char[sBuff.length() + 1]);
359 strcpy((
char*)buffer.get(), sBuff.c_str());
360 auto s =
o3prm_scanner(buffer.get(), int(sBuff.length() + 1), filename);
362 p.set_prm(__o3_prm.get());
363 p.set_prefix(module);
365 __errors += p.errors();
368 template <
typename GUM_SCALAR >
371 const std::string& module) {
375 auto module_path = module;
376 std::replace(module_path.begin(), module_path.end(),
'.',
'/');
381 auto imported =
false;
382 for (
const auto& cp : __class_path) {
383 auto file_path = cp + path +
".o3prm";
384 std::ifstream file(file_path);
386 if (file.is_open()) {
387 __parseStream(file, file_path, i.
import().
label());
392 file_path = cp + module + path +
".o3prm";
393 std::ifstream file2(file_path);
395 if (file2.is_open()) {
396 __parseStream(file2, file_path, module +
"." + i.
import().
label());
404 std::stringstream msg;
405 msg <<
"Import error: could not resolve import " << i.
import().
label();
406 __errors.addError(msg.str(), pos.file(), pos.line(), pos.column());
411 template <
typename GUM_SCALAR >
412 INLINE std::vector< const O3Import* >
414 auto copy = std::vector< const O3Import* >();
415 for (
const auto& i : __o3_prm->imports()) {
416 if (!__imported.exists(i->import().label())) { copy.push_back(i.get()); }
421 template <
typename GUM_SCALAR >
423 const std::string& file,
424 std::string module) {
425 if (module.size() > 0 && module.back() !=
'.') { module.append(
"."); }
427 __parseStream(input, file, module);
429 auto imports = __copyImports();
431 for (
auto i : imports) {
432 __parseImport(*i, module);
434 imports = __copyImports();
435 }
while (imports.size() > 0);
438 if (__errors.error_count == 0) {
443 auto interface_factory =
448 auto system_factory =
452 type_factory.build();
453 interface_factory.buildInterfaces();
454 class_factory.buildClasses();
455 interface_factory.buildElements();
456 class_factory.buildImplementations();
457 class_factory.buildParameters();
458 class_factory.buildReferenceSlots();
459 class_factory.declareAttributes();
460 class_factory.declareAggregates();
461 class_factory.completeAggregates();
462 class_factory.completeAttributes();
463 system_factory.build();
465 if (__errors.count() == 0) {
466 __errors.addException(
"an unknown error occured", file);
471 __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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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)