8 #include <boost/filesystem.hpp> 9 #include <boost/format.hpp> 23 namespace classic = boost::spirit::classic;
24 namespace bf = boost::filesystem;
34 while ( !ifs.
eof() ) {
41 ifs.
seekg( 0, ifs.beg );
44 template <
typename Grammar>
47 int last_line, last_column;
49 GetLastLineAndColumn( stream, last_line, last_column );
55 ForwardIterator fwd_begin = boost::spirit::make_default_multi_pass( in_begin );
60 Iterator position_begin( fwd_begin, fwd_end, stream_name );
64 gp::SkipperGrammar<Iterator> skipper;
66 root->value = stream_name;
67 bool result = qi::phrase_parse( position_begin, position_end, gr, skipper, *root );
70 if ( result && ( pos.line == last_line ) && ( pos.column == last_column ) ) {
return true; }
72 messages->AddError( gp::Position( stream_name, pos.line, pos.column ),
"parse error" );
77 template <
typename Grammar>
79 gp::IncludedFiles* included, gp::Messages* messages, gp::Node* root ) {
81 if ( !from.filename().empty() ) {
82 bf::path file_path( from.filename() );
83 search_path_with_current_dir =
84 file_path.parent_path().
string() +
85 ( search_path_with_current_dir.empty() ?
"" : (
"," + search_path_with_current_dir ) );
90 if ( absolute_path.
empty() ) {
91 messages->AddError( from,
"Couldn't find a file " + filename +
" in search path '" +
92 search_path_with_current_dir +
"'" );
95 const gp::Position* included_from;
96 if ( !included->GetPosition( absolute_path, &included_from ) ) {
97 included->AddFile( absolute_path, from );
99 if ( !file.is_open() ) {
100 messages->AddError( from,
"Couldn't open a file " + filename );
103 return ParseStream<Grammar>( file, absolute_path, messages,
root );
105 assert( included_from != NULL );
106 messages->AddWarning( from, str(
boost::format(
"File %1% already included from %2%" ) % absolute_path %
107 included_from->ToString() ) );
116 return Parse(
Position(), filename, search_path, included, messages, root );
122 return ParseFile<Grammar>( from,
filename, search_path, included, messages,
root );
129 return ParseFile<Grammar>( from,
filename, search_path, included, messages,
root );
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