Skip to content
Snippets Groups Projects
ContainerFromStringLexer.cpp 1.58 KiB
Newer Older
#include "ContainerFromStringLexer.h"
namespace container {
Jan Trávníček's avatar
Jan Trávníček committed
ContainerFromStringLexer::Token ContainerFromStringLexer::next(ext::istream& input) {
	ContainerFromStringLexer::Token token;
	token.type = TokenType::ERROR;
	token.value = "";
	token.raw = "";
Jan Travnicek's avatar
Jan Travnicek committed
	character = input.get();
	if ( input.eof ( ) || character == EOF ) {
		token.type = TokenType::TEOF;
		return token;
	} else if ( ext::isspace ( character ) ) {
		token.raw += character;
	} else if(character == '{') {
		token.type = TokenType::SET_BEGIN;
		token.value += character;
		token.raw += character;
		return token;
	} else if(character == '}') {
		token.type = TokenType::SET_END;
		token.value += character;
		token.raw += character;
		return token;
	} else if(character == '[') {
		token.type = TokenType::VECTOR_BEGIN;
		token.value += character;
		token.raw += character;
		return token;
	} else if(character == ']') {
		token.type = TokenType::VECTOR_END;
		token.value += character;
		token.raw += character;
		return token;
	} else if(character == '<') {
		token.type = TokenType::PAIR_BEGIN;
		token.value += character;
		token.raw += character;
		return token;
	} else if(character == '>') {
		token.type = TokenType::PAIR_END;
		token.value += character;
		token.raw += character;
		return token;
	} else if(character == ',') {
		token.type = TokenType::COMMA;
		token.value += character;
		token.raw += character;
		return token;
Jan Travnicek's avatar
Jan Travnicek committed
		input.clear ( );
		input.unget ( );
		putback(input, token);
		token.raw = "";
		token.type = TokenType::ERROR;
		return token;
} /* namespace container */