Changed if-else symbo, cleaned up parsing a bit
This commit is contained in:
@@ -4,8 +4,12 @@ Lexer::Lexer(string source): source(source) {
|
||||
}
|
||||
|
||||
vector<shared_ptr<Token>> Lexer::getTokens() {
|
||||
shared_ptr<Token> token = nullptr;
|
||||
tokens.clear();
|
||||
currentIndex = 0;
|
||||
currentLine = 0;
|
||||
currentColumn = 0;
|
||||
|
||||
vector<shared_ptr<Token>> tokens;
|
||||
shared_ptr<Token> token;
|
||||
do {
|
||||
token = nextToken();
|
||||
// Got a nullptr, shouldn't have happened
|
||||
@@ -123,14 +127,6 @@ shared_ptr<Token> Lexer::nextToken() {
|
||||
token = match(TokenKind::SEMICOLON, ";", false);
|
||||
if (token != nullptr)
|
||||
return token;
|
||||
|
||||
token = match(TokenKind::QUESTION_QUESTION, "??", false);
|
||||
if (token != nullptr)
|
||||
return token;
|
||||
|
||||
token = match(TokenKind::QUESTION, "?", false);
|
||||
if (token != nullptr)
|
||||
return token;
|
||||
|
||||
token = match(TokenKind::LEFT_ARROW, "<-", false);
|
||||
if (token != nullptr)
|
||||
@@ -187,6 +183,14 @@ shared_ptr<Token> Lexer::nextToken() {
|
||||
return token;
|
||||
|
||||
// keywords
|
||||
token = match(TokenKind::IF, "if", true);
|
||||
if (token != nullptr)
|
||||
return token;
|
||||
|
||||
token = match(TokenKind::ELSE, "else", true);
|
||||
if (token != nullptr)
|
||||
return token;
|
||||
|
||||
token = match(TokenKind::FUNCTION, "fun", true);
|
||||
if (token != nullptr)
|
||||
return token;
|
||||
|
||||
Reference in New Issue
Block a user