diff options
author | s-over-4 | 2023-09-30 16:59:13 -0400 |
---|---|---|
committer | s-over-4 | 2023-09-30 16:59:13 -0400 |
commit | 2569231ab9876d59a5e14261bae81dca4d24e4e3 (patch) | |
tree | bff30779f3debbc604ec2da3d41f672f531be67e /src/include | |
parent | f675656431075450714f2a1054ea8db3a2897e26 (diff) |
use flag vars for preprocessor states
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/lexer.h | 42 | ||||
-rw-r--r-- | src/include/util.h | 18 |
2 files changed, 42 insertions, 18 deletions
diff --git a/src/include/lexer.h b/src/include/lexer.h index a65f119..28d0e6f 100644 --- a/src/include/lexer.h +++ b/src/include/lexer.h @@ -1,37 +1,53 @@ #ifndef LEXER_H #define LEXER_H - #include "token.h" - #define LEXER_VALID (lexer->c != '\0' && lexer->i < strlen(lexer->content)) +/* the lexer struct */ typedef struct LEXER_STRUC { - char c; // current character in content - unsigned int i; // index of c - char* content; // the code itself + /* current character in content */ + char c; + + /* index of c */ + unsigned int i; + + /* source being read */ + char* content; } lexer_t; -// constructor/destroyer +/* create lexer from source code */ extern lexer_t* lexer_init (char* content); + +/* destroy the lexer */ extern void lexer_destroy (lexer_t* lexer); -// advance the lexer +/* move lexer forward one char */ extern void lexer_next (lexer_t* lexer); + +/* skip useless characters */ extern void lexer_pass (lexer_t* lexer); -extern token_t* lexer_get_next_token (lexer_t* lexer); // chars -> tokens + +/* create tokens */ +extern token_t* lexer_get_next_token (lexer_t* lexer); + +/* create token and move 1 char */ extern token_t* lexer_next_token (lexer_t* lexer, int token_type); + +/* create string from lexer->c */ extern char* lexer_get_c_as_string (lexer_t* lexer); -// collectors -extern token_t* lexer_get_arr (lexer_t* lexer); +/* + int fskip: skip first char? + + int lskip: skip last char? +*/ extern token_t* lexer_collect (lexer_t* lexer, int (*end_char)(char), int fskip, int lskip, int type); -// special def collectors -extern token_t* lexer_get_directive (lexer_t* lexer); -extern token_t* lexer_get_keyword (lexer_t* lexer); +/* run lexer from source */ +lexer_t* lexer_run(lexer_t*); #endif diff --git a/src/include/util.h b/src/include/util.h index a7879e9..a2f887b 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -7,10 +7,18 @@ #include <stdio.h> -void die(const char* fmt, ...); -void log_err(const char* fmt, ...); -void log_inf(const char* fmt, ...); -void log_raw(const char* fmt, ...); -void log_war(const char* fmt, ...); +/* die and leave message */ +void die(const char*, ...); +/* log an error */ +void log_err(const char*, ...); +/* log some information */ +void log_inf(const char*, ...); +/* log something with no formatting */ +void log_raw(const char*, ...); +/* log a warning */ +void log_war(const char*, ...); + +/* does c appear in s? */ +int appears_in_str(char*, char*); #endif |