aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/token.h2
-rw-r--r--src/main.c10
-rw-r--r--src/token.c64
-rw-r--r--src/util.c3
4 files changed, 71 insertions, 8 deletions
diff --git a/src/include/token.h b/src/include/token.h
index a42b81f..f05e962 100644
--- a/src/include/token.h
+++ b/src/include/token.h
@@ -38,6 +38,8 @@ typedef struct TOKEN_STRUC {
token_t* token_init(int type, char* val);
+char* token_get_type(int type);
+
int char_could_start_keyword(char* character);
int char_could_split_keyword(char* character);
int char_could_start_int(char* character);
diff --git a/src/main.c b/src/main.c
index 37f37bf..d98b98d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,17 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
-
#include "include/util.h"
+#include "include/token.h"
#include "include/lexer.h"
int main(int argc, char* argv[]) {
- FILE *fsource;
+ FILE* fsource;
long fsource_size;
- char *source;
+ char* source;
- fsource = fopen("examples/simple.halk", "rb");
+ fsource = fopen(argv[1], "rb");
if (!fsource) {
die("source file not found");
};
@@ -45,7 +45,7 @@ int main(int argc, char* argv[]) {
token_t* token = NULL;
while ((token = lexer_get_next_token(lexer)) != NULL) {
- log_inf("token type: [%d]\ttoken value: [%s]", token->type, token->value);
+ log_inf("token type: [%s]\ttoken value: [%s]", token_get_type(token->type), token->value);
free(token);
}
diff --git a/src/token.c b/src/token.c
index 6bba2b9..079a59f 100644
--- a/src/token.c
+++ b/src/token.c
@@ -12,6 +12,70 @@ token_t* token_init(int type, char* val) {
return token;
}
+char* token_get_type(int type) {
+ switch (type) {
+ case TOKEN_KEYWORD:
+ return "TOKEN_KEYWORD";
+ break;
+ case TOKEN_PRIM_STR:
+ return "TOKEN_PRIM_STR";
+ break;
+ case TOKEN_PRIM_INT:
+ return "TOKEN_PRIM_INT";
+ break;
+ case TOKEN_COMM:
+ return "TOKEN_COMM";
+ break;
+ case TOKEN_EXPR_END:
+ return "TOKEN_EXPR_END";
+ break;
+ case TOKEN_LGROUP:
+ return "TOKEN_LGROUP";
+ break;
+ case TOKEN_RGROUP:
+ return "TOKEN_RGROUP";
+ break;
+ case TOKEN_DIRECTIVE:
+ return "TOKEN_DIRECTIVE";
+ break;
+ case TOKEN_FN_APPLY:
+ return "TOKEN_FN_APPLY";
+ break;
+ case TOKEN_LIST_DELIM:
+ return "TOKEN_LIST_DELIM";
+ break;
+ case TOKEN_DEF_TAG:
+ return "TOKEN_DEF_TAG";
+ break;
+ case TOKEN_BLOCK_START:
+ return "TOKEN_BLOCK_START";
+ break;
+ case TOKEN_BLOCK_END:
+ return "TOKEN_BLOCK_END";
+ break;
+ case TOKEN_NAMESPACE_DELIM:
+ return "TOKEN_NAMESPACE_DELIM";
+ break;
+ case TOKEN_ARRAY_START:
+ return "TOKEN_ARRAY_START";
+ break;
+ case TOKEN_ARRAY_END:
+ return "TOKEN_ARRAY_END";
+ break;
+ case TOKEN_DEF_SET:
+ return "TOKEN_DEF_SET";
+ break;
+ case TOKEN_UNKNOWN:
+ return "TOKEN_UNKNOWN";
+ break;
+ case TOKEN_EOF:
+ return "TOKEN_EOF";
+ break;
+ default:
+ return "???";
+ }
+}
+
int char_could_start_keyword(char* character) {
for (int i = 0; i < TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS_LEN; ++ i) {
if (TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS[i] == *character) {
diff --git a/src/util.c b/src/util.c
index b4a2e15..1a7d256 100644
--- a/src/util.c
+++ b/src/util.c
@@ -35,12 +35,9 @@ void log_inf(const char* fmt, ...) {
void log_raw(const char* fmt, ...) {
va_list ap;
-
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
-
- fprintf(stderr, "\n");
}
void log_war(const char* fmt, ...) {