mecha
mecha copied to clipboard
If the mecha.many function is empty, returns a empty expression
try functionCall.parse(allocator, "call()");
pub const expression = mecha.oneOf(.{
functionCall,
binaryExpr,
parenExpression,
column,
stringLiteral,
numberLiteral,
});
const functionCall = mecha.recursiveRef(struct {
fn p(comptime _: anytype) mecha.Parser(Expression) {
return mecha.combine(.{
identifier.asStr(),
mecha.string("(").discard(),
mecha.many(token(Expression, expression), .{ .separator = mecha.ascii.char(',').discard() }),
mecha.string(")").discard(),
}).convert(struct {
fn p(allocator: std.mem.Allocator, expr_: anytype) !FunctionCall {
const name = expr_[0];
const rawArgs = expr_[1];
const finalArguments = try filterEmptyExpressions(allocator, rawArgs);
return FunctionCall{ .name = name, .arguments = finalArguments };
}
}.p).map(ast.toFunctionCall);
}
}.p);