kach / nearley

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

out of memory error #510

Closed Floffah closed 4 years ago

Floffah commented 4 years ago

for some reason every time i test my grammar it runs out of memory.

i tracked it down to the comment part of my grammar causing the issue.

grammar

@builtin "whitespace.ne"

main -> _ main
   | comment main

comment -> "//" (_ | [a-z] | [A-Z]):* {%
    function(data) {
        return {
            type: "comment",
            message: data.join(""),
        }
    }
%}

test js file


const nearley = require("nearley");
const grammar = require("../parse/grammar.js");

const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));

parser.feed("// test ");

console.log(parser.results);
kach commented 4 years ago

Having a _ option inside a * leads to ambiguity. Try changing it to (_ [a-zA-Z]:+):*, that should make things better.