summaryrefslogtreecommitdiff
path: root/lex.h
diff options
context:
space:
mode:
Diffstat (limited to 'lex.h')
-rw-r--r--lex.h81
1 files changed, 12 insertions, 69 deletions
diff --git a/lex.h b/lex.h
index 2f3cc8e..6c3c8b9 100644
--- a/lex.h
+++ b/lex.h
@@ -1,87 +1,30 @@
#pragma once
+#include "defs.h"
#include "utils.h"
-
-typedef struct Region Region;
-
-
-typedef enum {
- UN_Q,
- SINGLE_Q,
- DOUBLE_Q,
-} QuotationMode;
-
-typedef enum {
- LITERAL,
- REGION_EXP,
- VAR_EXP, // TODO: Later include other exps
-} ChunkKind;
+DECLARE_VEC(Chunk, ChunkVec)
+DECLARE_VEC(Token, TokenVec)
typedef struct {
- ChunkKind kind;
- QuotationMode qmode;
- union {
- char* literal_str;
- Region* reg_ptr;
- char* varname;
- } as;
-} Chunk;
+ RegionVec regions;
+ TokenVec tokens;
+ ChunkVec chunks;
+} PreprocArena;
-DECLARE_VEC(Chunk, Word)
-
-DECLARE_VEC(Word, WordVec)
-
-typedef enum {
- TOK_WORD,
- TOK_SPECIAL,
- TOK_PROCSUB_IN,
- TOK_PROCSUB_OUT,
-} TokenKind;
-
-typedef enum {
- PIPE,
- WRITE_REDIR_TRUNC,
- WRITE_REDIR_APPEND,
- READ_REDIR,
- EOL,
-} SpecialToken;
-
typedef struct {
- TokenKind kind;
-
- union {
- Word word;
- SpecialToken spec;
- Region* procsub_region;
- } as;
-} Token;
-
-
-DECLARE_VEC(Token, TokenVec)
+ TokenVec top_tokens;
+ RegionVec reg_arena;
+} LexResult;
-DECLARE_MAYBE(SpecialToken, MaybeSpecialToken)
-typedef enum {
- CMDS,
- ARITHM,
-} RegionMode;
+TokenPtrVec lex(char* input, PreprocArena* arena);
-struct Region {
- RegionMode mode;
- TokenVec tokens;
-};
+
-DECLARE_MAYBE(Chunk, MaybeChunk);
-DECLARE_VEC(Region, RegionVec)
-typedef struct {
- TokenVec top_tokens;
- RegionVec reg_arena;
-} LexResult;
-LexResult lex(char* input);