9 #include <boost/format.hpp>
10 #include <boost/filesystem.hpp>
24 namespace classic = boost::spirit::classic;
25 namespace bf = boost::filesystem;
26 namespace gp= Gaudi::Parsers;
27 namespace gpu= Gaudi::Parsers::Utils;
28 namespace qi = boost::spirit::qi;
32 template<
typename Grammar>
34 const std::string& stream_name, gp::Messages* messages,
40 boost::spirit::make_default_multi_pass(in_begin);
45 Iterator position_begin(fwd_begin, fwd_end, stream_name);
49 gp::SkipperGrammar<Iterator> skipper;
51 root->value = stream_name;
52 bool result = qi::phrase_parse(position_begin,
53 position_end, gr, skipper, *root);
54 if (result && (position_begin==position_end)) {
58 messages->AddError(gp::Position(stream_name, pos.line,
59 pos.column),
"parse error");
64 template<
typename Grammar>
65 bool ParseFile(
const gp::Position& from,
const std::string& filename,
67 gp::IncludedFiles* included, gp::Messages* messages,gp::Node* root) {
70 if (!from.filename().empty()) {
72 search_path_with_current_dir = file_path.parent_path().string()
73 + (search_path_with_current_dir.empty()?
""
74 :(
"," + search_path_with_current_dir));
79 if (absolute_path.empty()) {
80 messages->AddError(from,
"Couldn't find a file " + filename+
81 " in search path '"+ search_path_with_current_dir+
"'");
84 const gp::Position* included_from;
85 if (!included->GetPosition(absolute_path, &included_from)){
86 included->AddFile(absolute_path, from);
88 if (!
file.is_open()) {
89 messages->AddError(from,
"Couldn't open a file "+filename);
92 return ParseStream<Grammar>(
file, absolute_path, messages,
root);
94 assert(included_from != NULL);
95 messages->AddWarning(from,
97 % absolute_path % included_from->ToString()));
107 return Parse(
Position(), filename, search_path, included, messages,
116 return ParseFile<Grammar>(from, filename, search_path, included,
126 return ParseFile<Grammar>(from, filename, search_path, included,