diff options
| author | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-12 02:31:34 +0200 |
|---|---|---|
| committer | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-12 02:31:34 +0200 |
| commit | b59501340a5d6b1c0ace169f140391cc0555015e (patch) | |
| tree | 71e8da755209a63cf57c52907777485cda9f27e2 /lex.h | |
| parent | 30fd15dec535007340ffb0d8b7617a7b0d76ef3a (diff) | |
write some lexing; split code into files
Diffstat (limited to 'lex.h')
| -rw-r--r-- | lex.h | 72 |
1 files changed, 72 insertions, 0 deletions
@@ -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) |
