summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-06-14 02:38:30 +0200
committerkdx <kikoodx@paranoici.org>2023-06-14 02:38:30 +0200
commit959b379b90ec95ea0813cc1228cd949872713ec2 (patch)
tree5bb04ed04831ce8b1788961c05ce237a2f30e5a0 /src
parentcd20e8bb36f6ef65bea0e062c66867cb80568152 (diff)
downloadgolem-959b379b90ec95ea0813cc1228cd949872713ec2.tar.gz
function piping
Diffstat (limited to 'src')
-rw-r--r--src/main.c52
1 files changed, 36 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
index 622ced0..8aa98ec 100644
--- a/src/main.c
+++ b/src/main.c
@@ -92,6 +92,8 @@ is_punct(const char *p)
return 2;
if (strchr("-+", p[0]) != NULL && p[0] == p[1])
return 2;
+ if (p[0] == '|' && p[1] == '>')
+ return 2;
return (strchr("+-/*()<>,;{}[]=&^|", p[0]) != NULL);
}
@@ -564,6 +566,29 @@ mul(Token **rest, Token *tok)
}
static Node *
+fncall(Token **rest, Token *tok)
+{
+ Node *node = new_word(tok);
+ tok = tok->next;
+ node->type = NOD_FNCALL;
+
+ /* args */
+ Node head = {0};
+ Node *cur = &head;
+
+ tok = skip(tok, "(");
+ while (tok->type != TOK_EOF && !equal(tok, ")")) {
+ cur = cur->next = expr(&tok, tok);
+ if (equal(tok, ","))
+ tok = tok->next;
+ }
+ *rest = skip(tok, ")");
+
+ node->rhs = head.next;
+ return node;
+}
+
+static Node *
primary(Token **rest, Token *tok)
{
if (equal(tok, "(")) {
@@ -605,23 +630,13 @@ primary(Token **rest, Token *tok)
if (tok->type == TOK_WORD && equal(tok->next, "(")) {
/* function call */
- Node *node = new_word(tok);
- tok = tok->next;
- node->type = NOD_FNCALL;
-
- /* args */
- Node head = {0};
- Node *cur = &head;
-
- tok = skip(tok, "(");
- while (tok->type != TOK_EOF && !equal(tok, ")")) {
- cur = cur->next = expr(&tok, tok);
- if (equal(tok, ","))
- tok = tok->next;
+ Node *node = fncall(&tok, tok);
+ Node *cur = node;
+ while (tok->type != TOK_EOF && equal(tok, "|>")) {
+ tok = tok->next;
+ cur = cur->lhs = fncall(&tok, tok);
}
- *rest = skip(tok, ")");
-
- node->rhs = head.next;
+ *rest = tok;
return node;
}
@@ -899,6 +914,11 @@ gen_fncall(Node *node)
printf("\tJRT ,__fn_%.*s\n", node->len, node->loc);
depth += 1;
+
+ if (node->lhs != NULL) {
+ depth -= 1;
+ gen_fncall(node->lhs);
+ }
}
static void