diff options
| author | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-18 11:53:36 +0200 |
|---|---|---|
| committer | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-18 11:53:36 +0200 |
| commit | b4f4959d8401af0b68cc00ba199a6ef73cab21e5 (patch) | |
| tree | dd3885750cb95a947d88e615b38d285539510964 /lex.h | |
| parent | c454374b73b748dd711554b275ffaf62001b1fc9 (diff) | |
rewrite preproc for arenas
Diffstat (limited to 'lex.h')
| -rw-r--r-- | lex.h | 81 |
1 files changed, 12 insertions, 69 deletions
@@ -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); |
