summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÁkos Kőrösi <korakos99@gmail.com>2026-05-12 15:14:24 +0200
committerÁkos Kőrösi <korakos99@gmail.com>2026-05-12 15:14:24 +0200
commit32babee5145bb0248566960a69b674484deb3f94 (patch)
tree8180b6a10b0c8b20bacd4d63bebe4fd731014f75
parentce7bc08b1db6011a82b27dbccf4e5502b948a820 (diff)
fixes
-rw-r--r--lex.c8
-rw-r--r--main.c3
-rw-r--r--parse.c4
-rw-r--r--parse.h5
4 files changed, 15 insertions, 5 deletions
diff --git a/lex.c b/lex.c
index 3689432..8ffb2a8 100644
--- a/lex.c
+++ b/lex.c
@@ -214,6 +214,11 @@ TokenVec lex_level(RawLine* line, char until, RegionVec* reg_arena) {
case '\"':
lex_double_quoted_section(line, &state.word_germ, reg_arena);
break;
+ case '|':
+ line->pos++;
+ close_word_and_lit_germs(&state);
+ push_to_TokenVec(&state.tokens, (Token){.kind = TOK_SPECIAL, .as.spec = PIPE});
+ break;
case '$':
line->pos++;
MaybeChunk mchunk = lex_expansion_chunk(line, reg_arena, UN_Q);
@@ -256,9 +261,8 @@ TokenVec lex_level(RawLine* line, char until, RegionVec* reg_arena) {
line->pos++;
push_to_TokenVec(&state.tokens, (Token){.kind = TOK_PROCSUB_IN, .as.procsub_region = reg_ptr});
- break;
} else {
- push_to_TokenVec(&state.tokens, (Token){.kind = TOK_SPECIAL, .as.spec = READ_REDIR});
+ push_to_TokenVec(&state.tokens, (Token){.kind = TOK_SPECIAL, .as.spec = READ_REDIR});
}
break;
default:
diff --git a/main.c b/main.c
index 4b39f66..690b6d9 100644
--- a/main.c
+++ b/main.c
@@ -4,7 +4,7 @@
#include <string.h>
#include "lex.h"
-
+#include "parse.h"
int main() {
char* line;
@@ -13,6 +13,7 @@ int main() {
if (line[0] == '\0') continue;
if (strcmp(line, "exit") == 0) exit(0);
LexResult res = lex(line);
+ Pipeline pl = parse_tokstream(res.top_tokens);
printf("%s \n", line);
}
diff --git a/parse.c b/parse.c
index b20b8dc..90b904e 100644
--- a/parse.c
+++ b/parse.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <stdio.h>
#include "lex.h"
#include "typeutils.h"
@@ -29,7 +30,7 @@ Command parse_command(TokStream* toks) {
RedirectVec redirects = make_RedirectVec(256);
for (
Token curr_tok;
- (curr_tok = toks->ptr[toks->pos], !(curr_tok.kind == TOK_SPECIAL && (curr_tok.as.spec == PIPE && curr_tok.as.spec == EOL)));
+ (curr_tok = toks->ptr[toks->pos], !(curr_tok.kind == TOK_SPECIAL && (curr_tok.as.spec == PIPE || curr_tok.as.spec == EOL)));
toks->pos++
) {
switch (curr_tok.kind) {
@@ -73,5 +74,6 @@ Pipeline parse_tokstream(TokenVec toks) {
Command cmd = parse_command(&tokstream);
Connector conn = parse_connector(&tokstream);
push_to_Pipeline(&result, (PipelineElement){.cmd = cmd, .conn = conn});
+ if (conn == CONN_EOL) break;
}
}
diff --git a/parse.h b/parse.h
index 8f95b44..5837a4f 100644
--- a/parse.h
+++ b/parse.h
@@ -42,7 +42,10 @@ typedef struct {
Connector conn;
} PipelineElement;
-
DECLARE_VEC(PipelineElement, Pipeline)
+Pipeline parse_tokstream(TokenVec toks);
+
+
+