Skip to content

Commit 90e7085

Browse files
committed
parserFnApp: Changed explicit fn marker to !, restructured the AST creation
1 parent 78e1594 commit 90e7085

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/lexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ inline static token lexerNext (lexerCtx* ctx) {
209209
case '[': case ']':
210210
case '{': case '}':
211211
case ',': case '`':
212+
case '!':
212213
tok.kind = tokenOp;
213214
lexerEat(ctx);
214215
}

src/parser.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ static ast* parseAtom (parserCtx* ctx) {
128128

129129
static bool waiting_for_delim (parserCtx* ctx) {
130130
bool seeLowPrecOp = see_kind(ctx, tokenOp)
131-
&& !(see(ctx, "(") || see(ctx, "["));
131+
&& !see(ctx, "(")
132+
&& !see(ctx, "[")
133+
&& !see(ctx, "!");
132134

133135
return waiting(ctx) && !seeLowPrecOp;
134136
}
@@ -147,37 +149,39 @@ static ast* parseFnApp (parserCtx* ctx) {
147149
vector(ast*) nodes = vectorInit(3, malloc);
148150

149151
/*Require at least one expr*/
150-
if (!see(ctx, "`"))
152+
if (!see(ctx, "!"))
151153
vectorPush(&nodes, parseAtom(ctx));
152154

153155
while (waiting_for_delim(ctx)) {
154-
if (try_match(ctx, "`")) {
156+
if (try_match(ctx, "!")) {
155157
if (fn) {
156-
error(ctx)("Multiple explicit functions in backticks: '%s'\n", ctx->current.buffer);
158+
error(ctx)("Multiple explicit functions: '%s'\n", ctx->current.buffer);
157159
vectorPush(&nodes, fn);
158160
}
159161

160162
fn = parseAtom(ctx);
161-
match(ctx, "`");
162163

163164
} else
164165
vectorPush(&nodes, parseAtom(ctx));
165166
}
166167

167-
if (nodes.length == 1) {
168+
if (fn)
169+
return astCreateFnApp(nodes, fn);
170+
171+
else if (nodes.length == 0) {
172+
/*Shouldn't happen due to the way it parses*/
173+
errprintf("FnApp took no AST nodes");
174+
return astCreateInvalid();
175+
176+
} else if (nodes.length == 1) {
177+
/*No application*/
168178
ast* node = vectorPop(&nodes);
169179
vectorFree(&nodes);
170180
return node;
171181

172-
} else if (nodes.length == 0 && fn) {
173-
error(ctx)("No arguments provided to backtick-marked function");
174-
return fn;
175-
176182
} else {
177-
/*If not explicitly marked in backticks, the last expr was the fn*/
178-
if (!fn)
179-
fn = vectorPop(&nodes);
180-
183+
/*The last node is the fn*/
184+
fn = vectorPop(&nodes);
181185
return astCreateFnApp(nodes, fn);
182186
}
183187
}

0 commit comments

Comments
 (0)