30 #include "exceptions/WParseError.h"
31 #include "exceptions/WNotFound.h"
33 #include "WPredicateHelper.h"
35 #include "WStructuredTextParser.h"
37 namespace WStructuredTextParser
70 return count( key, valuesOnly );
75 std::vector< ObjectType > rObj;
76 std::vector< KeyValueType > rKV;
87 return rKV.size() + rObj.size();
93 std::vector< StructuredValueTree > r =
getSubTrees( key );
108 std::vector< ObjectType > rObj;
109 std::vector< KeyValueType > rKV;
110 std::vector< StructuredValueTree > r;
116 for( std::vector< ObjectType >::const_iterator objects = rObj.begin(); objects != rObj.end(); ++objects )
126 std::vector< ObjectType >& resultObjects,
127 std::vector< KeyValueType >& resultValues )
const
132 if( !keySplit.size() )
138 for( FileType::const_iterator i = current.begin(); i != current.end(); ++i )
140 traverse( *i, keySplit.begin(), keySplit.end(), resultObjects, resultValues );
145 std::vector< std::string >::const_iterator keyEnd,
146 std::vector< ObjectType >& resultObjects,
147 std::vector< KeyValueType >& resultValues )
const
150 std::string elementName = boost::apply_visitor(
NameQueryVisitor(), current );
151 bool elementIsKeyValuePair = boost::apply_visitor(
IsLeafVisitor(), current );
152 bool elementIsComment = boost::apply_visitor(
IsCommentVisitor(), current );
157 if( elementIsComment )
163 if( elementName == *keyIter )
166 if( !elementIsKeyValuePair && ( ( keyIter + 1 ) != keyEnd) )
168 ObjectType elementAsObj = boost::get< ObjectType >( current );
169 for( std::vector< MemberType >::const_iterator nodeIter = elementAsObj.
m_nodes.begin();
170 nodeIter != elementAsObj.
m_nodes.end();
173 traverse( *nodeIter, keyIter + 1, keyEnd, resultObjects, resultValues );
176 else if( ( keyIter + 1 ) == keyEnd )
179 if( elementIsKeyValuePair )
182 resultValues.push_back( boost::get< KeyValueType >( current ) );
187 resultObjects.push_back( boost::get< ObjectType >( current ) );
197 std::ostringstream error;
202 std::string::const_iterator iter = input.begin();
203 std::string::const_iterator end = input.end();
204 bool r = phrase_parse( iter, end, parser, boost::spirit::ascii::space, ast );
207 if( !( r && iter == end ) )
209 throw WParseError(
"Parse error. Parser message: " + error.str() );
219 std::string input= readFileIntoString( path );
222 std::ostringstream error;
227 std::string::const_iterator iter = input.begin();
228 std::string::const_iterator end = input.end();
229 bool r = phrase_parse( iter, end, parser, boost::spirit::ascii::space, ast );
232 if( !( r && iter == end ) )
234 throw WParseError(
"Parse error. Parser message: " + error.str() );