summaryrefslogtreecommitdiff
path: root/lexer.c
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-06-13 01:23:42 -0700
committerKai Stevenson <kai@kaistevenson.com>2023-06-13 01:23:42 -0700
commit8f4eb9fc953512365f9258ffd5d11ed8950f77a9 (patch)
tree113ac7d09640e97fa678f098809b20b63c310286 /lexer.c
parent3bd120957d570756d396db8a112113f2ffb8f33b (diff)
added indentation support for |as rule
Diffstat (limited to 'lexer.c')
-rw-r--r--lexer.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/lexer.c b/lexer.c
index 5df1103..c6c4ffe 100644
--- a/lexer.c
+++ b/lexer.c
@@ -1,5 +1,4 @@
#include <stdlib.h>
-#include <stdio.h>
#include <string.h>
#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;
}