From b4f4959d8401af0b68cc00ba199a6ef73cab21e5 Mon Sep 17 00:00:00 2001 From: Ákos Kőrösi Date: Mon, 18 May 2026 11:53:36 +0200 Subject: rewrite preproc for arenas --- lex.h | 81 ++++++++++--------------------------------------------------------- 1 file changed, 12 insertions(+), 69 deletions(-) (limited to 'lex.h') 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); -- cgit v1.2.3