Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// joinCompoundVerbs.js

(function() {
  /*global adventurejs A*/ 
  "use strict";

	var p = adventurejs.Parser.prototype;

  /**
   * List of methods to be called during parse that perform
   * regex operations on input in order to join compound verb phrases.
   * @var adventurejs.Parser#joins
   * @type {Array}
   */
  p.joints = [
    "joinVerbPrepNounPrepNounPrepNouns",
    "joinVerbNounPrepPrepNouns",
    "joinVerbNounPrepNounPrepNouns",
    "joinVerbPrepNounPrepNouns",
    "joinVerbPrepPrepPrepNouns",
    "joinVerbPrepPrepNouns",
    "joinVerbNounPrepNouns",
    "joinVerbNounPreps",
    "joinVerbPrepNouns"
  ];

  /**
   * <code>joinCompoundVerbs</code>is a holdover from an earlier version 
   * of the parser that didn't parse prepositions as distinct words, but 
   * instead performed multiple regexs on input, finding patterns like 
   * "swing from tree to cliff on vine" and joining them into 
   * "swing_from_to_on tree cliff vine". All verbs were originally handled 
   * this way. Most now are not, with a few remaining exceptions. There 
   * are still some verbs with baked-in prepositions because it's just 
   * an easier way of catching variants like "get off" or "get down" and 
   * funneling them to the same chunk of logic while also distinguishing 
   * them from "get lamp".
   * <br><br>
   * The listed order of regex operations is important. We're calling them 
   * in order of longest to shortest, to ensure we don't accidentally 
   * catch partial phrases, like only finding "swing_from" out of 
   * "swing from tree to cliff on vine", and then not finding "swing_from_to_on",
   * which is (or was) a distinct verb.
   * @memberOf adventurejs.Parser
   * @method adventurejs.Parser#joinCompoundVerbs
   * @param {String} input Player input.
   * @returns {String}
   */
   p.joinCompoundVerbs = function Parser_joinCompoundVerbs( input ) 
  {    

    // join compound verb phrases
    if( 1 < input.split(" ").length )
    {
      for( var join = 0; join < this.joints.length; join++ )
      {
        input = this[this.joints[join]]( input );
      }
    }

		return input;
  }  
}());