From 8f4eb9fc953512365f9258ffd5d11ed8950f77a9 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Tue, 13 Jun 2023 01:23:42 -0700 Subject: added indentation support for |as rule --- lexer.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lexer.c') diff --git a/lexer.c b/lexer.c index 5df1103..c6c4ffe 100644 --- a/lexer.c +++ b/lexer.c @@ -1,5 +1,4 @@ #include -#include #include #include "lexer.h" @@ -21,6 +20,8 @@ char* tttos(tokenType_t tokenType) { return "ERR"; case EOL: return "EOL"; + case INDENT: + return "INDENT"; case STRING: return "STRING"; case INT: @@ -53,7 +54,7 @@ char* tttos(tokenType_t tokenType) { } int advance_whitespace(char** linePointer) { int64_t a = (int64_t)linePointer; - while (**linePointer == ' ' || **linePointer == ' ') { + while (**linePointer == ' ') { (*linePointer)++; } return (int)((int64_t)linePointer - a); @@ -67,13 +68,11 @@ tokenSet_t lex_line(char* line) { while (1) { token_t t = lex_first_token(p); if (t.type == EOL) { - printf("eol\n"); break; } if (t.type == ERR) { exit(1); } - printf("good\n"); tokens[i] = t; i++; } @@ -89,7 +88,6 @@ token_t lex_first_token(char** content) { s[c] = **content; s[c+1] = '\0'; (*content)++; - printf("lexing: %c\n", s[c]); /* check if we need to parse a string or an int */ if (s[c] >= 65 && s[c] <= 90) { free(s); @@ -114,6 +112,10 @@ token_t lex_first_token(char** content) { free(s); return init_token(START_COMMENT, NULL); } + else if (strcmp(s, " ") == 0) { + free(s); + return init_token(INDENT, NULL); + } else if (strcmp(s, "|") == 0) { free(s); return init_token(JUSTIFICATION, NULL); @@ -155,7 +157,6 @@ token_t lex_first_token(char** content) { return init_token(BI_IMPLICATION, NULL); } else if (c <= m) { - printf("c: %d\n", c); c++; continue; } -- cgit v1.3.1