UNPKG

parsey

Version:

A parser for context-free grammars

42 lines (33 loc) 728 B
'use strict'; class Verb { constructor(name, inputs, output) { this.name = name; } apply(env, inputs) { if (inputs.length !== this.inputs.length) { return false; } env.statements.push({ name : this.name, inputs: inputs }); } check(env, inputs) { let matchingStatements = env.statements.filter((stmt) => { if ( stmt.name === this.name && stmt.inputs.reduce((doesMatch, value, i) => { return doesMatch && value.compare(this.inputs[i]); }, true) ) { return true; } return false; }); if (matchingStatements.length > 0) { return true; } return false; } } let v = new Verb('hello');