How to use the nearley/lib/nearley.js.Parser 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 / src / language / nearley.worker.js View on Github external
import * as nearley from 'nearley/lib/nearley.js';
import * as grammar from './livelang.js';
import IRToJavascript from '../IR/IR.js'

var parserStartPoint;
let processor = nearley.Grammar.fromCompiled(grammar);
let parser = new nearley.Parser(processor);
parserStartPoint = parser.save();
console.log('Nearley parser loaded')

var ts = 0;
onmessage = (m) => {
  // console.log(m.data);
  if (m.data !== undefined) {
    try {
      parser.feed(m.data);
      // console.log(parser.results)
      postMessage({
        "treeTS": 1
      });
      console.log(JSON.stringify(parser.results));
      let jscode = IRToJavascript.treeToCode(parser.results);
      jscode.paramMarkers = JSON.stringify(jscode.paramMarkers);
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');
}