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

safer detection of eof in string lexers

parent 0754dfa0
No related branches found
No related tags found
No related merge requests found
......@@ -20,12 +20,17 @@ AutomatonFromStringLexer::Token AutomatonFromStringLexer::next(std::istream& in)
 
L0:
character = in.get();
if(in.eof()) {
if ( in.eof ( ) || character == EOF ) { // for some reason the in stream was not setting eof bit for automata input without last newline
token.type = TokenType::TEOF;
return token;
} else if(character == ' ' || character == '\t') {
token.raw += character;
goto L0;
} else if(character == '\r') {
token.type = TokenType::NEW_LINE;
token.value += character;
token.raw += character;
return token;
} else if(character == '\n') {
token.type = TokenType::NEW_LINE;
token.value += character;
......
......@@ -18,7 +18,7 @@ ContainerFromStringLexer::Token ContainerFromStringLexer::next(std::istream& in)
 
L0:
character = in.get();
if(in.eof()) {
if ( in.eof ( ) || character == EOF ) {
token.type = TokenType::TEOF;
return token;
} else if(character == ' ' || character == '\n' || character == '\t') {
......
......@@ -18,7 +18,7 @@ GrammarFromStringLexer::Token GrammarFromStringLexer::next(std::istream& in) {
 
L0:
character = in.get();
if(in.eof()) {
if ( in.eof ( ) || character == EOF ) {
token.type = TokenType::TEOF;
return token;
} else if(character == ' ' || character == '\t' || character == '\n') {
......
......@@ -18,7 +18,7 @@ PrimitiveFromStringLexer::Token PrimitiveFromStringLexer::next(std::istream& in)
 
L0:
character = in.get();
if(in.eof()) {
if ( in.eof ( ) || character == EOF ) {
token.type = TokenType::TEOF;
return token;
} else if(character == ' ' || character == '\n' || character == '\t') {
......
......@@ -18,7 +18,7 @@ RegExpFromStringLexer::Token RegExpFromStringLexer::next(std::istream& in) {
 
L0:
character = in.get();
if(in.eof()) {
if ( in.eof ( ) || character == EOF ) {
token.type = TokenType::TEOF;
return token;
} else if(character == ' ' || character == '\n' || character == '\t') {
......
......@@ -18,8 +18,7 @@ StringFromStringLexer::Token StringFromStringLexer::next(std::istream& in) {
 
L0:
character = in.get();
if(in.eof()) {
if ( in.eof ( ) || character == EOF ) {
token.type = TokenType::TEOF;
return token;
} else if(character == ' ' || character == '\n' || character == '\t') {
......
......@@ -17,9 +17,9 @@ TreeFromStringLexer::Token TreeFromStringLexer::next ( std::istream & in ) {
token.raw = "";
char character;
 
L0: character = in.get ( );
if ( in.eof ( ) ) {
L0:
character = in.get ( );
if ( in.eof ( ) || character == EOF ) {
token.type = TokenType::TEOF;
return token;
} else if ( ( character == ' ' ) || ( character == '\n' ) || ( character == '\t' ) ) {
......
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