diff options
author | kdx <kdx@42l.fr> | 2023-03-17 02:26:25 +0100 |
---|---|---|
committer | kdx <kdx@42l.fr> | 2023-03-17 02:26:25 +0100 |
commit | 4160e9650bcfe7449beb150cdf8196b768a92eb3 (patch) | |
tree | 14d4e2d4131d3c7a198466ba899efa5978808686 /scope.c | |
parent | a60f03db9ef3eb65b8898a9bf0ad70fbc2d2cc53 (diff) | |
download | golem-4160e9650bcfe7449beb150cdf8196b768a92eb3.tar.gz |
extract scope
Diffstat (limited to 'scope.c')
-rw-r--r-- | scope.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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; +} |