diff options
Diffstat (limited to 'src/brussel.codegen.comp/CodegenLexer.hpp')
-rw-r--r-- | src/brussel.codegen.comp/CodegenLexer.hpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/brussel.codegen.comp/CodegenLexer.hpp b/src/brussel.codegen.comp/CodegenLexer.hpp new file mode 100644 index 0000000..ec8c8b7 --- /dev/null +++ b/src/brussel.codegen.comp/CodegenLexer.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include <LookupTable.hpp> + +#include <stb_c_lexer.h> +#include <span> +#include <string> +#include <string_view> +#include <vector> + +enum { + CLEX_ext_single_char = CLEX_first_unused_token, + CLEX_ext_double_colon, + CLEX_ext_dot_dot_dot, + CLEX_ext_COUNT, +}; + +struct StbLexerToken { + std::string text; + + union { + double lexerRealNumber; + long lexerIntNumber; + }; + + // Can either be CLEX_* or CLEX_ext_* values + int type; + + int Reamalgamate() const; +}; + +bool StbTokenIsSingleChar(int lexerToken); +bool StbTokenIsMultiChar(int lexerToken); +std::string CombineTokens(std::span<const StbLexerToken> tokens, std::string_view separator = {}); + +struct CodegenLexer { + std::vector<StbLexerToken> tokens; + size_t idx = 0; + + void InitializeFrom(std::string_view source); + + const StbLexerToken& Current() const; + + const StbLexerToken* TryConsumeToken(int type); + const StbLexerToken* TryConsumeSingleCharToken(char c); + + void SkipUntilToken(int type); + void SkipUntilTokenSingleChar(char c); +}; |