@fink/larix
Version:
A parser for generating fink's AST.
146 lines (122 loc) • 2.96 kB
JavaScript
import { _in_ } from "@fink/js-interop/runtime.js";
import { next_lbp } from "@fink/prattler/expressions.js";
import { next_is_end } from "@fink/prattler/parser.js";
import { single_expression, expressions } from "../block/expr.js";
import { end_of_block_indent, next_is_new_expr } from "../block/indentation.js";
// TODO: move to lexer?
export const expr_end_tokens = [`,`, `:`, `}`, `]`, `)`, `str-expr-end`, `jsx-expr-end`];
export 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;
}
};
export 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];
};
export 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];
}
};