@fink/larix
Version:
A parser for generating fink's AST.
83 lines (73 loc) • 1.75 kB
JavaScript
import { map, filter } from "@fink/std-lib/iter.js";
import { curr_indentation } from "../block/indentation.js";
export const get_comments = ctx => {
const ind = curr_indentation(ctx);
let _do_result;
{
let ˆpipe_result_1 = ctx.ignored_tokens;
ˆpipe_result_1 = filter(token => {
const ˆvalue_2 = token;
/* istanbul ignore else */
if (ˆvalue_2 != null) {
const {
type: ˆp_4
} = ˆvalue_2;
/* istanbul ignore else */
if (ˆp_4 === `ignorable`) {
return false;
}
}
/* istanbul ignore else */
if (ˆvalue_2 != null) {
const {
loc: ˆp_5
} = ˆvalue_2;
/* istanbul ignore else */
if (ˆp_5 != null) {
const {
start: ˆp_6
} = ˆp_5;
/* istanbul ignore else */
if (ˆp_6 != null) {
const {
column: ˆp_7
} = ˆp_6;
/* istanbul ignore else */
if (ˆp_7 === ind) {
return true;
}
}
}
}
})(ˆpipe_result_1);
_do_result = ˆpipe_result_1 = map(({
type,
value,
loc
}) => {
const ˆvalue_8 = type;
/* istanbul ignore else */
if (ˆvalue_8 === `comment-sl`) {
return {
type: `comment`,
op: `#`,
loc,
value: value.slice(1)
};
}
{
return {
type: `comment`,
op: `---`,
loc,
value: value.slice(3, -3)
};
}
})(ˆpipe_result_1);
}
const [...comments] = _do_result;
_do_result = undefined;
return [comments, { ...ctx,
ignored_tokens: []
}];
};