From ca2fbad75901c661d8d5e1dea574b8074dbc56ba Mon Sep 17 00:00:00 2001 From: c+1 Date: Thu, 18 May 2023 13:28:04 -0400 Subject: moar --- src/include/token.h | 11 ++++++++--- src/token.c | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/include/token.h b/src/include/token.h index bca00b1..45154f4 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -28,13 +28,18 @@ typedef struct TOKEN_STRUC { char* value; } token_t; -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 +int TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS_LEN = 27; // maximum efficiency! 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. +int TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS_LEN = 12; +char TOKEN_CHAR_IGNORE[] = " \t\n\r"; // characters to ignore while parsing tokens +int TOKEN_CHAR_IGNORE_LEN = 4; + +int char_could_start_keyword(char* character); +int char_could_split_keyword(char* character); +int char_can_ignore(char* character); #endif diff --git a/src/token.c b/src/token.c index 6991399..9ea2ccf 100644 --- a/src/token.c +++ b/src/token.c @@ -14,7 +14,7 @@ token_t* token_init(int type, char* val) { } int char_could_start_keyword(char* character) { - for (int i = 0; i < 27; ++ i) { + for (int i = 0; i < TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS_LEN; ++ i) { if (TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS[i] == *character) { return 1; } @@ -27,7 +27,7 @@ int char_could_split_keyword(char* character) { if (char_could_start_keyword(character)) { return 1; } else { - for (int i = 0; i < 12; ++ i) { + for (int i = 0; i < TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS_LEN; ++ i) { if (TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS[i] == *character) { return 1; } @@ -36,3 +36,13 @@ int char_could_split_keyword(char* character) { return 0; } } + +int char_can_ignore(char* character) { + for (int i = 0; i < TOKEN_CHAR_IGNORE_LEN; ++ i) { + if (TOKEN_CHAR_IGNORE[i] == *character) { + return 1; + } + } + + return 0; +} -- cgit v1.2.3