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 --- parse.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'parse.c') diff --git a/parse.c b/parse.c index 6bea4af..75be330 100644 --- a/parse.c +++ b/parse.c @@ -1,9 +1,11 @@ #include #include "parse.h" #include "lexer.h" +#include "stdio.h" -line_t init_line(prop_t proposition, just_t justification) { +line_t init_line(int aLevel, prop_t proposition, just_t justification) { line_t line; + line.aLevel = aLevel; line.proposition = proposition; line.justification = justification; return line; @@ -39,14 +41,19 @@ lineSet_t parse_lines(char* content, int lineCount) { } line_t parse_line(char* content) { tokenSet_t ts = lex_line(content); - int i = 0; - while (ts.tokens[i].type != JUSTIFICATION) { - i++; + int c = 0; + int indent = 0; + while (ts.tokens[c].type != JUSTIFICATION) { + if (ts.tokens[c].type == INDENT) { + indent++; + } + c++; } int* seek = calloc(sizeof(int), 1); - prop_t prop = parse_proposition(init_tokenset(ts.tokens, i), seek, 0); - just_t just = parse_justification(init_tokenset(ts.tokens + i + 1, ts.count - (i + 1))); - return init_line(prop, just); + prop_t prop = parse_proposition(init_tokenset(ts.tokens + indent, c - indent), seek, 0); + just_t just = parse_justification(init_tokenset(ts.tokens + c + 1, ts.count - (c + 1))); + free(seek); + return init_line(indent, prop, just); } prop_t parse_proposition(tokenSet_t tokenSet, int* seek, char isNegative) { prop_t prop; -- cgit v1.3.1