summaryrefslogtreecommitdiff
path: root/scope.c
diff options
context:
space:
mode:
Diffstat (limited to 'scope.c')
-rw-r--r--scope.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/scope.c b/scope.c
new file mode 100644
index 0000000..722e430
--- /dev/null
+++ b/scope.c
@@ -0,0 +1,27 @@
+#include "scope.h"
+#include "group.h"
+#include "token.h"
+#include <stdio.h>
+
+void
+scope_extract(Token *list)
+{
+ // Recurse in child scopes.
+ for (Token *e = list->group.tokens; e != NULL; e = e->next)
+ if (e->type == TOK_GROUP)
+ scope_extract(e);
+ if (!token_isgroup(list, GROUP_SCOPE))
+ return;
+
+ // Extract let groups.
+ Token *e = list->group.tokens;
+ while (e != NULL)
+ if (token_isgroup(e, GROUP_LET)) {
+ token_append(&list->group.scope,
+ token_extract(&list->group.tokens, e));
+ group_extract(&list->group.scope,
+ token_last(list->group.scope));
+ e = list->group.tokens; // XXX: this is slow
+ } else
+ e = e->next;
+}