diff options
| author | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-12 12:25:14 +0200 |
|---|---|---|
| committer | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-12 12:25:14 +0200 |
| commit | a668be570b3b1b1d4c8a7e85159eece4080217c1 (patch) | |
| tree | 1e6a80e49efaf8a58ca6a92400245edd09d8ca8b | |
| parent | 9f0ac1740baac8f3a74ebacf5c62ecea700846d9 (diff) | |
outline a bit of parsing
| -rw-r--r-- | parse.c | 68 |
1 files changed, 68 insertions, 0 deletions
@@ -0,0 +1,68 @@ +#include "typeutils.h" +#include "lex.h" + +DECLARE_VEC(char*, StrVec) + + +typedef struct { + TokenVec tokens; + size_t pos; +} TokStream; + +typedef enum { + STDIN_REDIR, + STDOUT_REDIT, +} RedirKind; + + +typedef struct { + RedirKind kind; + + union { + char* std_redir_filename; + } as; +} Redirect; +DECLARE_VEC(Redirect, RedirectVec) + + +typedef struct { + StrVec args; + RedirectVec redirects; + // TODO: prefix variable settings +} Command; + + +typedef enum { + CONN_PIPE, + CONN_EOL, + // TODO: add the |& thingy +} Connector; + + +typedef struct { + Command cmd; + Connector conn; +} PipelineElement; + + +DECLARE_VEC(PipelineElement, Pipeline) + + +Command parse_command(TokStream* toks) { + StrVec args = make_StrVec(256); + RedirectVec redirects = make_RedirectVec(256); + for ( + Token curr_tok; + (curr_tok = toks->tokens.items[toks->pos], !(curr_tok.kind == TOK_SPECIAL && (curr_tok.as.spec == PIPE && curr_tok.as.spec == EOL))); + toks->pos++ + ) { + if (curr_tok.kind == TOK_SPECIAL) { + } + } +} + + +Pipeline parse_tokstream(TokenVec toks) { + TokStream tokstream = {.tokens = toks, .pos = 0}; + Pipeline result = make_Pipeline(256); +} |
