diff options
| author | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-19 21:13:19 +0200 |
|---|---|---|
| committer | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-19 21:13:19 +0200 |
| commit | 2bdbf387261285d07e4b62d1e23c9e43efb14604 (patch) | |
| tree | 92b81d300f3c17d072f2a30362dafd815e57a758 /src/preproc.h | |
| parent | 6a391a1180766ac5717c40efa70d46cacca83f91 (diff) | |
restructure dir, create makefile
Diffstat (limited to 'src/preproc.h')
| -rw-r--r-- | src/preproc.h | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/preproc.h b/src/preproc.h new file mode 100644 index 0000000..7907f9d --- /dev/null +++ b/src/preproc.h @@ -0,0 +1,116 @@ +#pragma once + +#include "utils.h" + +typedef struct Region Region; + + +// Lexing stage +typedef enum { + UN_Q, + SINGLE_Q, + DOUBLE_Q, +} QuotationMode; + +typedef enum { + LITERAL, + REGION_EXP, + VAR_EXP, // TODO: Later include other exps +} ChunkKind; + +typedef struct { + ChunkKind kind; + QuotationMode qmode; + union { + char* literal_str; + Region* reg_ptr; + char* varname; + } as; +} Chunk; +DECLARE_MAYBE(Chunk, MaybeChunk); +DECLARE_VEC(Chunk*, Word) + +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; +DECLARE_MAYBE(SpecialToken, MaybeSpecialToken) + +typedef struct { + TokenKind kind; + + union { + Word word; + SpecialToken spec; + Region* procsub_region; + } as; +} Token; + + +DECLARE_VEC(Token*, TokenPtrVec) + + +typedef enum { + CMDS, + ARITHM, +} RegionMode; + +struct Region { + RegionMode mode; + TokenPtrVec tokens; +}; +DECLARE_VEC(Region, RegionVec) + + + +DECLARE_VEC(Chunk, ChunkVec) +DECLARE_VEC(Token, TokenVec) + + + +// Lexing + +typedef struct { + RegionVec regions; + TokenVec tokens; + ChunkVec chunks; +} PreprocArena; + + +TokenPtrVec lex(char* input, PreprocArena* arena); + + +// Parsing + +typedef enum { + CONN_PIPE, + CONN_EOL, + // TODO: add the |& thingy +} Connector; + +DECLARE_MAYBE(Connector, MaybeConnector) + +typedef struct { + TokenVec cmd_toks; + Connector conn; +} PipelineElement; + +DECLARE_VEC(PipelineElement, Pipeline) + +Pipeline parse_tokstream(Token* tokstream); + + + + + + |
