// joinVerbPrepNouns.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 noun",
* by comparing the input string against entries in
* dictionary.verb_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">"look in desk"</code>
* becomes
* <code class="property">"lookIn desk"</code>
* </p>
* @memberOf adventurejs.Parser
* @method adventurejs.Parser#joinVerbPrepNouns
* @param {String} input Player input.
* @returns {String}
*/
p.joinVerbPrepNouns = function Parser_joinVerbPrepNouns( input )
{
for( var i=0; i < this.dictionary.verb_prep_nouns.length; i++ )
{
var pair = this.dictionary.verb_prep_nouns[i];
//var replaced = input.replace( pair[0], pair[1] );
// search anywhere in string
//var search = "\\b"+pair[0]+"\\b";
// only search beginning of string
// important for cases like "put plug in sink" so we don't concat "plugIn"
var search = "^(\\b" + pair[0] + "\\b)";
var regex = new RegExp(search,"g");
var replaced = input.replace( regex, pair[1] );
if( replaced !== input )
{
console.warn( 'pair[0]', pair[0] );
console.warn( 'pair[1]', pair[1] );
// save a record of the original input
this.input_history[ 0 ].input_verb = pair[0];
this.input_history[ 0 ].joint = "verb_prep_noun";
input = replaced;
break;
}
}
this.game.log( "log", "high", "parseInput.js > joinVerbPrepNouns returns: " + input, 'Parser' );
return input;
}
}());