@fink/larix
Version:
A parser for generating fink's AST.
37 lines • 980 B
JavaScript
import { init_parser, start_parser } from "@fink/prattler/parser.js";
import { tokenize } from "./lexer/tokens.js";
import { init_language } from "./lang/init.js";
import { parse_module } from "./lang/module/init.js";
import { single_expression } from "./lang/block/expr.js";
export const init_tokens = ctx => {
const tokens = tokenize(ctx.code);
return { ...ctx,
tokens
};
};
export const init = ctx => {
let ˆpipe_result_1 = ctx;
ˆpipe_result_1 = init_tokens(ˆpipe_result_1);
ˆpipe_result_1 = init_parser(ˆpipe_result_1);
ˆpipe_result_1 = init_language(ˆpipe_result_1);
return ˆpipe_result_1 = start_parser(ˆpipe_result_1);
};
export const parse_expr = (code, filename) => {
const ctx = init({
code,
filename
});
const [expr, {
errors
}] = single_expression(ctx, 0);
return { ...expr,
errors
};
};
export const parse = (code, filename) => {
const ctx = init({
code,
filename
});
return parse_module(ctx);
};