// Copyright {Jagger Software Limited} 2003 #if !defined GRAMMAR_TOOLS_PARSEABLE_SOURCE_INCLUDED || \ defined GRAMMAR_TOOLS_PARSEABLE_SOURCE_TEMPLATE_INCLUDED #error "grammar_tools/parseable_source-template.hpp" #included directly #endif #define GRAMMAR_TOOLS_PARSEABLE_SOURCE_TEMPLATE_INCLUDED #include "grammar/non_terminal_symbol_definition.hpp" #include "grammar/production_symbol_definition.hpp" #include "grammar/qualified_symbol_definition.hpp" namespace grammar_tools // parser - 'tor { template parseable_source::parseable_source(iterator start, iterator finish) : from(start) , until(finish) , current_position(start) { } } namespace grammar_tools // parseable_source - attributes { template iterator parseable_source::begin() const { return from; } template iterator parseable_source::end() const { return until; } template iterator parseable_source::position() const { return current_position; } } namespace grammar_tools // parseable_source - parsing { template bool parseable_source::parse ( const ::grammar::non_terminal_symbol_definition & to_parse, ::grammar::visitor & visitor ) { const iterator reset = position(); size_t at = 0; while (at != to_parse.size() && !to_parse[at].accept(visitor)) { position(reset); ++at; } return at != to_parse.size(); } template bool parseable_source::parse ( const ::grammar::production_symbol_definition & to_parse, ::grammar::visitor & visitor ) { size_t at = 0; while (at != to_parse.size() && to_parse[at].accept(visitor)) { ++at; } return at == to_parse.size(); } template bool parseable_source::parse ( const ::grammar::qualified_symbol_definition & to_parse, ::grammar::visitor & visitor ) { using ::grammar::bound; bound count = 0; const bound lower_bound = to_parse.multiplicity.lower_bound; while (count != lower_bound && to_parse.symbol_definition.accept(visitor)) { ++count; } if (count == lower_bound) { const bound upper_bound = to_parse.multiplicity.upper_bound; while (count != upper_bound && to_parse.symbol_definition.accept(visitor)) { ++count; } } return count >= lower_bound; } } namespace grammar_tools //parseable_source - positioning { template bool parseable_source::reposition ( const ::grammar::symbol_definition &, iterator, iterator new_position ) { const bool result = current_position != new_position; position(new_position); return result; } template void parseable_source::position(iterator new_position) { current_position = new_position; } }