From b59501340a5d6b1c0ace169f140391cc0555015e Mon Sep 17 00:00:00 2001 From: Ákos Kőrösi Date: Tue, 12 May 2026 02:31:34 +0200 Subject: write some lexing; split code into files --- lex.h | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 lex.h (limited to 'lex.h') diff --git a/lex.h b/lex.h new file mode 100644 index 0000000..db4d713 --- /dev/null +++ b/lex.h @@ -0,0 +1,72 @@ +#include "typeutils.h" + + +typedef struct Region Region; + + +typedef enum { + UN_Q, + SINGLE_Q, + DOUBLE_Q, +} QuotationMode; + + +typedef enum { + LITERAL, + CMD_SUB, + ARITHM, + VAR_EXP, // TODO: Later include other exps +} ChunkKind; + + +typedef struct { + ChunkKind kind; + QuotationMode mode; + + union { + char* lit_str; + Region* sub_cmd_region; + Region* arithm_expr_region; + char* param_string; + } as; +} Chunk; + + +DECLARE_VEC(Chunk, ChunkVec) + +typedef enum { + TOK_WORD, + TOK_SPECIAL, +} TokenKind; + +typedef enum { + PIPE, + WRITE_REDIR_TRUNC, + WRITE_REDIR_APPEND, + READ_REDIR, + EOL, +} SpecialToken; + +typedef struct { + TokenKind kind; + + union { + ChunkVec word; + SpecialToken spec; + } as; +} Token; + + +DECLARE_VEC(Token, TokenVec) + +DECLARE_MAYBE(SpecialToken) + + +struct Region { + QuotationMode mode; + TokenVec tokens; +}; + +DECLARE_MAYBE(Chunk); + +DECLARE_VEC(Region, RegionVec) -- cgit v1.2.3