lib/rules.js
function Rule(lhs, rhs, valuator) {
  let arr = [];

  if (!rhs || rhs.length === 0) {
    throw new Error('Rule does not produce anything');
  }
  arr.push.apply(arr, rhs);
  arr.lhs = lhs;

  Object.defineProperty(arr, 'lhs', { value: lhs });
  Object.defineProperty(arr, 'evaluate', {
    value: (values) => (valuator) ? valuator.apply(null, values) : null
  });

  arr.__proto__ = Rule.prototype;

  return arr;
}
function Rule(lhs, rhs, valuator) {
  let arr = [];

  if (!rhs || rhs.length === 0) {
    throw new Error('Rule does not produce anything');
  }
  arr.push.apply(arr, rhs);
  arr.lhs = lhs;

  Object.defineProperty(arr, 'lhs', { value: lhs });
  Object.defineProperty(arr, 'evaluate', {
    value: (values) => (valuator) ? valuator.apply(null, values) : null
  });

  arr.__proto__ = Rule.prototype;

  return arr;
}
function Rule ( lhs , rhs , valuator ) { let arr = [ ] ; if ( ! rhs || rhs . length === 0 ) { throw new Error ( 'Rule does not produce anything' ) ; } arr . push . apply ( arr , rhs ) ; arr . lhs = lhs ; Object . defineProperty ( arr , 'lhs' , { value : lhs } ) ; Object . defineProperty ( arr , 'evaluate' , { value : ( values ) => ( valuator ) ? valuator . apply ( null , values ) : null } ) ; arr . __proto__ = Rule . prototype ; return arr ; }
Defines a production rule, with a sole symbol on the left-hand side and a
list of symbols on the right-hand side. The constructor also accepts a third
argument, a valuator function, which can be used to evaluate values that are
obtained by matching this production

@class Rule
@extends Array
@constructor
@memberof module:lib/rules
@param {Sym} lhs - Sym representing the left hand side of the production
@param {Array.<Sym|string|RegExp>} rhs - Sequence of Syms, plain strings, or
RegExp objects that represents the right hand side of the production
@param {Function=} valuator - Function used to evaluate values obtained by
matching this production
Defines a production rule with a sole symbol on the left - hand side and a list of symbols on the right - hand side . The constructor also accepts a third argument a valuator function which can be used to evaluate values that are obtained by matching this production