Skip to content

Commit 0b94642

Browse files
better support for complex conditionals
1 parent 39131e1 commit 0b94642

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/basic/main.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,23 @@ char *clean_basic(const char *program, char *output_buffer) {
105105
} else if (*p == '(' && !in_quotes) {
106106
bracket_depth++;
107107
} else if (*p == ')' && !in_quotes) {
108-
bracket_depth--;
108+
if (bracket_depth > 0) {
109+
bracket_depth--;
110+
}
109111
} else if (*p == '\'' && bracket_depth == 0 && !in_quotes) {
110112
/* If we see ' then skip it and anything after it to the end of the line or end of program */
111113
while (*p && *p != '\r' && *p != '\n') {
112114
p++;
113115
}
116+
continue;
114117
} else if (*p == '\t') {
115118
*d++ = ' ';
116119
p++;
120+
continue;
117121
}
118-
if (!in_quotes && bracket_depth > 0) {
119-
if (*p != ' ') {
120-
*d++ = *p++;
121-
} else {
122-
p++;
123-
}
124-
} else {
125-
*d++ = *p++;
126-
}
122+
123+
*d++ = *p++;
124+
127125
/* Remove extra newlines */
128126
if (*(p - 1) == '\n' || *(p - 1) == '\r') {
129127
while (*p == '\r' || *p == '\n') {

src/basic/unified_expression.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ static up_value up_factor(struct basic_ctx *ctx);
7575
static up_value up_factor(struct basic_ctx *ctx) {
7676
enum token_t tok = tokenizer_token(ctx);
7777

78+
/* Skip space */
79+
while (tok == NO_TOKEN) {
80+
tokenizer_next(ctx);
81+
tok = tokenizer_token(ctx);
82+
}
83+
7884
switch (tok) {
7985
case NUMBER: {
8086
/* Distinguish 123 vs 1.23 by peeking a dot in the lexeme. */

0 commit comments

Comments
 (0)