Skip to content
Snippets Groups Projects
StringFromStringLexer.cpp 1021 B
Newer Older
  • Learn to ignore specific revisions
  • #include "StringFromStringLexer.h"
    
    namespace string {
    
    
    StringFromStringLexer::StringFromStringLexer(std::stringstream& in) : m_In(in) {
    	m_Current.type = TokenType::ERROR;
    	m_Current.value = "";
    
    }
    
    StringFromStringLexer& StringFromStringLexer::next() {
    	char character;
    	m_Current.value = "";
    
    L0:
    	character = m_In.get();
    	if(m_In.eof()) {
    
    		m_Current.type = TokenType::TEOF;
    
    		return *this;
    	} else if(character == ' ' || character == '\n' || character == '\t') {
    		goto L0;
    
    Jan Trávníček's avatar
    Jan Trávníček committed
    	} else if(character == '<') {
    
    		m_Current.type = TokenType::LESS;
    
    Jan Trávníček's avatar
    Jan Trávníček committed
    		m_Current.value += character;
    
    		return *this;
    
    Jan Trávníček's avatar
    Jan Trávníček committed
    	} else if(character == '>') {
    
    		m_Current.type = TokenType::GREATER;
    
    Jan Trávníček's avatar
    Jan Trávníček committed
    		m_Current.value += character;
    
    		return *this;
    
    	} else if(character == '"') {
    
    		m_Current.type = TokenType::QUOTE;
    
    		m_Current.value += character;
    		return *this;
    	} else {
    		m_In.unget();
    
    		m_Current.type = TokenType::ERROR;
    
    		return *this;
    	}
    }
    
    StringFromStringLexer::Token StringFromStringLexer::token() {
    	return m_Current;
    }
    
    
    } /* namespace string */