From d3bc3eafd68f2d362a468800f6ef43e9f0cf87fb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Tr=C3=A1vn=C3=AD=C4=8Dek?= <jan.travnicek@fit.cvut.cz>
Date: Mon, 13 Dec 2021 22:01:53 +0100
Subject: [PATCH] str: attempt to simplify code

---
 .../automaton/AutomatonFromStringLexer.cpp    |  9 +++++----
 .../container/ContainerFromStringLexer.cpp    |  2 +-
 .../src/grammar/GrammarFromStringLexer.cpp    | 10 ++++++----
 .../primitive/PrimitiveFromStringLexer.cpp    |  8 ++++----
 alib2str/src/regexp/RegExpFromStringLexer.cpp |  7 ++++---
 alib2str/src/rte/RTEFromStringLexer.cpp       | 10 ++++++----
 alib2str/src/string/StringFromStringLexer.cpp |  5 +++--
 alib2str/src/tree/TreeFromStringLexer.cpp     | 14 +++++++-------
 examples2/automaton/DFA_no_new_line.txt       | 19 +++++++++++++++++++
 9 files changed, 55 insertions(+), 29 deletions(-)
 create mode 100644 examples2/automaton/DFA_no_new_line.txt

diff --git a/alib2str/src/automaton/AutomatonFromStringLexer.cpp b/alib2str/src/automaton/AutomatonFromStringLexer.cpp
index e5db4fedd2..75d2d9fc74 100644
--- a/alib2str/src/automaton/AutomatonFromStringLexer.cpp
+++ b/alib2str/src/automaton/AutomatonFromStringLexer.cpp
@@ -12,8 +12,8 @@ AutomatonFromStringLexer::Token AutomatonFromStringLexer::next(ext::istream& inp
 	char character;
 
 L0:
-	character = input.get();
-	if ( input.eof ( ) || character == EOF ) { // for some reason the input stream was not setting eof bit for automata input without last newline
+	character = static_cast < char > ( input.get ( ) );
+	if ( input.eof ( ) ) {
 		token.type = TokenType::TEOF;
 		return token;
 	} else if(character == '\r' || character == '\n') {
@@ -109,8 +109,9 @@ L0:
 		token.type = TokenType::ERROR;
 		return token;
 	}
+
 L1:
-	character = input.get();
+	character = static_cast < char > ( input.get ( ) );
 	if(input.eof()) {
 		token.type = TokenType::TEOF;
 		return token;
@@ -129,7 +130,7 @@ L1:
 	}
 
 L2:
-	character = input.get ( );
+	character = static_cast < char > ( input.get ( ) );
 	if ( input.eof ( ) ) {
 		return token;
 	} else if ( ( character >= '0' ) && ( character <= '9' ) ) {
diff --git a/alib2str/src/container/ContainerFromStringLexer.cpp b/alib2str/src/container/ContainerFromStringLexer.cpp
index 31abfa4da2..c0bd6314f0 100644
--- a/alib2str/src/container/ContainerFromStringLexer.cpp
+++ b/alib2str/src/container/ContainerFromStringLexer.cpp
@@ -10,7 +10,7 @@ ContainerFromStringLexer::Token ContainerFromStringLexer::next(ext::istream& inp
 	char character;
 
 L0:
-	character = input.get();
+	character = static_cast < char > ( input.get ( ) );
 	if ( input.eof ( ) || character == EOF ) {
 		token.type = TokenType::TEOF;
 		return token;
diff --git a/alib2str/src/grammar/GrammarFromStringLexer.cpp b/alib2str/src/grammar/GrammarFromStringLexer.cpp
index 7695d3364e..435ad618be 100644
--- a/alib2str/src/grammar/GrammarFromStringLexer.cpp
+++ b/alib2str/src/grammar/GrammarFromStringLexer.cpp
@@ -10,8 +10,8 @@ GrammarFromStringLexer::Token GrammarFromStringLexer::next(ext::istream& input)
 	char character;
 
 L0:
-	character = input.get();
-	if ( input.eof ( ) || character == EOF ) {
+	character = static_cast < char > ( input.get ( ) );
+	if ( input.eof ( ) ) {
 		token.type = TokenType::TEOF;
 		return token;
 	} else if ( ext::isspace ( character ) ) {
@@ -126,8 +126,9 @@ L0:
 		token.raw = "";
 		return token;
 	}
+
 L1:
-	character = input.get();
+	character = static_cast < char > ( input.get ( ) );
 	if(input.eof()) {
 		token.type = TokenType::TEOF;
 		return token;
@@ -144,8 +145,9 @@ L1:
 		token.type = TokenType::ERROR;
 		return token;
 	}
+
 L2:
-	character = input.get();
+	character = static_cast < char > ( input.get ( ) );
 	if(input.eof()) {
 		token.type = TokenType::TEOF;
 		return token;
diff --git a/alib2str/src/primitive/PrimitiveFromStringLexer.cpp b/alib2str/src/primitive/PrimitiveFromStringLexer.cpp
index ce1c01b7dc..1c01090f4c 100644
--- a/alib2str/src/primitive/PrimitiveFromStringLexer.cpp
+++ b/alib2str/src/primitive/PrimitiveFromStringLexer.cpp
@@ -10,8 +10,8 @@ PrimitiveFromStringLexer::Token PrimitiveFromStringLexer::next(ext::istream& inp
 	char character;
 
 L0:
-	character = input.get();
-	if ( input.eof ( ) || character == EOF ) {
+	character = static_cast < char > ( input.get ( ) );
+	if ( input.eof ( ) ) {
 		token.type = TokenType::TEOF;
 		return token;
 	} else if ( ext::isspace ( character ) ) {
@@ -36,7 +36,7 @@ L0:
 		return token;
 	}
 L1:
-	character = input.get();
+	character = static_cast < char > ( input.get ( ) );
 	if(input.eof()) {
 		return token;
 	} else if ( ( character >= 'a' && character <= 'z' ) || ( character >= 'A' && character <= 'Z' ) || character == '_' || ( character >= '0' && character <= '9' ) ) {
@@ -49,7 +49,7 @@ L1:
 		return token;
 	}
 L2:
-	character = input.get();
+	character = static_cast < char > ( input.get ( ) );
 	if(input.eof()) {
 		return token;
 	} else if(character >= '0' && character <= '9') {
diff --git a/alib2str/src/regexp/RegExpFromStringLexer.cpp b/alib2str/src/regexp/RegExpFromStringLexer.cpp
index ecea220328..5c23f8b046 100644
--- a/alib2str/src/regexp/RegExpFromStringLexer.cpp
+++ b/alib2str/src/regexp/RegExpFromStringLexer.cpp
@@ -10,8 +10,8 @@ RegExpFromStringLexer::Token RegExpFromStringLexer::next(ext::istream& input) {
 	char character;
 
 L0:
-	character = input.get();
-	if ( input.eof ( ) || character == EOF ) {
+	character = static_cast < char > ( input.get ( ) );
+	if ( input.eof ( ) ) {
 		token.type = TokenType::TEOF;
 		return token;
 	} else if ( ext::isspace ( character ) ) {
@@ -49,8 +49,9 @@ L0:
 		token.type = TokenType::ERROR;
 		return token;
 	}
+
 L1:
-	character = input.get();
+	character = static_cast < char > ( input.get ( ) );
 	if(input.eof()) {
 		token.type = TokenType::TEOF;
 		return token;
diff --git a/alib2str/src/rte/RTEFromStringLexer.cpp b/alib2str/src/rte/RTEFromStringLexer.cpp
index a08811b192..d0f79c67ca 100644
--- a/alib2str/src/rte/RTEFromStringLexer.cpp
+++ b/alib2str/src/rte/RTEFromStringLexer.cpp
@@ -10,8 +10,8 @@ RTEFromStringLexer::Token RTEFromStringLexer::next(ext::istream& input) {
 	char character;
 
 L0:
-	character = input.get();
-	if ( input.eof ( ) || character == EOF ) {
+	character = static_cast < char > ( input.get ( ) );
+	if ( input.eof ( ) ) {
 		token.type = TokenType::TEOF;
 		return token;
 	} else if ( ext::isspace ( character ) ) {
@@ -64,8 +64,9 @@ L0:
 		token.type = TokenType::ERROR;
 		return token;
 	}
+
 L1:
-	character = input.get();
+	character = static_cast < char > ( input.get ( ) );
 	if(input.eof()) {
 		token.type = TokenType::TEOF;
 		return token;
@@ -82,8 +83,9 @@ L1:
 		token.type = TokenType::ERROR;
 		return token;
 	}
-L2:	character = input.get ( );
 
+L2:
+	character = static_cast < char > ( input.get ( ) );
 	if ( input.eof ( ) ) {
 		return token;
 	} else if ( ( character >= '0' ) && ( character <= '9' ) ) {
diff --git a/alib2str/src/string/StringFromStringLexer.cpp b/alib2str/src/string/StringFromStringLexer.cpp
index 9f9a2f25ac..2824364efe 100644
--- a/alib2str/src/string/StringFromStringLexer.cpp
+++ b/alib2str/src/string/StringFromStringLexer.cpp
@@ -10,7 +10,7 @@ StringFromStringLexer::Token StringFromStringLexer::next(ext::istream& input) {
 	char character;
 
 L0:
-	character = input.get();
+	character = static_cast < char > ( input.get ( ) );
 	if ( input.eof ( ) || character == EOF ) {
 		token.type = TokenType::TEOF;
 		return token;
@@ -44,8 +44,9 @@ L0:
 		token.type = TokenType::ERROR;
 		return token;
 	}
+
 L1:
-	character = input.get();
+	character = static_cast < char > ( input.get ( ) );
 	if(input.eof()) {
 		token.type = TokenType::TEOF;
 		return token;
diff --git a/alib2str/src/tree/TreeFromStringLexer.cpp b/alib2str/src/tree/TreeFromStringLexer.cpp
index f57d936f4c..8f5259dda0 100644
--- a/alib2str/src/tree/TreeFromStringLexer.cpp
+++ b/alib2str/src/tree/TreeFromStringLexer.cpp
@@ -11,7 +11,7 @@ TreeFromStringLexer::Token TreeFromStringLexer::next ( ext::istream & input ) {
 	char character;
 
 L0:
-	character = input.get ( );
+	character = static_cast < char > ( input.get ( ) );
 	if ( input.eof ( ) || character == EOF ) {
 		token.type = TokenType::TEOF;
 		return token;
@@ -83,8 +83,8 @@ L0:
 		return token;
 	}
 
-L1:	character = input.get ( );
-
+L1:
+	character = static_cast < char > ( input.get ( ) );
 	if ( input.eof ( ) ) {
 		token.type = TokenType::TEOF;
 		return token;
@@ -112,8 +112,8 @@ L1:	character = input.get ( );
 		return token;
 	}
 
-L2:	character = input.get ( );
-
+L2:
+	character = static_cast < char > ( input.get ( ) );
 	if ( input.eof ( ) ) {
 		return token;
 	} else if ( ( character >= '0' ) && ( character <= '9' ) ) {
@@ -126,8 +126,8 @@ L2:	character = input.get ( );
 		return token;
 	}
 
-L3:	character = input.get ( );
-
+L3:
+	character = static_cast < char > ( input.get ( ) );
 	if ( input.eof ( ) ) {
 		token.type = TokenType::TEOF;
 		return token;
diff --git a/examples2/automaton/DFA_no_new_line.txt b/examples2/automaton/DFA_no_new_line.txt
new file mode 100644
index 0000000000..b92752c85a
--- /dev/null
+++ b/examples2/automaton/DFA_no_new_line.txt
@@ -0,0 +1,19 @@
+DFA a b c d
+0 1 - - -
+1 14 - - -
+10 - 2 - -
+11 - 8 - -
+12 - 7 - -
+13 - 16 - -
+14 - - 5 12
+15 - - - 13
+<16 - - - -
+<17 4 - - -
+2 15 - - -
+>3 10 9 0 12
+<4 - 11 - -
+<5 - 6 5 -
+<6 - - 5 -
+<7 - - - 12
+8 10 17 0 12
+9 4 - - -
\ No newline at end of file
-- 
GitLab