Pre-release
Adventure.js Docs Downloads
Score: 0 Moves: 0
// joinVerbPrepPrepNouns.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 noun",
   * by comparing the input string against entries in 
   * dictionary.verb_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 of boat"</code>
   * becomes 
   * <code class="property">"go_out boat"</code>
   * </p>
   * @memberOf adventurejs.Parser
   * @method adventurejs.Parser#joinVerbPrepPrepNouns
   * @param {String} input Player input.
   * @returns {String}
   */
   p.joinVerbPrepPrepNouns = function Parser_joinVerbPrepPrepNouns( input ) 
  {
		for( var i = 0; i < this.dictionary.verb_prep_prep_nouns.length; i++ ) 
    {
      var trio = this.dictionary.verb_prep_prep_nouns[i];
      //var replaced = input.replace( trio[0], trio[1] );

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

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

		}

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