How to use the nearley.Rule 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 bijection / nearley-playground / src / client / compile.js View on Github external
function buildRule(ruleName, rule, env) {
        var tokens = []
        for (var i = 0; i < rule.tokens.length; i++) {
            var token = buildToken(ruleName, rule.tokens[i], env)
            if (token !== null) {
                tokens.push(token)
            }
        }
        return new nearley.Rule(ruleName, tokens, rule.postprocess)
    }
github bijection / nearley-playground / src / client / editor.js View on Github external
return rules.map(rule => 
        new nearley.Rule(rule.name, rule.symbols, rule.postprocess && ((data, ref, reject) => {
            var orig = rule.postprocess(data, ref, reject);
            if(typeof orig == 'object' && !orig.slice){
                orig.pos = ref;
            }
            return orig
        }))
    )
github mimic-sussex / sema / client / compiler / compiler-low-level.js View on Github external
function buildRule(ruleName, rule, env) {
		var tokens = [];
		for (var i = 0; i < rule.tokens.length; i++) {
			var token = buildToken(ruleName, rule.tokens[i], env);
			if (token !== null) {
				tokens.push(token);
			}
		}
		return new nearley.Rule(ruleName, tokens, rule.postprocess);
	}
github mimic-sussex / sema / client / compiler / compiler.js View on Github external
rule =>
			new nearley.Rule(
				rule.name,
				rule.symbols,
				rule.postprocess &&
					((data, ref, reject) => {
						var orig = rule.postprocess(data, ref, reject);
						if (orig === null) return null;
						if (typeof orig == "object" && !orig.slice) {
							orig.pos = ref;
						}
						return orig;
					})
			)
	);
github bijection / nearley-playground / src / client / high_level_compile.js View on Github external
return rules.map(rule => 
        new nearley.Rule(rule.name, rule.symbols, rule.postprocess && ((data, ref, reject) => {
            var orig = rule.postprocess(data, ref, reject);
            if(orig === null) 
                return null
            if(typeof orig == 'object' && !orig.slice){
                orig.pos = ref;
            }
            return orig
        }))
    )