kach / nearley

📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
https://nearley.js.org
MIT License
3.57k stars 232 forks source link

initializing parser out of memory v8 error #534

Closed Floffah closed 3 years ago

Floffah commented 3 years ago

basically i have a class that looks like:

import {Grammar, Parser} from "nearley";
import {readFileSync} from "fs";

export default class Actioniser {
    parsed: string[];
    parser: Parser;

    constructor(grammar: Grammar) {
        this.parser = new Parser(grammar);
    }

    start(_initpath: string) {
        this.parsed = readFileSync(_initpath, "utf8").split(/\r\n/g);
        for(let chunk of this.parsed) {
            this.parser.feed(chunk);
        }
        console.log(this.parser.results);
    }
}

I tracked it down to the this.parse = new parser that fails and its confusion just so you know in the file that initializes it im doing

function continuerun(_opts:any) {
    let grammar = require(resolve(__dirname, '../../../lang/o/grammar.js'));
    let actioniser = new Actioniser(Grammar.fromCompiled(grammar));

    if (!existsSync(resolve(process.cwd(), "project.json"))) {
        throw new Error("project.json file not found");
    }
    let project = require(resolve(process.cwd(), "project.json"));

    actioniser.start(resolve(process.cwd(), "src", project.compiler.entry));
}

and this is the full log: https://hastebin.com/yoyudafowa.rb and this is the outputted grammar file https://hastebin.com/otohemapev.js