diff options
author | c+1 | 2023-05-18 13:16:49 -0400 |
---|---|---|
committer | c+1 | 2023-05-18 13:16:49 -0400 |
commit | 1b6a28f6a777350ae7e04d06a48cba62a09b2dfb (patch) | |
tree | e2d5da481a2bf5aa9ec5e6fc0bfd2767e234c8d4 | |
parent | a8bfa841540a13aea75fafcf11fe27688f1ea939 (diff) |
re-do all the syntax because why not
-rw-r--r-- | examples/v2.halk | 4 | ||||
-rw-r--r-- | src/include/token.h | 43 | ||||
-rw-r--r-- | src/token.c | 24 |
3 files changed, 51 insertions, 20 deletions
diff --git a/examples/v2.halk b/examples/v2.halk index c116ed7..1d35efd 100644 --- a/examples/v2.halk +++ b/examples/v2.halk @@ -13,4 +13,6 @@ void:say_hello.str:to = { ` functions need no special keyword ` io.stdout.to; } - +int:main.str[]:args = { ` start executing here ` + return.0; +} diff --git a/src/include/token.h b/src/include/token.h index 43d868c..bca00b1 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -5,31 +5,36 @@ typedef struct TOKEN_STRUC { enum { TOKEN_KEYWORD, // keyword - TOKEN_STR_DELIM, // '"' - TOKEN_STR, // "string" - TOKEN_COMM_DELIM_START, // '[' - TOKEN_COMM, // '[comment]' - TOKEN_COMM_DELIM_END, // ']' - TOKEN_DEFINE_CONST, // '=>' - TOKEN_DEFINE_MUT, // '->' - TOKEN_END, // ';' - TOKEN_LORD, // '(' - TOKEN_RORD, // ')' - TOKEN_DIRECTIVE_DELIM, // '#' + TOKEN_STR_DELIM, // ' + TOKEN_STR, // 'string' + 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_MODULE_MEMBER_DELIM, // ':' - TOKEN_BLOCK_DELIM_START, // '{' - TOKEN_BLOCK_DELIM_END, // '}' - TOKEN_ANY, // '_' - TOKEN_EOF, // '\0' + TOKEN_FN_APPLY, // . + TOKEN_LIST_DELIM, // , + TOKEN_DEF_ARGS_DELIM, // : + TOKEN_BLOCK_DELIM_START, // { + TOKEN_BLOCK_DELIM_END, // } + TOKEN_NAMESPACE_DELIM, // / + TOKEN_ARRAY_DELIM_START, // [ + TOKEN_ARRAY_DELIM_END, // ] + TOKEN_EOF, // \0 } type; char* value; } token_t; -extern token_t* token_init(int type, char* value); +int char_could_start_keyword(char* character); +int char_could_split_keyword(char* character); + +char TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS[] = "abcdefghijklmnopqrstuvwxyz_"; // chars that can begin a var name +char TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS[] = "1234567890_-"; // chars that can be in the rest of the var name, + // not including the ones already defined to begin + // one. #endif diff --git a/src/token.c b/src/token.c index e57ecd5..6991399 100644 --- a/src/token.c +++ b/src/token.c @@ -12,3 +12,27 @@ token_t* token_init(int type, char* val) { return token; } + +int char_could_start_keyword(char* character) { + for (int i = 0; i < 27; ++ i) { + if (TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS[i] == *character) { + return 1; + } + } + + return 0; +} + +int char_could_split_keyword(char* character) { + if (char_could_start_keyword(character)) { + return 1; + } else { + for (int i = 0; i < 12; ++ i) { + if (TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS[i] == *character) { + return 1; + } + } + + return 0; + } +} |