9 #include <boost/algorithm/string_regex.hpp>
15 using namespace boost;
17 namespace confparser {
22 ifstream configFile( configFileName.c_str(), ios::out );
23 if ( !configFile )
throw BadSyntax( configFileName, 0,
24 "Specified configuration file does not exist" );
27 cout <<
"Parsing configuration file " << configFileName << endl;
30 parse_rec( &outermost_, 0, 0, configFile, configFileName );
40 const string& configFileName ) {
44 while ( getline( configFile, l ) ) {
51 if ( l.empty() )
continue;
54 if ( starts_with( l,
"#") || starts_with( l,
"//" ) )
continue;
57 if ( l.length() == 1 && l[0] ==
'}' ) {
62 "Found closing block at outermost level" );
69 regex blockBegin(
"^(\\w+)\\s*\\{$" );
70 regex keyVal(
"^(\\w+)\\s+(.*);" );
73 if ( regex_match( l.c_str(), m, blockBegin ) ) {
76 cout <<
"Adding Block " << m[1] <<
" at level " << level <<
" (line " << nLine <<
")" << endl;
79 nLine = parse_rec( &currBlock->
addChild( m[1] ), level + 1, nLine, configFile, configFileName );
82 }
else if ( regex_match( l.c_str(), m, keyVal ) ) {
89 throw BadSyntax( configFileName, nLine,
"Malformed expression" );
97 throw BadSyntax( configFileName, nLine,
"Unexpected end of configuration file" );