58 template <
typename GUM_SCALAR >
62 text =
replace(text,
"Syntax error",
"Error");
64 text =
replace(text,
"LABEL_OR_STAR_LIST",
"declaration");
66 text =
replace(text,
"ARRAY_REFERENCE_SLOT",
"declaration");
67 text =
replace(text,
"FLOAT_AS_LABEL",
"declaration");
68 text =
replace(text,
"FLOAT_OR_INT",
"declaration");
69 text =
replace(text,
"INTEGER_AS_FLOAT",
"declaration");
70 text =
replace(text,
"INTEGER_AS_LABEL",
"declaration");
71 text =
replace(text,
"INT_TYPE_DECLARATION",
"declaration");
72 text =
replace(text,
"LABEL_OR_INT",
"declaration");
73 text =
replace(text,
"LABEL_OR_STAR",
"declaration");
74 text =
replace(text,
"NAMED_CLASS_ELEMENT",
"declaration");
75 text =
replace(text,
"REAL_TYPE_DECLARATION",
"declaration");
77 text =
replace(text,
"AGGREGATE_PARENTS",
"declaration");
78 text =
replace(text,
"CLASS_BODY",
"declaration");
79 text =
replace(text,
"CLASS_DECLARATION",
"declaration");
80 text =
replace(text,
"CLASS_ELEMENT",
"declaration");
81 text =
replace(text,
"CLASS_PARAMETER",
"declaration");
82 text =
replace(text,
"CLASS_UNIT",
"declaration");
83 text =
replace(text,
"FLOAT_LIST",
"declaration");
84 text =
replace(text,
"FORMULA_LIST",
"declaration");
85 text =
replace(text,
"IDENTIFIER_LIST",
"declaration");
86 text =
replace(text,
"IMPORT_BODY",
"declaration");
87 text =
replace(text,
"IMPORT_DECLARATION",
"declaration");
88 text =
replace(text,
"IMPORT_UNIT",
"declaration");
89 text =
replace(text,
"INTERFACE_BODY",
"declaration");
90 text =
replace(text,
"INTERFACE_DECLARATION",
"declaration");
91 text =
replace(text,
"INTERFACE_UNIT",
"declaration");
92 text =
replace(text,
"LABEL_LIST",
"declaration");
93 text =
replace(text,
"PARAMETER_LIST",
"declaration");
94 text =
replace(text,
"PREFIXED_LABEL",
"declaration");
95 text =
replace(text,
"RAW_CPT",
"declaration");
96 text =
replace(text,
"REFERENCE_SLOT",
"declaration");
97 text =
replace(text,
"RULE_CPT",
"declaration");
98 text =
replace(text,
"SYSTEM_BODY",
"declaration");
99 text =
replace(text,
"SYSTEM_DECLARATION",
"declaration");
100 text =
replace(text,
"SYSTEM_UNIT",
"declaration");
101 text =
replace(text,
"TYPE_DECLARATION",
"declaration");
102 text =
replace(text,
"TYPE_LABEL",
"declaration");
103 text =
replace(text,
"TYPE_UNIT",
"declaration");
104 text =
replace(text,
"TYPE_VALUE_LIST",
"declaration");
106 text =
replace(text,
"AGGREGATE",
"declaration");
107 text =
replace(text,
"ARRAY",
"declaration");
108 text =
replace(text,
"ATTRIBUTE",
"declaration");
109 text =
replace(text,
"CAST",
"declaration");
110 text =
replace(text,
"CHAIN",
"declaration");
112 text =
replace(text,
"FLOAT",
"declaration");
113 text =
replace(text,
"FORMULA",
"declaration");
114 text =
replace(text,
"IDENTIFIER",
"declaration");
115 text =
replace(text,
"INT",
"declaration");
116 text =
replace(text,
"INTEGER",
"declaration");
117 text =
replace(text,
"INTERFACE",
"declaration");
118 text =
replace(text,
"LABEL",
"declaration");
119 text =
replace(text,
"LINK",
"declaration");
120 text =
replace(text,
"MAP",
"declaration");
121 text =
replace(text,
"PARAMETER",
"declaration");
122 text =
replace(text,
"REAL",
"declaration");
123 text =
replace(text,
"RULE",
"declaration");
124 text =
replace(text,
"TYPE",
"declaration");
125 text =
replace(text,
"UNIT",
"declaration");
130 template <
typename GUM_SCALAR >
137 template <
typename GUM_SCALAR >
140 inputstr.seekg(0, inputstr.end);
141 int length = int(inputstr.tellg());
142 inputstr.seekg(0, inputstr.beg);
144 auto str = std::string();
145 str.resize(length,
' ');
146 auto begin = &*str.begin();
148 inputstr.read(begin, length);
158 template <
typename GUM_SCALAR >
164 template <
typename GUM_SCALAR >
170 template <
typename GUM_SCALAR >
177 template <
typename GUM_SCALAR >
185 template <
typename GUM_SCALAR >
190 template <
typename GUM_SCALAR >
193 if (
this == &src) {
return *
this; }
202 template <
typename GUM_SCALAR >
204 if (
this == &src) {
return *
this; }
205 _prm_ = std::move(src._prm_);
213 template <
typename GUM_SCALAR >
217 size_t j = class_path.find(
';');
219 while (j != std::string::npos) {
223 if (i < class_path.size()) {
224 j = class_path.find(
';', i);
226 j = std::string::npos;
230 if (i < class_path.size()) {
addClassPath(class_path.substr(i, std::string::npos)); }
233 template <
typename GUM_SCALAR >
235 auto path = class_path;
236 if (path[path.size() - 1] !=
'/') { path.append(
"/"); }
237 std::filesystem::directory_entry dir(path);
239 _errors_.addException(
"could not resolve class path", path);
245 template <
typename GUM_SCALAR >
250 template <
typename GUM_SCALAR >
255 template <
typename GUM_SCALAR >
260 template <
typename GUM_SCALAR >
265 template <
typename GUM_SCALAR >
270 template <
typename GUM_SCALAR >
278 template <
typename GUM_SCALAR >
282 o <<
_print_(err) << std::endl;
286 template <
typename GUM_SCALAR >
291 template <
typename GUM_SCALAR >
296 template <
typename GUM_SCALAR >
301 template <
typename GUM_SCALAR >
306 template <
typename GUM_SCALAR >
308 std::stringstream sBuff(str);
313 template <
typename GUM_SCALAR >
315 const std::string& module) {
317 auto const lastSlashIndex = file.find_last_of(
'/');
319 std::filesystem::directory_entry dir(file.substr(0, lastSlashIndex + 1));
321 _errors_.addException(
"could not find file", file);
325 auto const basename = file.substr(lastSlashIndex + 1);
326 auto const absFilename
327 = std::filesystem::absolute(dir.path() / std::filesystem::path(basename)).string();
329 std::ifstream input(absFilename);
330 if (input.is_open()) {
333 _errors_.addException(
"could not open file", file);
343 _errors_.addException(
"unknown error", file);
348 template <
typename GUM_SCALAR >
350 std::ostream& output,
351 std::string module) {
357 template <
typename GUM_SCALAR >
359 const std::string& filename,
360 const std::string& module) {
362 auto buffer = std::unique_ptr< unsigned char[] >(
new unsigned char[sBuff.length() + 1]);
363 strcpy((
char*)buffer.get(), sBuff.c_str());
364 auto s =
o3prm_scanner(buffer.get(),
int(sBuff.length() + 1), filename);
367 p.set_prefix(module);
372 template <
typename GUM_SCALAR >
374 const std::string& module) {
378 auto module_path =
module;
379 std::replace(module_path.begin(), module_path.end(),
'.',
'/');
382 std::replace(path.begin(), path.end(),
'.',
'/');
384 auto imported =
false;
386 auto file_path = cp + path +
".o3prm";
387 std::ifstream file(file_path);
389 if (file.is_open()) {
395 file_path = cp + module + path +
".o3prm";
396 std::ifstream file2(file_path);
398 if (file2.is_open()) {
407 std::stringstream msg;
408 msg <<
"Import error: could not resolve import " << i.
import().
label();
409 _errors_.addError(msg.str(), pos.file(), pos.line(), pos.column());
414 template <
typename GUM_SCALAR >
416 auto copy = std::vector< const O3Import* >();
417 for (
const auto& i:
_o3_prm_->imports()) {
418 if (!
_imported_.exists(i->import().label())) { copy.push_back(i.get()); }
423 template <
typename GUM_SCALAR >
425 const std::string& file,
426 std::string module) {
427 if (module.size() > 0 && module.back() !=
'.') {
module.append("."); }
433 for (
auto i: imports) {
437 }
while (imports.size() > 0);
444 auto interface_factory
451 type_factory.build();
452 interface_factory.buildInterfaces();
453 class_factory.buildClasses();
454 interface_factory.buildElements();
455 class_factory.buildImplementations();
456 class_factory.buildParameters();
457 class_factory.buildReferenceSlots();
458 class_factory.declareAttributes();
459 class_factory.declareAggregates();
460 class_factory.completeAggregates();
461 class_factory.completeAttributes();
462 system_factory.build();
464 if (
_errors_.count() == 0) {
_errors_.addException(
"an unknown error occured", file); }
465 }
catch (...) {
_errors_.addException(
"an unknown exception occured", file); }
Headers for the O3prmReader class.
std::wstring widen(const std::string &str)
Cast a std::string into a std::wstring.
This class is used contain and manipulate gum::ParseError.
Base class for all aGrUM's exceptions.
GUM_NODISCARD std::string errorContent() const
Returns the message content.
Exception : operation not allowed.
This class is used to represent parsing errors for the different parser implemented in aGrUM.
std::string filename
The file of this gum::ParseError, default is "".
Idx column
The column of this gum::ParseError, default is 0.
std::string msg
The gum::ParseError message.
Idx line
The line of this gum::ParseError.
bool is_error
If false, this gum::ParseError is a warning.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Builds gum::prm::Class from gum::prm::o3prm::O3Class.
The O3Import is part of the AST of the O3PRM language.
Bulds gum::prm:PRMInterface from gum::prm::o3prm::O3Interface.
Resolves names for the different O3PRM factories.
The O3PRM is part of the AST of the O3PRM language.
Builds gum::prm::PRMSystem from gum::prm::o3prm::O3System.
Builds gum::prm::PRMType from gum::prm::o3prm::O3Type, gum::prm::o3prm::O3IntType and gum::prm::o3prm...
This class read O3PRM files and creates the corresponding gum::prm::PRM.
Set< std::string > _imported_
Size errors() const
publishing Errors API
std::vector< const O3Import * > _copyImports_()
Size readString(const std::string &string)
With readString method, you must set the current path to search from import yourself,...
void _parseImport_(const O3Import &i, const std::string &module_path)
const ErrorsContainer & errorsContainer() const
publishing Errors API
std::wstring errFilename(Idx i) const
filename of ith error or warning
void showElegantErrors(std::ostream &o=std::cerr) const
send on std::cerr the list of errors
void addClassPath(const std::string &class_path)
Add a list of paths to look for o3prm files.
Idx errCol(Idx i) const
col of ith error or warning
std::string _print_(const ParseError &err) const
gum::prm::PRM< GUM_SCALAR > * prm()
void setClassPath(const std::string &class_path)
This methods defines the list of paths to look for o3prm files.
void showErrorCounts(std::ostream &o=std::cerr) const
send on std::cerr the number of errors and the number of warnings
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr) const
send on std::cerr the list of errors or warnings
O3prmReader & operator=(const O3prmReader &src)
void _readStream_(std::istream &input, const std::string &file, std::string module="")
void _parseStream_(std::istream &input, const std::string &filename, const std::string &module)
bool errIsError(Idx i) const
type of ith error or warning
Idx errLine(Idx i) const
line of ith error or warning
void parseStream(std::istream &input, std::ostream &output, std::string module="")
std::string errMsg(Idx i) const
message of ith error or warning
Size readFile(const std::string &file, const std::string &module="")
Read file and load its content using a PRMFactory. The package parameter set the file's content packa...
std::string _clean_(std::string text) const
std::unique_ptr< O3PRM > _o3_prm_
PRM< GUM_SCALAR > * _prm_
std::vector< std::string > _class_path_
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
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, ...
gum::prm::o3prm::Scanner o3prm_scanner
gum::prm::o3prm::Parser o3prm_parser
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities