diff options
author | s-over-4 | 2023-06-13 17:14:56 -0400 |
---|---|---|
committer | s-over-4 | 2023-06-13 17:14:56 -0400 |
commit | a85c68d5fa2ff2a55fe648fe84f0d7833ee5d72b (patch) | |
tree | e29e75eca5897e6aca83363006346bb04f9b6ef3 /src | |
parent | cadd9f414fada14319a5950e67721724cfd5089d (diff) |
gecc
Diffstat (limited to 'src')
-rw-r--r-- | src/include/token.h | 14 | ||||
-rw-r--r-- | src/lexer.c | 8 | ||||
-rw-r--r-- | src/main.c | 5 |
3 files changed, 12 insertions, 15 deletions
diff --git a/src/include/token.h b/src/include/token.h index dd0c42f..a42b81f 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -13,25 +13,21 @@ typedef struct TOKEN_STRUC { enum TOKEN_ENUM { TOKEN_KEYWORD, // keyword - TOKEN_PRIM_STR_DELIM, // ' TOKEN_PRIM_STR, // 'string' TOKEN_PRIM_INT, // 42 - TOKEN_COMM_DELIM, // ` TOKEN_COMM, // `comment` TOKEN_EXPR_END, // ; TOKEN_LGROUP, // ( TOKEN_RGROUP, // ) - TOKEN_DIRECTIVE_DELIM, // # TOKEN_DIRECTIVE, // #DIRECTIVE# TOKEN_FN_APPLY, // . TOKEN_LIST_DELIM, // , - TOKEN_DEF_TAGS_DELIM, // : - TOKEN_DEF, // def:def - TOKEN_BLOCK_DELIM_START, // { - TOKEN_BLOCK_DELIM_END, // } + TOKEN_DEF_TAG, // def:def + TOKEN_BLOCK_START, // { + TOKEN_BLOCK_END, // } TOKEN_NAMESPACE_DELIM, // / - TOKEN_ARRAY_DELIM_START, // [ - TOKEN_ARRAY_DELIM_END, // ] + TOKEN_ARRAY_START, // [ + TOKEN_ARRAY_END, // ] TOKEN_DEF_SET, // = TOKEN_UNKNOWN, // ??? TOKEN_EOF, // \0 diff --git a/src/lexer.c b/src/lexer.c index f4907eb..6cde958 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -71,16 +71,16 @@ token_t* lexer_get_next_token(lexer_t* lexer) { return lexer_next_token(lexer, TOKEN_LIST_DELIM); break; case ':': - return lexer_next_token(lexer, TOKEN_DEF_TAGS_DELIM); + return lexer_collect(lexer, ':', 1, 1, TOKEN_DEF_TAG); break; case '/': return lexer_next_token(lexer, TOKEN_NAMESPACE_DELIM); break; case '{': - return lexer_next_token(lexer, TOKEN_BLOCK_DELIM_START); + return lexer_next_token(lexer, TOKEN_BLOCK_START); break; case '}': - return lexer_next_token(lexer, TOKEN_BLOCK_DELIM_END); + return lexer_next_token(lexer, TOKEN_BLOCK_END); break; case '[': return lexer_collect(lexer, ']', 1, 1, TOKEN_PRIM_STR); @@ -115,7 +115,7 @@ char* lexer_get_c_as_string(lexer_t* lexer) { token_t* lexer_collect(lexer_t* lexer, char end_char, int fskip, int lskip, int type) { if (fskip) { lexer_next(lexer); } - size_t len = 1; // length of collected token so far + size_t len = 0; // length of collected token so far char* token = calloc(len, sizeof(char)); token[0] = '\0'; @@ -11,9 +11,9 @@ int main(int argc, char* argv[]) { long fsource_size; char *source; - fsource = fopen("examples/hello.halk", "rb"); + fsource = fopen("examples/simple.halk", "rb"); if (!fsource) { - die("source file not found: %s", "examples/hello.halk"); + die("source file not found"); }; fseek(fsource, 0L, SEEK_END); @@ -46,6 +46,7 @@ int main(int argc, char* argv[]) { while ((token = lexer_get_next_token(lexer)) != NULL) { log_inf("token type: [%d]\ttoken value: [%s]", token->type, token->value); + free(token); } fclose(fsource); |