summaryrefslogtreecommitdiff
path: root/src/lib/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/module.c')
-rw-r--r--src/lib/module.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/lib/module.c b/src/lib/module.c
new file mode 100644
index 0000000..4ce9f8c
--- /dev/null
+++ b/src/lib/module.c
@@ -0,0 +1,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);
+}