UNPKG

@fink/larix

Version:

A parser for generating fink's AST.

40 lines 1.07 kB
import { add_operator } from "@fink/prattler/expressions.js"; import { curr_value } from "@fink/prattler/parser.js"; import { add_named_block } from "../block/init.js"; import { single_expression } from "../block/expr.js"; import { infix } from "../expressions.js"; export const infix_pipe = token_type => ({ ...infix(token_type, `call`), led: lbp => (ctx, left) => { const { loc: { start } } = left; const op = curr_value(ctx); const [callee, next_ctx] = single_expression(ctx, lbp); const { loc: { end } } = callee; return [{ type: `call`, callee, args: [left], op, loc: { start, end } }, next_ctx]; } }); export const add_pipe = ctx => { let ˆpipe_result_1 = ctx; ˆpipe_result_1 = add_named_block(`pipe`)(ˆpipe_result_1); return ˆpipe_result_1 = add_operator(infix_pipe(`|`))(ˆpipe_result_1); }; export const add_call_operators = ctx => { let ˆpipe_result_2 = ctx; return ˆpipe_result_2 = add_pipe(ˆpipe_result_2); };