mecha icon indicating copy to clipboard operation
mecha copied to clipboard

If the mecha.many function is empty, returns a empty expression

Open catchex opened this issue 5 months ago • 4 comments

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);

catchex avatar Nov 06 '25 12:11 catchex