-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from dragonfly-lang/6-implement-scanning-to-fu…
…lfil-test-cases Implemented scanning to fulfil test cases
- Loading branch information
Showing
6 changed files
with
797 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
#ifndef LEXER_H | ||
#define LEXER_H | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <sstream> | ||
#include <optional> | ||
#include "token.h" | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <ctype.h> | ||
|
||
typedef struct { | ||
char* source; | ||
size_t position; | ||
} Lexer; | ||
|
||
Lexer* create_lexer(const char* source); | ||
Token lex_number(Lexer* lexer); | ||
Token lex_identifier(Lexer* lexer); | ||
Token lex_symbol(Lexer* lexer); | ||
Token lex_string(Lexer* lexer); | ||
Token is_keyword(Token token); | ||
TokenList* tokenise(const char* source); | ||
void free_lexer(Lexer* lexer); | ||
|
||
#endif // LEXER_H | ||
|
||
class Lexer { | ||
public: | ||
Lexer() = default; | ||
Lexer(std::string input); | ||
|
||
std::vector<Token> lex(std::string input); | ||
std::vector<Token> lex(); | ||
|
||
void reset(); | ||
|
||
Token lex_identifier(); | ||
Token lex_number(); | ||
Token lex_string(); | ||
Token lex_symbol(); | ||
Token lex_single_line_comment(); | ||
Token lex_multi_line_comment(); | ||
|
||
TokenType get_keyword(std::string input); | ||
|
||
private: | ||
std::vector<Token> tokens; | ||
std::string input; | ||
size_t index = 0; | ||
size_t line = 1; | ||
size_t column = 1; | ||
|
||
std::optional<char> peek() const; | ||
std::optional<char> peek_next() const; | ||
std::optional<char> advance(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.