Skip to content
Snippets Groups Projects
Commit dcc88843 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

allow empty lines and no newline after automaton

parent d85e6848
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -56,6 +56,8 @@ automaton::DFA < SymbolType, StateType > stringApi < automaton::DFA < SymbolType ...@@ -56,6 +56,8 @@ automaton::DFA < SymbolType, StateType > stringApi < automaton::DFA < SymbolType
token = automaton::AutomatonFromStringLexer::next(input); token = automaton::AutomatonFromStringLexer::next(input);
if(token.type == automaton::AutomatonFromStringLexer::TokenType::TEOF) if(token.type == automaton::AutomatonFromStringLexer::TokenType::TEOF)
break; break;
else if (token.type == automaton::AutomatonFromStringLexer::TokenType::NEW_LINE)
continue;
else else
automaton::AutomatonFromStringLexer::putback(input, token); automaton::AutomatonFromStringLexer::putback(input, token);
   
...@@ -102,7 +104,7 @@ void stringApi < automaton::DFA < SymbolType, StateType > >::parseTransition(std ...@@ -102,7 +104,7 @@ void stringApi < automaton::DFA < SymbolType, StateType > >::parseTransition(std
automaton::AutomatonFromStringLexer::Token token = automaton::AutomatonFromStringLexer::next(input); automaton::AutomatonFromStringLexer::Token token = automaton::AutomatonFromStringLexer::next(input);
typename ext::vector<SymbolType>::const_iterator iter = symbols.begin(); typename ext::vector<SymbolType>::const_iterator iter = symbols.begin();
   
while(token.type != automaton::AutomatonFromStringLexer::TokenType::NEW_LINE) { while ( token.type != automaton::AutomatonFromStringLexer::TokenType::NEW_LINE && token.type != automaton::AutomatonFromStringLexer::TokenType::TEOF ) {
if(iter == symbols.end()) if(iter == symbols.end())
throw exception::CommonException("Invalid line format"); throw exception::CommonException("Invalid line format");
   
......
...@@ -62,6 +62,8 @@ automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > stringApi < automat ...@@ -62,6 +62,8 @@ automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > stringApi < automat
token = automaton::AutomatonFromStringLexer::next(input); token = automaton::AutomatonFromStringLexer::next(input);
if(token.type == automaton::AutomatonFromStringLexer::TokenType::TEOF) if(token.type == automaton::AutomatonFromStringLexer::TokenType::TEOF)
break; break;
else if (token.type == automaton::AutomatonFromStringLexer::TokenType::NEW_LINE)
continue;
else else
automaton::AutomatonFromStringLexer::putback(input, token); automaton::AutomatonFromStringLexer::putback(input, token);
   
...@@ -109,8 +111,9 @@ void stringApi < automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > >: ...@@ -109,8 +111,9 @@ void stringApi < automaton::EpsilonNFA < SymbolType, EpsilonType, StateType > >:
automaton::AutomatonFromStringLexer::Token token = automaton::AutomatonFromStringLexer::next(input); automaton::AutomatonFromStringLexer::Token token = automaton::AutomatonFromStringLexer::next(input);
typename ext::vector<ext::variant<EpsilonType, SymbolType>>::const_iterator iter = symbols.begin(); typename ext::vector<ext::variant<EpsilonType, SymbolType>>::const_iterator iter = symbols.begin();
   
while(token.type != automaton::AutomatonFromStringLexer::TokenType::NEW_LINE) { while ( token.type != automaton::AutomatonFromStringLexer::TokenType::NEW_LINE && token.type != automaton::AutomatonFromStringLexer::TokenType::TEOF ) {
if(iter == symbols.end()) throw exception::CommonException("Invalid line format"); if(iter == symbols.end())
throw exception::CommonException("Invalid line format");
   
if(token.type != automaton::AutomatonFromStringLexer::TokenType::NONE) { if(token.type != automaton::AutomatonFromStringLexer::TokenType::NONE) {
automaton::AutomatonFromStringLexer::putback(input, token); automaton::AutomatonFromStringLexer::putback(input, token);
......
...@@ -54,6 +54,8 @@ automaton::MultiInitialStateNFA < SymbolType, StateType > stringApi < automaton: ...@@ -54,6 +54,8 @@ automaton::MultiInitialStateNFA < SymbolType, StateType > stringApi < automaton:
token = automaton::AutomatonFromStringLexer::next(input); token = automaton::AutomatonFromStringLexer::next(input);
if(token.type == automaton::AutomatonFromStringLexer::TokenType::TEOF) if(token.type == automaton::AutomatonFromStringLexer::TokenType::TEOF)
break; break;
else if (token.type == automaton::AutomatonFromStringLexer::TokenType::NEW_LINE)
continue;
else else
automaton::AutomatonFromStringLexer::putback(input, token); automaton::AutomatonFromStringLexer::putback(input, token);
   
...@@ -82,8 +84,9 @@ void stringApi < automaton::MultiInitialStateNFA < SymbolType, StateType > >::pa ...@@ -82,8 +84,9 @@ void stringApi < automaton::MultiInitialStateNFA < SymbolType, StateType > >::pa
automaton::AutomatonFromStringLexer::Token token = automaton::AutomatonFromStringLexer::next(input); automaton::AutomatonFromStringLexer::Token token = automaton::AutomatonFromStringLexer::next(input);
typename ext::vector<SymbolType>::const_iterator iter = symbols.begin(); typename ext::vector<SymbolType>::const_iterator iter = symbols.begin();
   
while(token.type != automaton::AutomatonFromStringLexer::TokenType::NEW_LINE) { while ( token.type != automaton::AutomatonFromStringLexer::TokenType::NEW_LINE && token.type != automaton::AutomatonFromStringLexer::TokenType::TEOF ) {
if(iter == symbols.end()) throw exception::CommonException("Invalid line format"); if(iter == symbols.end())
throw exception::CommonException("Invalid line format");
   
if(token.type != automaton::AutomatonFromStringLexer::TokenType::NONE) { if(token.type != automaton::AutomatonFromStringLexer::TokenType::NONE) {
automaton::AutomatonFromStringLexer::putback(input, token); automaton::AutomatonFromStringLexer::putback(input, token);
......
...@@ -56,6 +56,8 @@ automaton::NFA < SymbolType, StateType > stringApi < automaton::NFA < SymbolType ...@@ -56,6 +56,8 @@ automaton::NFA < SymbolType, StateType > stringApi < automaton::NFA < SymbolType
token = automaton::AutomatonFromStringLexer::next(input); token = automaton::AutomatonFromStringLexer::next(input);
if(token.type == automaton::AutomatonFromStringLexer::TokenType::TEOF) if(token.type == automaton::AutomatonFromStringLexer::TokenType::TEOF)
break; break;
else if (token.type == automaton::AutomatonFromStringLexer::TokenType::NEW_LINE)
continue;
else else
automaton::AutomatonFromStringLexer::putback(input, token); automaton::AutomatonFromStringLexer::putback(input, token);
   
...@@ -101,8 +103,9 @@ void stringApi < automaton::NFA < SymbolType, StateType > >::parseTransition(std ...@@ -101,8 +103,9 @@ void stringApi < automaton::NFA < SymbolType, StateType > >::parseTransition(std
automaton::AutomatonFromStringLexer::Token token = automaton::AutomatonFromStringLexer::next(input); automaton::AutomatonFromStringLexer::Token token = automaton::AutomatonFromStringLexer::next(input);
typename ext::vector < SymbolType >::const_iterator iter = symbols.begin(); typename ext::vector < SymbolType >::const_iterator iter = symbols.begin();
   
while(token.type != automaton::AutomatonFromStringLexer::TokenType::NEW_LINE) { while ( token.type != automaton::AutomatonFromStringLexer::TokenType::NEW_LINE && token.type != automaton::AutomatonFromStringLexer::TokenType::TEOF ) {
if(iter == symbols.end()) throw exception::CommonException("Invalid line format"); if(iter == symbols.end())
throw exception::CommonException("Invalid line format");
   
if(token.type != automaton::AutomatonFromStringLexer::TokenType::NONE) { if(token.type != automaton::AutomatonFromStringLexer::TokenType::NONE) {
automaton::AutomatonFromStringLexer::putback(input, token); automaton::AutomatonFromStringLexer::putback(input, token);
......
...@@ -40,13 +40,21 @@ void AutomatonTest::FSMStringParserTest() { ...@@ -40,13 +40,21 @@ void AutomatonTest::FSMStringParserTest() {
"1 2 - - - -\n" "1 2 - - - -\n"
"2 3 - - - -\n" "2 3 - - - -\n"
"3 - - 4 - -\n" "3 - - 4 - -\n"
"4 - 5 - - 5\n" "\n"
"<4 - 5 - - 5\n"
"<5 - - - - 3";
std::string input2 = "ENFA a b c d #E\n"
">0 3|4 5 1|3|4 - 2\n"
"1 2 - - - -\n"
"2 3 - - - -\n"
"3 - - 4 - -\n"
"<4 - 5 - - 5\n"
"<5 - - - - 3\n"; "<5 - - - - 3\n";
automaton::Automaton automaton = alib::StringDataFactory::fromString (input); automaton::Automaton automaton = alib::StringDataFactory::fromString (input);
   
std::string output = alib::StringDataFactory::toString(automaton); std::string output = alib::StringDataFactory::toString(automaton);
   
CPPUNIT_ASSERT( input == output ); CPPUNIT_ASSERT( input2 == output );
   
automaton::Automaton automaton2 = alib::StringDataFactory::fromString (output); automaton::Automaton automaton2 = alib::StringDataFactory::fromString (output);
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment