blob: 4ce9f8c38bc025076f631bc0060d5ec4aa9111be (
plain) (
blame)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include "aplwc_internal.h"
static int
read_keyword_decl(struct token_list *tokens, size_t offset)
{
int len;
for(len = 1; (offset + len) < tokens->length; len++)
if(tokens->tokens[offset+len].tag == TOKEN_TAG_NEWLINE)
break;
return len;
}
static int
read_function_decl(struct token_list *tokens, size_t offset)
{
int len;
for(len = 1; (offset + len) < tokens->length; len++)
if(tokens->tokens[offset+len].tag == TOKEN_TAG_DEL)
break;
return len;
}
static int
read_decl(struct token_list *tokens, size_t offset)
{
UNUSED_PARAMETER(tokens);
UNUSED_PARAMETER(offset);
switch(tokens->tokens[offset].tag){
case TOKEN_TAG_NEWLINE:
return 0;
case TOKEN_TAG_KEYWORD:
return read_keyword_decl(tokens, offset);
case TOKEN_TAG_DEL:
return read_function_decl(tokens, offset);
default:
return -1;
}
}
static enum aplwc_rc
read_decls(struct token_list *tokens)
{
size_t offset;
int skip;
for(offset = 0; offset < tokens->length; offset++){
skip = read_decl(tokens, offset);
if(skip == -1)
return APLWC_INVALID_SYNTAX;
offset += skip;
}
return APLWC_OK;
}
enum aplwc_rc
load_module(struct aplwc *aplwc, struct string *name, struct token_list *tokens)
{
UNUSED_PARAMETER(aplwc);
UNUSED_PARAMETER(name);
return read_decls(tokens);
}
|