blob: fdd36c594595631c44d6e3728fb855a0fbe2da99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#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;
}
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);
}
|