diff --git a/alib2algo/src/regexp/convert/ToAutomatonGlushkov.cpp b/alib2algo/src/regexp/convert/ToAutomatonGlushkov.cpp index 3f29833ae069e083257e221cc1afc04d8af514b6..53a16df00430f6385b892a54a46317913ec1e09c 100644 --- a/alib2algo/src/regexp/convert/ToAutomatonGlushkov.cpp +++ b/alib2algo/src/regexp/convert/ToAutomatonGlushkov.cpp @@ -23,59 +23,59 @@ namespace regexp { namespace convert { -automaton::NFA ToAutomatonGlushkov::convert(const regexp::RegExp& regexp) { - return dispatch(regexp.getData()); +automaton::NFA ToAutomatonGlushkov::convert ( const regexp::RegExp & regexp ) { + return dispatch ( regexp.getData ( ) ); } -automaton::NFA ToAutomatonGlushkov::convert(const regexp::UnboundedRegExp& regexp) { - automaton::State q0( label::Label( label::LabelPairLabel( std::make_pair( label::labelFrom( 'q' ), label::labelFrom( 0 ) ) ) ) ); - automaton::NFA automaton( q0 ); +automaton::NFA ToAutomatonGlushkov::convert ( const regexp::UnboundedRegExp & regexp ) { + automaton::State q0 ( label::Label ( label::LabelPairLabel ( std::make_pair ( label::labelFrom ( 'q' ), label::labelFrom ( 0 ) ) ) ) ); + automaton::NFA automaton ( q0 ); - // step 1 - automaton.setInputAlphabet(regexp.getAlphabet()); + // step 1 + automaton.setInputAlphabet ( regexp.getAlphabet ( ) ); + + regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::index ( regexp ); + + // steps 2, 3, 4 + const std::set < regexp::UnboundedRegExpSymbol > first = regexp::GlushkovTraversal::first ( indexedRegExp ); + const std::set < regexp::UnboundedRegExpSymbol > last = regexp::GlushkovTraversal::last ( indexedRegExp ); - regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::indexate(regexp); - // steps 2, 3, 4 - const std::set<regexp::UnboundedRegExpSymbol> first = regexp::GlushkovTraversal::first(indexedRegExp); - const std::set<regexp::UnboundedRegExpSymbol> last = regexp::GlushkovTraversal::last(indexedRegExp); // \e in q0 check is in step 7 - // step 5 - for( auto const& symbol : indexedRegExp.getAlphabet()) - automaton.addState( automaton::State ( label::Label( label::ObjectLabel( alib::Object( symbol.getData() ) ) ) ) ); + // step 5 + for ( auto const & symbol : indexedRegExp.getAlphabet ( ) ) + automaton.addState ( automaton::State ( label::Label ( label::ObjectLabel ( alib::Object ( symbol.getData ( ) ) ) ) ) ); - // step 6 - for( auto const& symbol : first ) { - automaton.addTransition( q0, regexp::GlushkovTraversal::getSymbolFromGlushkovPair(symbol.getSymbol()), automaton::State ( label::Label( label::ObjectLabel( alib::Object( symbol.getSymbol( ).getData() ) ) ) ) ); - } + // step 6 + for ( auto const & symbol : first ) + automaton.addTransition ( q0, regexp::GlushkovTraversal::getSymbolFromGlushkovPair ( symbol.getSymbol ( ) ), automaton::State ( label::Label ( label::ObjectLabel ( alib::Object ( symbol.getSymbol ( ).getData ( ) ) ) ) ) ); - for(const auto& x : indexedRegExp.getAlphabet()) - for(const auto& f : regexp::GlushkovTraversal::follow(indexedRegExp, UnboundedRegExpSymbol ( x ))) { - const alphabet::Symbol& p = x; - const alphabet::Symbol& q = f.getSymbol(); + for ( const auto & x : indexedRegExp.getAlphabet ( ) ) + for ( const auto & f : regexp::GlushkovTraversal::follow ( indexedRegExp, UnboundedRegExpSymbol ( x ) ) ) { + const alphabet::Symbol & p = x; + const alphabet::Symbol & q = f.getSymbol ( ); - automaton.addTransition( automaton::State ( label::Label( label::ObjectLabel( alib::Object( p.getData( ) ) ) ) ), regexp::GlushkovTraversal::getSymbolFromGlushkovPair(q), automaton::State ( label::Label( label::ObjectLabel( alib::Object( q.getData( ) ) ) ) ) ); + automaton.addTransition ( automaton::State ( label::Label ( label::ObjectLabel ( alib::Object ( p.getData ( ) ) ) ) ), regexp::GlushkovTraversal::getSymbolFromGlushkovPair ( q ), automaton::State ( label::Label ( label::ObjectLabel ( alib::Object ( q.getData ( ) ) ) ) ) ); } // step 7 - for( auto const& symbol : last ) { - automaton.addFinalState( automaton::State ( label::Label( label::ObjectLabel( alib::Object( symbol.getSymbol( ).getData() ) ) ) ) ); - } - if(regexp::properties::RegExpEpsilon::languageContainsEpsilon(regexp)) - automaton.addFinalState( q0 ); + for ( auto const & symbol : last ) + automaton.addFinalState ( automaton::State ( label::Label ( label::ObjectLabel ( alib::Object ( symbol.getSymbol ( ).getData ( ) ) ) ) ) ); + + if ( regexp::properties::RegExpEpsilon::languageContainsEpsilon ( regexp ) ) + automaton.addFinalState ( q0 ); return automaton; } -auto ToAutomatonGlushkovUnboundedRegExp = ToAutomatonGlushkov::RegistratorWrapper<automaton::NFA, regexp::UnboundedRegExp>( ToAutomatonGlushkov::convert); +auto ToAutomatonGlushkovUnboundedRegExp = ToAutomatonGlushkov::RegistratorWrapper < automaton::NFA, regexp::UnboundedRegExp > ( ToAutomatonGlushkov::convert ); -automaton::NFA ToAutomatonGlushkov::convert(const regexp::FormalRegExp& /* regexp */) -{ - throw exception::CommonException("Glushkov: Converting FormalRegExp NYI"); // TODO +automaton::NFA ToAutomatonGlushkov::convert ( const regexp::FormalRegExp & /* regexp */ ) { + throw exception::CommonException ( "Glushkov: Converting FormalRegExp NYI" ); // TODO } -auto ToAutomatonGlushkovFormalRegExp = ToAutomatonGlushkov::RegistratorWrapper<automaton::NFA, regexp::FormalRegExp>(ToAutomatonGlushkov::convert); +auto ToAutomatonGlushkovFormalRegExp = ToAutomatonGlushkov::RegistratorWrapper < automaton::NFA, regexp::FormalRegExp > ( ToAutomatonGlushkov::convert ); } /* namespace convert */ diff --git a/alib2algo/src/regexp/convert/ToGrammarRightRGGlushkov.cpp b/alib2algo/src/regexp/convert/ToGrammarRightRGGlushkov.cpp index 704eb641a53736afae1ad4b27feffb94168ce954..4ab5d62a0b71a2ae33bcba7f5fede32a642282de 100644 --- a/alib2algo/src/regexp/convert/ToGrammarRightRGGlushkov.cpp +++ b/alib2algo/src/regexp/convert/ToGrammarRightRGGlushkov.cpp @@ -25,70 +25,73 @@ namespace regexp { namespace convert { -grammar::RightRG ToGrammarRightRGGlushkov::convert(const regexp::RegExp& regexp) { - return dispatch(regexp.getData()); +grammar::RightRG ToGrammarRightRGGlushkov::convert ( const regexp::RegExp & regexp ) { + return dispatch ( regexp.getData ( ) ); } -grammar::RightRG ToGrammarRightRGGlushkov::convert(const regexp::UnboundedRegExp& regexp) { - alphabet::Symbol S = alphabet::symbolFrom("S"); - grammar::RightRG grammar(S); +grammar::RightRG ToGrammarRightRGGlushkov::convert ( const regexp::UnboundedRegExp & regexp ) { + alphabet::Symbol S = alphabet::symbolFrom ( "S" ); + grammar::RightRG grammar ( S ); - // step 1 - grammar.setTerminalAlphabet(regexp.getAlphabet()); + // step 1 + grammar.setTerminalAlphabet ( regexp.getAlphabet ( ) ); + + regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::index ( regexp ); + + // steps 2, 3, 4 + const std::set < regexp::UnboundedRegExpSymbol > first = regexp::GlushkovTraversal::first ( indexedRegExp ); + const std::set < regexp::UnboundedRegExpSymbol > last = regexp::GlushkovTraversal::last ( indexedRegExp ); - regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::indexate(regexp); - // steps 2, 3, 4 - const std::set<regexp::UnboundedRegExpSymbol> first = regexp::GlushkovTraversal::first(indexedRegExp); - const std::set<regexp::UnboundedRegExpSymbol> last = regexp::GlushkovTraversal::last(indexedRegExp); // \e in q0 check is in step 7 - // step 5 - for(const auto & symbol : indexedRegExp.getAlphabet()) - grammar.addNonterminalSymbol (symbol); + // step 5 + for ( const auto & symbol : indexedRegExp.getAlphabet ( ) ) + grammar.addNonterminalSymbol ( symbol ); - // step 6 - for(const auto& symbol : first) - grammar.addRule(S, std::make_pair(regexp::GlushkovTraversal::getSymbolFromGlushkovPair(symbol.getSymbol()), symbol.getSymbol())); + // step 6 + for ( const auto & symbol : first ) + grammar.addRule ( S, std::make_pair ( regexp::GlushkovTraversal::getSymbolFromGlushkovPair ( symbol.getSymbol ( ) ), symbol.getSymbol ( ) ) ); - for(const auto& x : indexedRegExp.getAlphabet()) - for(const auto& f : regexp::GlushkovTraversal::follow(indexedRegExp, UnboundedRegExpSymbol ( x ))) { - const alphabet::Symbol& a = x; - const alphabet::Symbol& b = f.getSymbol(); + for ( const auto & x : indexedRegExp.getAlphabet ( ) ) + for ( const auto & f : regexp::GlushkovTraversal::follow ( indexedRegExp, UnboundedRegExpSymbol ( x ) ) ) { + const alphabet::Symbol & a = x; + const alphabet::Symbol & b = f.getSymbol ( ); - grammar.addRule(a, std::make_pair(regexp::GlushkovTraversal::getSymbolFromGlushkovPair(b), b)); + grammar.addRule ( a, std::make_pair ( regexp::GlushkovTraversal::getSymbolFromGlushkovPair ( b ), b ) ); } // step 7 + /* * for all rules where ns.m_nonTerminal is on rightSide: * add Rule: leftSide -> symbol.getSymbol( ) * unless it already exists */ - for(const auto& rule : grammar.getRawRules()) { - for(const auto& rhs : rule.second) { - for(const auto& symbol : last) { + for ( const auto & rule : grammar.getRawRules ( ) ) { + for ( const auto & rhs : rule.second ) + for ( const auto & symbol : last ) { - const alphabet::Symbol& a = symbol.getSymbol(); + const alphabet::Symbol & a = symbol.getSymbol ( ); - if(std::find(rhs.begin(), rhs.end(), a) != rhs.end()) - grammar.addRule(rule.first, rhs.at(0)); + if ( std::find ( rhs.begin ( ), rhs.end ( ), a ) != rhs.end ( ) ) + grammar.addRule ( rule.first, rhs.at ( 0 ) ); } - } + } - if(regexp::properties::RegExpEpsilon::languageContainsEpsilon(regexp)) - grammar.setGeneratesEpsilon(true); + if ( regexp::properties::RegExpEpsilon::languageContainsEpsilon ( regexp ) ) + grammar.setGeneratesEpsilon ( true ); return grammar; } -auto ToGrammarRightRGGlushkovUnboundedRegExp = ToGrammarRightRGGlushkov::RegistratorWrapper<grammar::RightRG, regexp::UnboundedRegExp>(ToGrammarRightRGGlushkov::convert); +auto ToGrammarRightRGGlushkovUnboundedRegExp = ToGrammarRightRGGlushkov::RegistratorWrapper < grammar::RightRG, regexp::UnboundedRegExp > ( ToGrammarRightRGGlushkov::convert ); -grammar::RightRG ToGrammarRightRGGlushkov::convert(const regexp::FormalRegExp& /* regexp */) { - throw exception::CommonException("Glushkov: Converting FormalRegExp NYI"); // TODO +grammar::RightRG ToGrammarRightRGGlushkov::convert ( const regexp::FormalRegExp & /* regexp */ ) { + throw exception::CommonException ( "Glushkov: Converting FormalRegExp NYI" ); // TODO } -auto ToGrammarRightRGGlushkovFormalRegExp = ToGrammarRightRGGlushkov::RegistratorWrapper<grammar::RightRG, regexp::FormalRegExp>(ToGrammarRightRGGlushkov::convert); +auto ToGrammarRightRGGlushkovFormalRegExp = ToGrammarRightRGGlushkov::RegistratorWrapper < grammar::RightRG, regexp::FormalRegExp > ( ToGrammarRightRGGlushkov::convert ); } /* namespace convert */ diff --git a/alib2algo/src/regexp/glushkov/GlushkovTraversal.cpp b/alib2algo/src/regexp/glushkov/GlushkovTraversal.cpp index ca79e7f81378348b290c3a9583701d2fd345ac8b..e9eebff36eece37c5d7cba0c4d4c3c309c2f4b2d 100644 --- a/alib2algo/src/regexp/glushkov/GlushkovTraversal.cpp +++ b/alib2algo/src/regexp/glushkov/GlushkovTraversal.cpp @@ -15,12 +15,14 @@ namespace regexp { +alphabet::Symbol GlushkovTraversal::getSymbolFromGlushkovPair ( const alphabet::Symbol & symbol ) { + const alphabet::SymbolPairSymbol & symbolPair = ( const alphabet::SymbolPairSymbol & ) symbol.getData ( ); -alphabet::Symbol GlushkovTraversal::getSymbolFromGlushkovPair(const alphabet::Symbol & symbol) { - const alphabet::SymbolPairSymbol & symbolPair = (const alphabet::SymbolPairSymbol&) symbol.getData(); - return symbolPair.getData().first; + return symbolPair.getData ( ).first; } +// ----------------------------------------------------------------------------- + bool GlushkovTraversal::pos ( const UnboundedRegExpSymbol & symbol, const regexp::UnboundedRegExp & node ) { return pos ( node.getRegExp ( ), symbol ); } @@ -325,13 +327,13 @@ bool GlushkovTraversal::pos ( const regexp::UnboundedRegExpEpsilon & /* node */, // ---------------------------------------------------------------------------- -UnboundedRegExp GlushkovTraversal::indexate ( const regexp::UnboundedRegExp & re ) { +UnboundedRegExp GlushkovTraversal::index ( const regexp::UnboundedRegExp & re ) { int i = 1; - return UnboundedRegExp ( indexate ( re.getRegExp ( ), i ) ); + return UnboundedRegExp ( index ( re.getRegExp ( ), i ) ); } -std::rvalue_ref < UnboundedRegExpElement > GlushkovTraversal::indexate ( const regexp::UnboundedRegExpElement & node, int & i ) { +std::rvalue_ref < UnboundedRegExpElement > GlushkovTraversal::index ( const regexp::UnboundedRegExpElement & node, int & i ) { const regexp::UnboundedRegExpAlternation * alternation = dynamic_cast < const regexp::UnboundedRegExpAlternation * > ( & node ); const regexp::UnboundedRegExpConcatenation * concatenation = dynamic_cast < const regexp::UnboundedRegExpConcatenation * > ( & node ); const regexp::UnboundedRegExpIteration * iteration = dynamic_cast < const regexp::UnboundedRegExpIteration * > ( & node ); @@ -342,27 +344,27 @@ std::rvalue_ref < UnboundedRegExpElement > GlushkovTraversal::indexate ( const r if ( symbol ) { return std::rvalue_ref < UnboundedRegExpElement > ( new UnboundedRegExpSymbol ( alphabet::Symbol ( alphabet::SymbolPairSymbol ( std::make_pair ( symbol->getSymbol ( ), alphabet::symbolFrom ( i++ ) ) ) ) ) ); } else if ( alternation ) { - UnboundedRegExpAlternation * alt = new UnboundedRegExpAlternation(); + UnboundedRegExpAlternation * alt = new UnboundedRegExpAlternation ( ); for ( const auto & element : alternation->getElements ( ) ) - alt->appendElement ( indexate ( * element, i ) ); + alt->appendElement ( index ( * element, i ) ); return std::rvalue_ref < UnboundedRegExpElement > ( alt ); } else if ( concatenation ) { - UnboundedRegExpConcatenation * con = new UnboundedRegExpConcatenation(); + UnboundedRegExpConcatenation * con = new UnboundedRegExpConcatenation ( ); for ( const auto & element : concatenation->getElements ( ) ) - con->appendElement ( indexate ( * element, i ) ); + con->appendElement ( index ( * element, i ) ); return std::rvalue_ref < UnboundedRegExpElement > ( con ); } else if ( iteration ) { - return std::rvalue_ref < UnboundedRegExpElement > ( new UnboundedRegExpIteration ( indexate ( iteration->getElement ( ), i ) ) ); + return std::rvalue_ref < UnboundedRegExpElement > ( new UnboundedRegExpIteration ( index ( iteration->getElement ( ), i ) ) ); } else if ( empty ) { return std::rvalue_ref < UnboundedRegExpElement > ( new UnboundedRegExpEmpty ( ) ); } else if ( eps ) { return std::rvalue_ref < UnboundedRegExpElement > ( new UnboundedRegExpEpsilon ( ) ); } else { - throw exception::CommonException ( "GlushkovTraversal::getSymbols() - unknown RegExpElement node" ); + throw exception::CommonException ( "GlushkovTraversal::index() - unknown RegExpElement node" ); } } diff --git a/alib2algo/src/regexp/glushkov/GlushkovTraversal.h b/alib2algo/src/regexp/glushkov/GlushkovTraversal.h index b169058d1e2f9ab7868d14e4a6690e47687ff4cc..d7682dc0951852b262eda5af50f5095683dff73c 100644 --- a/alib2algo/src/regexp/glushkov/GlushkovTraversal.h +++ b/alib2algo/src/regexp/glushkov/GlushkovTraversal.h @@ -8,18 +8,18 @@ #ifndef GLUSHKOVTRAVERSAL_H_ #define GLUSHKOVTRAVERSAL_H_ -#include <set> -#include <list> #include <algorithm> +#include <list> +#include <set> #include <regexp/unbounded/UnboundedRegExp.h> -#include <regexp/unbounded/UnboundedRegExpElement.h> #include <regexp/unbounded/UnboundedRegExpAlternation.h> #include <regexp/unbounded/UnboundedRegExpConcatenation.h> -#include <regexp/unbounded/UnboundedRegExpIteration.h> -#include <regexp/unbounded/UnboundedRegExpSymbol.h> +#include <regexp/unbounded/UnboundedRegExpElement.h> #include <regexp/unbounded/UnboundedRegExpEmpty.h> #include <regexp/unbounded/UnboundedRegExpEpsilon.h> +#include <regexp/unbounded/UnboundedRegExpIteration.h> +#include <regexp/unbounded/UnboundedRegExpSymbol.h> namespace regexp { @@ -30,7 +30,7 @@ namespace regexp { */ class GlushkovTraversal { public: - static alphabet::Symbol getSymbolFromGlushkovPair(const alphabet::Symbol & symbol); + static alphabet::Symbol getSymbolFromGlushkovPair ( const alphabet::Symbol & symbol ); /** * @param re RegExp to probe @@ -52,19 +52,18 @@ public: static std::set < UnboundedRegExpSymbol > follow ( const regexp::UnboundedRegExp & re, const UnboundedRegExpSymbol & symbol ); /** - * @param re RegExp to probe - * @return symbols of regexp tree in order of they occurence in regexp. + * @param re RegExp to index + * @return UnboundedRegExp with indexed elements */ - static regexp::UnboundedRegExp indexate ( const regexp::UnboundedRegExp & re ); + static regexp::UnboundedRegExp index ( const regexp::UnboundedRegExp & re ); private: - /** * @return bool true if symbol pointer is in this subtree */ static bool pos ( const UnboundedRegExpSymbol & symbol, const regexp::UnboundedRegExp & node ); - static std::rvalue_ref < UnboundedRegExpElement > indexate ( const regexp::UnboundedRegExpElement & node, int & i ); + static std::rvalue_ref < UnboundedRegExpElement > index ( const regexp::UnboundedRegExpElement & node, int & i ); static std::set < regexp::UnboundedRegExpSymbol > first ( const regexp::UnboundedRegExpElement & node ); static std::set < regexp::UnboundedRegExpSymbol > first ( const regexp::UnboundedRegExpAlternation & node ); diff --git a/alib2algo/test-src/regexp/RegExpTest.cpp b/alib2algo/test-src/regexp/RegExpTest.cpp index 962ca5d8f7488afecc0f70aab78706d74914ea00..b78f1eac3abb03b7de76423e7f761d07c6ec499b 100644 --- a/alib2algo/test-src/regexp/RegExpTest.cpp +++ b/alib2algo/test-src/regexp/RegExpTest.cpp @@ -1,125 +1,122 @@ -#include <list> #include "RegExpTest.h" +#include <list> -#include "sax/SaxParseInterface.h" #include "sax/SaxComposeInterface.h" +#include "sax/SaxParseInterface.h" -#include "regexp/unbounded/UnboundedRegExp.h" #include "regexp/RegExpFromStringParser.h" +#include "regexp/unbounded/UnboundedRegExp.h" #include "regexp/glushkov/GlushkovTraversal.h" #include <factory/StringDataFactory.hpp> -#define CPPUNIT_IMPLY(x, y) CPPUNIT_ASSERT(!(x) || (y)) -#define CPPUNIT_EXCLUSIVE_OR(x, y) CPPUNIT_ASSERT((!(x) && (y)) || ((x) && !(y))) +#define CPPUNIT_IMPLY( x, y ) CPPUNIT_ASSERT ( !( x ) || ( y ) ) +#define CPPUNIT_EXCLUSIVE_OR( x, y ) CPPUNIT_ASSERT ( ( !( x ) && ( y ) ) || ( ( x ) && !( y ) ) ) -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RegExpTest, "regexp" ); -CPPUNIT_TEST_SUITE_REGISTRATION( RegExpTest ); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( RegExpTest, "regexp" ); +CPPUNIT_TEST_SUITE_REGISTRATION ( RegExpTest ); -void RegExpTest::setUp() { +void RegExpTest::setUp ( ) { } -void RegExpTest::tearDown() { +void RegExpTest::tearDown ( ) { } -void RegExpTest::testFirst() { +void RegExpTest::testFirst ( ) { { std::string input = "#E* #0*"; - regexp::UnboundedRegExp regexp( static_cast<const regexp::UnboundedRegExp &>( alib::StringDataFactory::fromString<regexp::RegExp>(input).getData() ) ); - regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::indexate(regexp); + regexp::UnboundedRegExp regexp ( static_cast < const regexp::UnboundedRegExp & > ( alib::StringDataFactory::fromString < regexp::RegExp > ( input ).getData ( ) ) ); + regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::index ( regexp ); - std::set<regexp::UnboundedRegExpSymbol> first = regexp::GlushkovTraversal::first(indexedRegExp); + std::set < regexp::UnboundedRegExpSymbol > first = regexp::GlushkovTraversal::first ( indexedRegExp ); - CPPUNIT_ASSERT(first.size() == 0); + CPPUNIT_ASSERT ( first.size ( ) == 0 ); } { std::string input = "#E* a"; - regexp::UnboundedRegExp regexp( static_cast<const regexp::UnboundedRegExp &>( alib::StringDataFactory::fromString<regexp::RegExp>(input).getData() ) ); - regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::indexate(regexp); + regexp::UnboundedRegExp regexp ( static_cast < const regexp::UnboundedRegExp & > ( alib::StringDataFactory::fromString < regexp::RegExp > ( input ).getData ( ) ) ); + regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::index ( regexp ); - std::set<regexp::UnboundedRegExpSymbol> first = regexp::GlushkovTraversal::first(indexedRegExp); + std::set < regexp::UnboundedRegExpSymbol > first = regexp::GlushkovTraversal::first ( indexedRegExp ); - CPPUNIT_ASSERT(first.size() == 1); + CPPUNIT_ASSERT ( first.size ( ) == 1 ); } - } -void RegExpTest::testLast() { +void RegExpTest::testLast ( ) { { std::string input = "a+a"; - regexp::UnboundedRegExp regexp( static_cast<const regexp::UnboundedRegExp &>( alib::StringDataFactory::fromString<regexp::RegExp>(input).getData() ) ); - regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::indexate(regexp); + regexp::UnboundedRegExp regexp ( static_cast < const regexp::UnboundedRegExp & > ( alib::StringDataFactory::fromString < regexp::RegExp > ( input ).getData ( ) ) ); + regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::index ( regexp ); - std::set<regexp::UnboundedRegExpSymbol> last = regexp::GlushkovTraversal::last(indexedRegExp); + std::set < regexp::UnboundedRegExpSymbol > last = regexp::GlushkovTraversal::last ( indexedRegExp ); - CPPUNIT_ASSERT(last.size() == 2); + CPPUNIT_ASSERT ( last.size ( ) == 2 ); } { std::string input = "(a+a)b"; - regexp::UnboundedRegExp regexp( static_cast<const regexp::UnboundedRegExp &>( alib::StringDataFactory::fromString<regexp::RegExp>(input).getData() ) ); - regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::indexate(regexp); + regexp::UnboundedRegExp regexp ( static_cast < const regexp::UnboundedRegExp & > ( alib::StringDataFactory::fromString < regexp::RegExp > ( input ).getData ( ) ) ); + regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::index ( regexp ); - std::set<regexp::UnboundedRegExpSymbol> last = regexp::GlushkovTraversal::last(indexedRegExp); + std::set < regexp::UnboundedRegExpSymbol > last = regexp::GlushkovTraversal::last ( indexedRegExp ); std::cout << last << std::endl; - CPPUNIT_ASSERT(last.size() == 1); + CPPUNIT_ASSERT ( last.size ( ) == 1 ); } } -void RegExpTest::testFollow() { +void RegExpTest::testFollow ( ) { { std::string input = "(a+a)b"; - regexp::UnboundedRegExp regexp( static_cast<const regexp::UnboundedRegExp &>( alib::StringDataFactory::fromString<regexp::RegExp>(input).getData() ) ); - regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::indexate(regexp); + regexp::UnboundedRegExp regexp ( static_cast < const regexp::UnboundedRegExp & > ( alib::StringDataFactory::fromString < regexp::RegExp > ( input ).getData ( ) ) ); + regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::index ( regexp ); - auto symbolsIter = indexedRegExp.getAlphabet().begin(); + auto symbolsIter = indexedRegExp.getAlphabet ( ).begin ( ); - std::set<regexp::UnboundedRegExpSymbol> follow1 = regexp::GlushkovTraversal::follow(indexedRegExp, regexp::UnboundedRegExpSymbol ( *symbolsIter) ); + std::set < regexp::UnboundedRegExpSymbol > follow1 = regexp::GlushkovTraversal::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol ( * symbolsIter ) ); - CPPUNIT_ASSERT(follow1.size() == 1); + CPPUNIT_ASSERT ( follow1.size ( ) == 1 ); symbolsIter++; - std::set<regexp::UnboundedRegExpSymbol> follow2 = regexp::GlushkovTraversal::follow(indexedRegExp, regexp::UnboundedRegExpSymbol ( *symbolsIter) ); + std::set < regexp::UnboundedRegExpSymbol > follow2 = regexp::GlushkovTraversal::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol ( * symbolsIter ) ); - CPPUNIT_ASSERT(follow2.size() == 1); + CPPUNIT_ASSERT ( follow2.size ( ) == 1 ); symbolsIter++; - std::set<regexp::UnboundedRegExpSymbol> follow3 = regexp::GlushkovTraversal::follow(indexedRegExp, regexp::UnboundedRegExpSymbol ( *symbolsIter) ); + std::set < regexp::UnboundedRegExpSymbol > follow3 = regexp::GlushkovTraversal::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol ( * symbolsIter ) ); - CPPUNIT_ASSERT(follow3.size() == 0); + CPPUNIT_ASSERT ( follow3.size ( ) == 0 ); } { std::string input = "a+a* (b+a)* c"; - regexp::UnboundedRegExp regexp( static_cast<const regexp::UnboundedRegExp &>( alib::StringDataFactory::fromString<regexp::RegExp>(input).getData() ) ); - regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::indexate(regexp); + regexp::UnboundedRegExp regexp ( static_cast < const regexp::UnboundedRegExp & > ( alib::StringDataFactory::fromString < regexp::RegExp > ( input ).getData ( ) ) ); + regexp::UnboundedRegExp indexedRegExp = regexp::GlushkovTraversal::index ( regexp ); - auto symbolsIter = indexedRegExp.getAlphabet().begin(); + auto symbolsIter = indexedRegExp.getAlphabet ( ).begin ( ); - std::set<regexp::UnboundedRegExpSymbol> follow1 = regexp::GlushkovTraversal::follow(indexedRegExp, regexp::UnboundedRegExpSymbol ( *symbolsIter) ); + std::set < regexp::UnboundedRegExpSymbol > follow1 = regexp::GlushkovTraversal::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol ( * symbolsIter ) ); - CPPUNIT_ASSERT(follow1.size() == 0); + CPPUNIT_ASSERT ( follow1.size ( ) == 0 ); symbolsIter++; - std::set<regexp::UnboundedRegExpSymbol> follow2 = regexp::GlushkovTraversal::follow(indexedRegExp, regexp::UnboundedRegExpSymbol ( *symbolsIter) ); + std::set < regexp::UnboundedRegExpSymbol > follow2 = regexp::GlushkovTraversal::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol ( * symbolsIter ) ); - CPPUNIT_ASSERT(follow2.size() == 4); + CPPUNIT_ASSERT ( follow2.size ( ) == 4 ); symbolsIter++; - std::set<regexp::UnboundedRegExpSymbol> follow3 = regexp::GlushkovTraversal::follow(indexedRegExp, regexp::UnboundedRegExpSymbol ( *symbolsIter) ); + std::set < regexp::UnboundedRegExpSymbol > follow3 = regexp::GlushkovTraversal::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol ( * symbolsIter ) ); - CPPUNIT_ASSERT(follow3.size() == 3); + CPPUNIT_ASSERT ( follow3.size ( ) == 3 ); symbolsIter++; - std::set<regexp::UnboundedRegExpSymbol> follow4 = regexp::GlushkovTraversal::follow(indexedRegExp, regexp::UnboundedRegExpSymbol ( *symbolsIter) ); + std::set < regexp::UnboundedRegExpSymbol > follow4 = regexp::GlushkovTraversal::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol ( * symbolsIter ) ); - CPPUNIT_ASSERT(follow4.size() == 3); + CPPUNIT_ASSERT ( follow4.size ( ) == 3 ); symbolsIter++; - std::set<regexp::UnboundedRegExpSymbol> follow5 = regexp::GlushkovTraversal::follow(indexedRegExp, regexp::UnboundedRegExpSymbol ( *symbolsIter) ); + std::set < regexp::UnboundedRegExpSymbol > follow5 = regexp::GlushkovTraversal::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol ( * symbolsIter ) ); - CPPUNIT_ASSERT(follow5.size() == 0); + CPPUNIT_ASSERT ( follow5.size ( ) == 0 ); } - } -