#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); }