UNPKG

@fink/larix

Version:

A parser for generating fink's AST.

173 lines (138 loc) 3.15 kB
const { _in_ } = require("@fink/js-interop/runtime.js"); const { next_lbp } = require("@fink/prattler/expressions.js"); const { next_is_end } = require("@fink/prattler/parser.js"); const { single_expression, expressions } = require("../block/expr.js"); const { end_of_block_indent, next_is_new_expr } = require("../block/indentation.js"); // TODO: move to lexer? const expr_end_tokens = [`,`, `:`, `}`, `]`, `)`, `str-expr-end`, `jsx-expr-end`]; exports.expr_end_tokens = expr_end_tokens; const next_is_call_arg = (callee, ctx) => { const ˆvalue_1 = ctx; /* istanbul ignore else */ if (ˆvalue_1 != null) { const { jsx: ˆp_3 } = ˆvalue_1; /* istanbul ignore else */ if (ˆp_3 === true) { return false; } } /* istanbul ignore else */ if (next_is_end(ˆvalue_1)) { return false; } // TODO /* istanbul ignore else */ if (ˆvalue_1 != null) { const { next_token: ˆp_4 } = ˆvalue_1; // TODO /* istanbul ignore else */ if (ˆp_4 != null) { const { type: ˆp_5 } = ˆp_4; // TODO /* istanbul ignore else */ if (_in_(ˆp_5, expr_end_tokens)) { return false; } } } /* istanbul ignore else */ if (0 < next_lbp(ˆvalue_1, callee)) { return false; } { return true; } }; exports.next_is_call_arg = next_is_call_arg; const call_expr = (ctx, callee, arg_block) => { const { start } = callee.loc; const [{ exprs, comments, loc }, next_ctx] = arg_block(ctx); let _do_result; ˆmatch_7: { const ˆvalue_6 = exprs; /* istanbul ignore else */ if (typeof ˆvalue_6?.[Symbol.iterator] === "function") { const [ˆa_8, ˆa_9] = ˆvalue_6; /* istanbul ignore else */ if (ˆa_8 !== undefined) /* istanbul ignore else */ if (ˆa_9 !== undefined) { _do_result = exprs; break ˆmatch_7; } } /* istanbul ignore else */ if (typeof ˆvalue_6?.[Symbol.iterator] === "function") { const [ˆa_10] = ˆvalue_6; /* istanbul ignore else */ if (ˆa_10 != null) { const { type: ˆp_11 } = ˆa_10; /* istanbul ignore else */ if (ˆp_11 === `empty`) { _do_result = []; break ˆmatch_7; } } } { _do_result = exprs; break ˆmatch_7; } } const args = _do_result; _do_result = undefined; return [{ type: `call`, callee, args, comments, loc: { ...loc, start } }, next_ctx]; }; exports.call_expr = call_expr; const maybe_call_expr = (expr, ctx) => { const ˆvalue_12 = ctx; /* istanbul ignore else */ if (next_is_new_expr(ˆvalue_12)) { return [expr, ctx]; } /* istanbul ignore else */ if (next_is_call_arg(expr, ˆvalue_12)) { { const indented_block = (ctx, block_expr = single_expression) => expressions(ctx, end_of_block_indent, block_expr); return call_expr(ctx, expr, indented_block); } } { return [expr, ctx]; } }; exports.maybe_call_expr = maybe_call_expr;