import nearly from "npm:nearley";
import "./grammar.js";
// deno-lint-ignore no-explicit-any
const grammar = (window as unknown as any)["grammar"];

const compiled_grammar = nearly.Grammar.fromCompiled(grammar);

export type MappingData = {
    dst: number,
    src: number,
    range: number
}

export type MapType = { from: string, to: string, data: MappingData[] }

export type InputType = {
    seeds: number[],
    map: MapType[]
}

export function parseInput(input: string): InputType {
    const parser = new nearly.Parser(compiled_grammar);
    parser.feed(input);
    return parser.results[0];
}