diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 55b5720..52062a2 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -24,13 +24,13 @@ void Lexer::addRegEx(std::string regExString) { } Symbol Lexer::next() { - //std::cout << "Current at is \"" << input.substr(currentPosition,input.length()-1) << "\" currentPos is " << currentPosition << " out of " << input.length() <= input.length()) return Symbol("$EOF$", true); int longestMatch = -1; RegEx* longestRegEx = NULL; - std::string remainingString = input.substr(currentPosition,input.length()-1); + std::string remainingString = input.substr(currentPosition); for (std::vector::size_type i = 0; i < regExs.size(); i++) { //std::cout << "Trying regex " << regExs[i]->getPattern() << std::endl; int currentMatch = regExs[i]->longMatch(remainingString); @@ -42,11 +42,11 @@ Symbol Lexer::next() { if (longestRegEx != NULL) { std::string eatenString = input.substr(currentPosition, longestMatch); currentPosition += longestMatch; - //std::cout << "Current at is \"" << input.substr(currentPosition,input.length()-1) << "\" currentPos is " << currentPosition <getPattern(), true, eatenString); } else { //std::cout << "Found no applicable regex" << std::endl; - //std::cout << "Remaining is ||" << input.substr(currentPosition,input.length()-1) << "||" << std::endl; + //std::cout << "Remaining is ||" << input.substr(currentPosition) << "||" << std::endl; return Symbol(); } } @@ -92,5 +92,15 @@ void Lexer::test() { assert(lex.next() == Symbol()); } + // Lexer can consume all the input at once. + { + Lexer lex; + lex.addRegEx("xyzzy"); + lex.setInput("xyzzy"); + s = lex.next(); + assert(s.getName() == "xyzzy" && s.getValue() == "xyzzy"); + assert(lex.next() == Symbol("$EOF$", true)); + } + std::cout << "Lexer tests passed\n"; }