How to use the nearley/lib/generate.js function in nearley

To help you get started, we’ve selected a few nearley examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mimic-sussex / sema / client / compiler / compiler.js View on Github external
let errors = stream();
	let output = "";
	let positions = {};

	try {
		parser.feed(grammar);
		if (parser.results[0]) {
			function rangeCallback(name, start, end) {
				positions[name] = [start, end];
			}
			var c = compileLowLevel(parser.results[0], {
				rangeCallback: rangeCallback
			});
			lint(c, { out: errors });

			output = generate(c, "grammar");
		}
	} catch (e) {
		errors.write(e);
	}

	return {
		errors: errors.dump(),
		positions,
		output
	};
}
github bijection / nearley-playground / src / client / high_level_compile.js View on Github external
let parser = new nearley.Parser( AnnotatePositions(ParserRules), ParserStart, {lexer: Lexer} )

    let errors = stream()
    let output = ''
    let positions = {}

    try {
        parser.feed(grammar)            
        if(parser.results[0]){
            function rangeCallback(name, start, end){
                positions[name] = [start, end]
            }
            var c = compile(parser.results[0], { rangeCallback: rangeCallback });
            lint(c, {out: errors});

            output = generate(c, 'grammar')
        }
    } catch(e) {
        errors.write(e)
    }

    return {
        errors: errors.dump(),
        positions,
        output
    }
}
github kozily / nearley-loader / src / index.js View on Github external
module.exports = function(input) {
  var parser = new nearley.Parser(nearleyGrammar);
  parser.feed(input);
  var compilation = compile(parser.results[0], {file: this.resourcePath});
  lint(compilation, {});
  return generate(compilation, 'grammar');
}