Пример #1
0
static void processCompoundPattern( const PatternMatchState & state, TransitionList & newTransitions ) {
	const Node & currentNode = state.getCurrentNode();

	if ( state.isComplete() ) { // Сопоставление завершено
		Match::AttributesMap attributes;

		state.context.addAttributes( attributes, state.getAlternative().getBindings() ); // Строим набор аттрибутов

		for ( uint i = 0; i < newTransitions.size(); ++ i ) {
			Match & match = static_cast<Match&>( *newTransitions[i] );

			if ( match.equals( state.getAlternative().getPattern(), state.startNode, currentNode, attributes ) ) {
				match.addVariant( state.releaseVariant() );
				return; // Если сопоставление уже было найдено
			}
		}

		newTransitions.push_back( new Match( state.startNode, currentNode, state.getAlternative().getPattern(), state.releaseVariant(), attributes ) ); // TODO Optimize

		return;
	}

	ChainList chains;

	if ( const AnnotationMatcher * curMatcher = dynamic_cast<const AnnotationMatcher *>( &state.getCurrentMatcher() ) ) {
		TransitionList nextTransitions = curMatcher->buildTransitions( currentNode, state.context );

		for ( uint i = 0, sz = nextTransitions.size(); i < sz; ++ i ) {
			PatternMatchState temp_state( state, nextTransitions[ i ], i == sz );
			processCompoundPattern( temp_state, newTransitions );
		}
	} else {
		const AnnotationChainMatcher & chainMatcher = static_cast<const AnnotationChainMatcher &>( state.getCurrentMatcher() );

		chains.clear();
		chainMatcher.buildChains( state.getCurrentNode(), state.context, chains );

		for ( uint i = 0, sz = chains.size(); i < sz; ++ i ) {
			PatternMatchState temp_state( state, chains[i].first, chains[i].second, i == sz - 1  );
			processCompoundPattern( temp_state, newTransitions);
		}
	}
}
Пример #2
0
void Normalization::appendToString( std::string & str, const TransitionList & transitions ) const {
	for ( uint i = 0; i < transitions.size(); ++ i )
		appendToString( str, *transitions[ i ] );
}