aboutsummaryrefslogtreecommitdiff
path: root/src/brussel.codegen.comp/CodegenLexer.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2023-10-19 22:50:07 -0700
committerrtk0c <[email protected]>2023-10-19 22:50:07 -0700
commit2c92e07f337e42cf58970443f9de678f85a9b2a4 (patch)
tree075d5407e1e12a9d35cbee6e4c20ad34e0765c42 /src/brussel.codegen.comp/CodegenLexer.hpp
parent615809c036f604bce4582cea8ad49c64693f4f45 (diff)
The great renaming: switch to "module style"
Diffstat (limited to 'src/brussel.codegen.comp/CodegenLexer.hpp')
-rw-r--r--src/brussel.codegen.comp/CodegenLexer.hpp49
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);
+};