aboutsummaryrefslogtreecommitdiff
path: root/src/include/lexer.h
diff options
context:
space:
mode:
authorc+12023-11-17 18:58:54 -0500
committerc+12023-11-17 18:58:54 -0500
commit2cc68205a1c0b746ad405607940e7183c4fb09b0 (patch)
treedd16a65479194da364929c71a22d6fb01b58f36a /src/include/lexer.h
parent7be0923d486cd6ed2e304d3673146563ad677ea7 (diff)
Cleaned up.
Diffstat (limited to 'src/include/lexer.h')
-rw-r--r--src/include/lexer.h58
1 files changed, 31 insertions, 27 deletions
diff --git a/src/include/lexer.h b/src/include/lexer.h
index d83e35f..02275cb 100644
--- a/src/include/lexer.h
+++ b/src/include/lexer.h
@@ -5,66 +5,70 @@
#include "syntax.h"
#include "token.h"
-#define LEXER_VALID (lexer->c != '\0' && lexer->i < strlen(lexer->content))
-
-/* the lexer struct */
+/* The Lexer. */
typedef struct LEXER_STRUC {
- /* source being read */
+ /* Source being read. */
char* src;
- /* what the lexer is looking at right now */
+ /* What the lexer is looking at right now. */
enum LEXER_STATE {
- /* normal 1-character token */
+ /* Normal 1-character token. */
LEXER_STATE_REG,
- /* definition tag */
+ /* Definition tag. */
LEXER_STATE_TAG,
- /* string */
+ /* String. */
LEXER_STATE_STR,
- /* escaped character in string */
+ /* Escaped character in string. */
LEXER_STATE_STR_ESC,
- /* integer */
+ /* Integer. */
LEXER_STATE_INT,
- /* keyword */
+ /* Keyword. */
LEXER_STATE_KWD,
} state;
- /* the linked list of tokens generated */
+ /* The linked list of tokens generated. */
token_t* tokenl;
- /* pointer to the last token in tokenl */
+ /* Pointer to the last token in tokenl. */
token_t* tokenl_last;
- /* number of tokens in tokenl */
+ /* Number of tokens in tokenl. */
int tokenc;
} lexer_t;
-/* create lexer from source */
+/* Create lexer from source. */
lexer_t* lexer_init (char* src);
-/* destroy lexer **but not src or tokenl** */
+/*
+ Destroy a lexer.
+ - Does not free `src.
+ - Does not free `tokenl`.
+*/
void lexer_destroy (lexer_t* lexer);
-/* add token to tokenl */
+/* Add token to tokenl. */
void lexer_add_token(lexer_t* lexer, token_t* token);
-/* add the current character as a token to tokenl -- utility function for
- lexer_do_reg() */
+/* Add the current character as a token to tokenl. Utility function `for lexer_do_reg()`. */
void lexer_add_current_char(lexer_t* lexer, int type);
-/* add first character of lexer's src to the value of the last token in tokenl, if it exists. otherwise, create new token and add it */
+/*
+ Add first character of given lexer's `src` to the value of the last token in `tokenl`, if it exists.
+ Otherwise, create new token and add it.
+*/
void lexer_add_current_char_to_last_token(lexer_t* lexer, int type);
-/* handle regular state */
+/* Handle regular state. */
void lexer_do_reg(lexer_t* lexer);
-/* handle definition tag state*/
+/* Handle definition tag. state*/
void lexer_do_tag(lexer_t* lexer);
-/* TODO: handle character state */
+/* TODO: handle character state. */
void lexer_do_chr(lexer_t* lexer);
-/* handle string state */
+/* Handle string state. */
void lexer_do_str(lexer_t* lexer);
-/* handle integer */
+/* Handle integer. */
void lexer_do_int(lexer_t* lexer);
-/* handle keywords */
+/* Handle keywords. */
void lexer_do_kwd(lexer_t* lexer);
-/* run lexer */
+/* Run lexer. */
void lexer_run(lexer_t* lexer);
#endif