aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/token.h17
-rw-r--r--src/lexer.c13
-rw-r--r--src/token.c1
3 files changed, 12 insertions, 19 deletions
diff --git a/src/include/token.h b/src/include/token.h
index b58233d..865ba4e 100644
--- a/src/include/token.h
+++ b/src/include/token.h
@@ -1,20 +1,21 @@
#ifndef TOKEN_H
#define TOKEN_H
-#define TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
-#define TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS_LEN 53
-#define TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS "1234567890_-"
-#define TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS_LEN 12
-#define TOKEN_CHAR_IGNORE " \t\n\r"
-#define TOKEN_CHAR_IGNORE_LEN 4
-#define TOKEN_CHAR_FIRST_CHAR_INT "0123456789"
+#define TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
+#define TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS_LEN 53
+#define TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS "1234567890_-"
+#define TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS_LEN 12
+#define TOKEN_CHAR_IGNORE " \t\n\r"
+#define TOKEN_CHAR_IGNORE_LEN 4
+#define TOKEN_CHAR_FIRST_CHAR_INT "0123456789"
+
typedef struct TOKEN_STRUC {
enum TOKEN_ENUM {
TOKEN_KEYWORD, // keyword
TOKEN_PRIM_STR_DELIM, // '
TOKEN_PRIM_STR, // 'string'
- TOKEN_PRIM_INT, // 'string'
+ TOKEN_PRIM_INT, // 42
TOKEN_COMM_DELIM, // `
TOKEN_COMM, // `comment`
TOKEN_EXPR_END, // ;
diff --git a/src/lexer.c b/src/lexer.c
index d137a07..5a0a6e9 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -3,7 +3,6 @@
#include <ctype.h>
#include <stdio.h>
-
#include "include/log.h"
#include "include/lexer.h"
@@ -150,7 +149,6 @@ token_t* lexer_get_next_token(lexer_t* lexer) {
token_t* lexer_next_token(lexer_t* lexer, token_t* token) {
lexer_next(lexer);
-
return token;
}
@@ -165,9 +163,7 @@ char* lexer_get_c_as_string(lexer_t* lexer) {
// fskip: skip first char?
// lskip: skip last char?
token_t* lexer_collect(lexer_t* lexer, char end_char, int fskip, int lskip, int type) {
- if (fskip) {
- lexer_next(lexer); // skip over starting character, e.g. opening quote or grave
- }
+ if (fskip) { lexer_next(lexer); }
size_t len = 0; // length of collected token so far
char* token = calloc(len, sizeof(char));
@@ -175,7 +171,7 @@ token_t* lexer_collect(lexer_t* lexer, char end_char, int fskip, int lskip, int
while (lexer->c != end_char) {
char* current = lexer_get_c_as_string(lexer);
- printf("[%p, %ld]\n", token, (strlen(token) + strlen(current) * sizeof(char)));
+ // printf("[%p, %ld]\n", token, (strlen(token) + strlen(current) * sizeof(char)));
token = realloc(
token,
(len + strlen(current) * sizeof(char))
@@ -186,10 +182,7 @@ token_t* lexer_collect(lexer_t* lexer, char end_char, int fskip, int lskip, int
lexer_next(lexer);
}
- if (lskip) {
- lexer_next(lexer);
- }
-
+ if (lskip) { lexer_next(lexer); }
token[len] = '\0'; // null terminate
return token_init(type, token);
diff --git a/src/token.c b/src/token.c
index 432d44f..6bba2b9 100644
--- a/src/token.c
+++ b/src/token.c
@@ -1,6 +1,5 @@
#include <stdlib.h>
-
#include "include/token.h"