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 void GetLastLineAndColumn(std::ifstream& ifs,
int&
line,
int& column) {
40 column = str.length()+1;
42 ifs.seekg(0, ifs.beg);
45 template<
typename Grammar>
46 bool ParseStream(std::ifstream& stream,
47 const std::string& stream_name, gp::Messages* messages,
50 int last_line, last_column;
53 GetLastLineAndColumn(stream, last_line, last_column);
55 std::string input((std::istreambuf_iterator<char>(stream)),
56 std::istreambuf_iterator<char>());
61 boost::spirit::make_default_multi_pass(in_begin);
66 Iterator position_begin(fwd_begin, fwd_end, stream_name);
70 gp::SkipperGrammar<Iterator> skipper;
72 root->value = stream_name;
73 bool result = qi::phrase_parse(position_begin,
74 position_end, gr, skipper, *root);
77 if (result && (pos.line == last_line) && (pos.column == last_column)) {
81 messages->AddError(gp::Position(stream_name, pos.line,
82 pos.column),
"parse error");
87 template<
typename Grammar>
88 bool ParseFile(
const gp::Position& from,
const std::string& filename,
89 const std::string& search_path,
90 gp::IncludedFiles* included, gp::Messages* messages,gp::Node* root) {
91 std::string search_path_with_current_dir =
93 if (!from.filename().empty()) {
95 search_path_with_current_dir = file_path.parent_path().string()
96 + (search_path_with_current_dir.empty()?
""
97 :(
"," + search_path_with_current_dir));
102 if (absolute_path.empty()) {
103 messages->AddError(from,
"Couldn't find a file " + filename+
104 " in search path '"+ search_path_with_current_dir+
"'");
107 const gp::Position* included_from;
108 if (!included->GetPosition(absolute_path, &included_from)){
109 included->AddFile(absolute_path, from);
110 std::ifstream
file(absolute_path.c_str());
111 if (!
file.is_open()) {
112 messages->AddError(from,
"Couldn't open a file "+filename);
115 return ParseStream<Grammar>(
file, absolute_path, messages,
root);
117 assert(included_from != NULL);
118 messages->AddWarning(from,
120 % absolute_path % included_from->ToString()));
130 return Parse(
Position(), filename, search_path, included, messages,
135 const std::string& filename,
139 return ParseFile<Grammar>(from, filename, search_path, included,
145 const std::string& filename,
149 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)
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
boost::spirit::classic::file_position_base< std::string > IteratorPosition