8 #include <boost/format.hpp> 9 #include <boost/filesystem.hpp> 23 namespace classic = boost::spirit::classic;
24 namespace bf = boost::filesystem;
41 ifs.
seekg(0, ifs.beg);
44 template<
typename Grammar>
46 const std::string& stream_name, gp::Messages* messages,
49 int last_line, last_column;
51 GetLastLineAndColumn(stream, last_line, last_column);
59 boost::spirit::make_default_multi_pass(in_begin);
64 Iterator position_begin(fwd_begin, fwd_end, stream_name);
68 gp::SkipperGrammar<Iterator> skipper;
70 root->value = stream_name;
71 bool result = qi::phrase_parse(position_begin,
72 position_end, gr, skipper, *root);
75 if (result && (pos.line == last_line) && (pos.column == last_column)) {
79 messages->AddError(gp::Position(stream_name, pos.line,
80 pos.column),
"parse error");
85 template<
typename Grammar>
88 gp::IncludedFiles* included, gp::Messages* messages,gp::Node* root) {
91 if (!from.filename().empty()) {
93 search_path_with_current_dir = file_path.parent_path().
string()
94 + (search_path_with_current_dir.empty()?
"" 95 :(
"," + search_path_with_current_dir));
100 if (absolute_path.
empty()) {
101 messages->AddError(from,
"Couldn't find a file " + filename+
102 " in search path '"+ search_path_with_current_dir+
"'");
105 const gp::Position* included_from;
106 if (!included->GetPosition(absolute_path, &included_from)){
107 included->AddFile(absolute_path, from);
109 if (!file.is_open()) {
110 messages->AddError(from,
"Couldn't open a file "+filename);
113 return ParseStream<Grammar>(file, absolute_path, messages,
root);
115 assert(included_from != NULL);
116 messages->AddWarning(from,
118 % absolute_path % included_from->ToString()));
128 return Parse(
Position(), filename, search_path, included, messages,
137 return ParseFile<Grammar>(from,
filename, search_path, included,
147 return ParseFile<Grammar>(from,
filename, search_path, included,
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
bool ParseUnits(const Position &from, const std::string &filename, const std::string &search_path, IncludedFiles *included, Messages *messages, Node *root)
static std::string find_file_from_list(const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)
std::string::const_iterator BaseIterator
std::string replaceEnvironments(const std::string &input)
boost::spirit::multi_pass< BaseIterator > ForwardIterator
bool Parse(const std::string &filename, const std::string &search_path, IncludedFiles *included, Messages *messages, Node *root)
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
boost::spirit::classic::file_position_base< std::string > IteratorPosition