commit 514d15e

shrub  ·  2026-11-22 16:37:56 +0000 UTC
parent 1ab5afa
pipe
3 files changed,  +25, -4
M punc.h
+3, -3
 1@@ -1,8 +1,8 @@
 2 use <buffer.kav> as buf
 3 
 4 pub fn main(w: World) -> World {
 5-    val out = buf::stdout(w)
 6-    val out = buf::puts(out, "hello, world\n")
 7-    val _   = buf::close(out)
 8+    val _  = buf::stdout(w)
 9+        |> buf::puts("hello, world\n")
10+        |> buf::close()
11     w
12 }
+21, -1
 1@@ -8,6 +8,7 @@ static struct token tok;
 2 static struct expr *expr(void);
 3 static struct expr *block(void);
 4 static struct expr *call(void);
 5+static struct expr *pipe(void);
 6 static struct param *sortparams(void);
 7 
 8 static void
 9@@ -400,7 +401,7 @@ expr(void) {
10 		e->arm = head;
11 		return e;
12 	}
13-	return binary(1);
14+	return pipe();
15 }
16 
17 static struct expr *
18@@ -431,6 +432,25 @@ block(void) {
19 	return e;
20 }
21 
22+static struct expr *
23+pipe(void) {
24+	struct expr *l;
25+	struct expr *r;
26+	struct token op;
27+	l = binary(1);
28+	while(tok.kind == TPIPE) {
29+		op = tok;
30+		next();
31+		r = call();
32+		if(r->kind != ECALL)
33+			errorat(&op.loc, "expected a function call after |>");
34+		l->next = r->args;
35+		r->args = l;
36+		l = r;
37+	}
38+	return l;
39+}
40+
41 static struct param *
42 sortparam(void) {
43 	struct param *p;
M punc.h
+1, -0
1@@ -25,3 +25,4 @@ TOKEN(TUS,         "_" )
2 TOKEN(TTILDE,       "~")
3 TOKEN(TDCOLON,     "::")
4 TOKEN(TBANG,        "!")
5+TOKEN(TPIPE,       "|>")