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

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

	var p = adventurejs.Parser.prototype;

  /**
   * <p>
   * Search input for compound verb phrases in the format of
   * "verb prep prep prep noun",
   * by comparing the input string against entries in 
   * dictionary.verb_prep_prep_prep_nouns, 
   * which was populated by Verb definitions.
   * If we find a set of words that match an entry, 
   * we compress the words into a single string
   * that is a Verb name.
   * </p> 
   * <p>
   * For example:<br>
   * <code class="property">"get out from behind boulder"</code>
   * becomes 
   * <code class="property">"go_out_from_behind boulder"</code>
   * </p>
   * @memberOf adventurejs.Parser
   * @method adventurejs.Parser#joinVerbPrepPrepPrepNouns
   * @param {String} input Player input.
   * @returns {String}
   */
   p.joinVerbPrepPrepPrepNouns = function Parser_joinVerbPrepPrepPrepNouns( input ) 
  {
		for( var i = 0; i < this.dictionary.verb_prep_prep_prep_nouns.length; i++ ) 
    {
      var quad = this.dictionary.verb_prep_prep_prep_nouns[i];
      //var replaced = input.replace( quad[0], quad[1] );

      var search = "\\b"+quad[0]+"\\b"; 
      var regex = new RegExp(search,"g");
      var replaced = input.replace( regex, quad[1] );

      if( replaced !== input ) 
      {
        // save a record of the original input
        this.input_history[ 0 ].input_verb = quad[0];
        this.input_history[ 0 ].joint = "verb_prep_prep_prep_noun";
        input = replaced;
        break;
      }

		}

    this.game.log( "log", "high", "parseInput.js > joinVerbPrepPrepPrepNouns returns: " + input, 'Parser' );
		return input;
  }  
}());