Blang/unittests/lex/test.cpp

65 lines
1.2 KiB
C++

#include <deque>
#include <iostream>
#include "Lexer.hpp"
using namespace std;
typedef enum {END_OF_STATEMENT, KEYWORD} TokenType;
typedef struct Token {
TokenType type;
} Token;
Lex::Lexer::Lexer(){
_functionList.push_back(function1);
}
void Lex::Lexer::function1(){
}
void Lex::Lexer::lexString(const string& text){
regex eos("^(?:[\n:])");
void (Lexer::*foo)() = function1;
(this->*foo)();
(this->*_functionList[0])();
regex keyword("^(?:if)");
deque<regex> regexList;
regexList.push_back(eos);
regexList.push_back(keyword);
unsigned int cursorPosition = 0;
smatch matchStrings;
while(cursorPosition < text.size()){
for(unsigned int i = 0; i < regexList.size(); i++){
if(regex_search(text.begin() + cursorPosition, text.end(), matchStrings, regexList[i])){
cout << matchStrings.str() << endl;
cursorPosition += matchStrings.length();
continue;
}
}
cursorPosition++;
}
}
void Lex::Lexer::registerCallback(const std::string& pattern, void (Lexer::*f)()){
_regexList.push_back(regex(pattern));
_functionList.push_back(f);
}
int main(int argc, char const *argv[]) {
Lex::Lexer lexer;
lexer.lexString("if you are: black, \n its good");
return 0;
}