diff options
| author | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-22 14:09:14 +0200 |
|---|---|---|
| committer | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-22 14:09:14 +0200 |
| commit | 7a106ea8332ed6d95504fd3181f7b5f81a6c3072 (patch) | |
| tree | fcc7eccd435a42f062b87f6cd549658023b9437b /src/lexparse.c | |
| parent | 6d36e6517d5fdf02a583fa276d009f462da3ed84 (diff) | |
start work on cmdsub
Diffstat (limited to 'src/lexparse.c')
| -rw-r--r-- | src/lexparse.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/lexparse.c b/src/lexparse.c index eae5c16..2fcd909 100644 --- a/src/lexparse.c +++ b/src/lexparse.c @@ -16,6 +16,9 @@ typedef struct { DECLARE_MAYBE(Token, MaybeToken) +TokenVec* lex_level(char* line, size_t* pos, char until, TokenVecVec* tok_seq_pool); + + MaybeToken consolidate_buffer(LexingBuffer* buf) { if (buf->lit_germ.count > 0) { push_to_Word(&buf->word_germ, (Chunk){ @@ -40,11 +43,26 @@ MaybeToken consolidate_buffer(LexingBuffer* buf) { } -static MaybeChunk handle_dollar_expansion(char* line, size_t* pos, QuotationMode qmode) { +static MaybeChunk handle_dollar_expansion(char* line, size_t* pos, QuotationMode qmode, TokenVecVec* tok_seq_pool) { (*pos)++; if (line[*pos] == '(') { - // TODO - exit(66); + (*pos)++; + if (line[*pos] == '(') { + // TODO: arithm parsing + exit(66); + } else { + TokenVec* sub_region = lex_level(line, pos, ')', tok_seq_pool); + (*pos)++; // consume paren + return (MaybeChunk){ + .some = true, + .value = (Chunk){ + .qmode = qmode, + .kind = CHUNK_CMDSUB, + .as.cmdsub_toks = sub_region, + } + }; + } + } else if (line[*pos] == '_' || isalnum(line[*pos])){ String buf = make_String(256); while (line[*pos] == '_' || isalnum(line[*pos])) { @@ -96,7 +114,7 @@ static Chunk collect_single_q_section(char* line, size_t* pos) { }; } -static void collect_double_q_section(char* line, Word* result_buf, size_t* pos) { +static void collect_double_q_section(char* line, Word* result_buf, size_t* pos, TokenVecVec* tok_seq_pool) { // TODO: add the extra double-q expansions (*pos)++; String lit_buf = make_String(256); @@ -104,7 +122,7 @@ static void collect_double_q_section(char* line, Word* result_buf, size_t* pos) while (line[*pos] != '\"' && line[*pos] != '\0') { // TODO: handle escapes if (line[*pos] == '$') { - MaybeChunk m_dollar = handle_dollar_expansion(line, pos, DOUBLE_Q); + MaybeChunk m_dollar = handle_dollar_expansion(line, pos, DOUBLE_Q, tok_seq_pool); if (m_dollar.some) { if (lit_buf.count>0) { push_to_Word(result_buf, (Chunk){.qmode = DOUBLE_Q, .kind = CHUNK_LIT, .as.lit_str = inner(&lit_buf)}); @@ -211,9 +229,9 @@ TokenVec* lex_level(char* line, size_t* pos, char until, TokenVecVec* tok_seq_po Chunk chunk = collect_single_q_section(line, pos); push_to_Word(&buf.word_germ, chunk); } else if (line[*pos] == '\"') { - collect_double_q_section(line, &buf.word_germ,pos); + collect_double_q_section(line, &buf.word_germ,pos, tok_seq_pool); } else if (line[*pos] == '$') { - MaybeChunk dollar_chunk = handle_dollar_expansion(line, pos, UN_Q); + MaybeChunk dollar_chunk = handle_dollar_expansion(line, pos, UN_Q, tok_seq_pool); if (dollar_chunk.some) { push_to_Word(&buf.word_germ, dollar_chunk.value); } else { |
