summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx@42l.fr>2023-03-17 03:49:29 +0100
committerkdx <kdx@42l.fr>2023-03-17 03:49:29 +0100
commit1aa823effc534526c1bc2ec4ca80139826660f2f (patch)
tree8739530a2a8ec0df738cbdd72277b85bbfce2715
parent4160e9650bcfe7449beb150cdf8196b768a92eb3 (diff)
downloadgolem-1aa823effc534526c1bc2ec4ca80139826660f2f.tar.gz
scope function arguments
-rw-r--r--main.c1
-rw-r--r--scope.c20
-rw-r--r--scope.h1
-rw-r--r--token.c10
-rw-r--r--token.h1
5 files changed, 33 insertions, 0 deletions
diff --git a/main.c b/main.c
index 7ba3033..2a7b162 100644
--- a/main.c
+++ b/main.c
@@ -62,6 +62,7 @@ main(int argc, char **argv)
}
group->group.type = GROUP_SCOPE;
scope_extract(tokens);
+ scope_function(tokens);
token_print(tokens, 1, 0);
} while(0);
token_destroy(tokens);
diff --git a/scope.c b/scope.c
index 722e430..fdd36c5 100644
--- a/scope.c
+++ b/scope.c
@@ -25,3 +25,23 @@ scope_extract(Token *list)
} else
e = e->next;
}
+
+static void
+_scope_function(Token *list)
+{
+ unsigned int len = token_len(list->group.tokens);
+ while (len > 2) {
+ token_append(&list->group.scope,
+ token_extract(&list->group.tokens,
+ list->group.tokens->next));
+ len -= 1;
+ }
+}
+
+void
+scope_function(Token *list)
+{
+ for (Token *e = list->group.tokens; e != NULL; e = e->next)
+ if (token_isgroup(e, GROUP_FUNCTION))
+ _scope_function(e);
+}
diff --git a/scope.h b/scope.h
index 96ab8cb..1d5e1f1 100644
--- a/scope.h
+++ b/scope.h
@@ -2,3 +2,4 @@
#include "token.h"
void scope_extract(Token *list);
+void scope_function(Token *list);
diff --git a/token.c b/token.c
index 25223c0..6ec9f40 100644
--- a/token.c
+++ b/token.c
@@ -47,6 +47,16 @@ token_append(Token **list, Token *elem)
return *list;
}
+Token *
+token_prepend(Token **list, Token *elem)
+{
+ elem->next = *list;
+ if (*list)
+ (*list)->prev = elem;
+ *list = elem;
+ return *list;
+}
+
void
token_delete(Token **list, Token *elem)
{
diff --git a/token.h b/token.h
index 018ee10..fd378a5 100644
--- a/token.h
+++ b/token.h
@@ -38,6 +38,7 @@ struct Token {
Token *token_create(Slice slice, unsigned int type);
void token_destroy(Token *token);
Token *token_append(Token **list, Token *elem);
+Token *token_prepend(Token **list, Token *elem);
void token_delete(Token **list, Token *elem);
Token *token_extract(Token **list, Token *elem);
Token *token_search(Token *list, unsigned int type);