// joinVerbPrepNounPrepNouns.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 prep noun",
* by comparing the input string against entries in
* dictionary.verb_prep_noun_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">"jump from branch to vine"</code>
* becomes
* <code class="property">"jumpFrom_to branch vine"</code>
* </p>
* @memberOf adventurejs.Parser
* @method adventurejs.Parser#joinVerbPrepNounPrepNouns
* @param {String} input Player input.
* @returns {String}
*/
p.joinVerbPrepNounPrepNouns = function Parser_joinVerbPrepNounPrepNouns( input )
{
for( var i=0; i < this.dictionary.verb_prep_noun_prep_nouns.length; i++ )
{
var trio = this.dictionary.verb_prep_noun_prep_nouns[i][0];
var verb = trio.split(" ")[0];
var prep1 = trio.split(" ")[1];
var prep2 = trio.split(" ")[2];
var combined = this.dictionary.verb_prep_noun_prep_nouns[i][1];
/**
* Valid chars are alphanumeric, plus:
* " " spaces, used as delimeters
* "_" underscores, used to serialize compound names
* "," commas, stripped from input but then used with multiple search results
* "=" used with multiple search results
* "&" used with multiple search results
*/
var search = verb + " " + prep1 + " ([,_=&A-Za-z0-9]*) " + prep2 + " ([,_=&A-Za-z0-9]*)";
var regex = new RegExp(search,"g");
var replaced = input.replace(regex, combined + " $1" + " $2");
if( replaced !== input )
{
// save a record of the original input
this.input_history[ 0 ].input_verb = trio;
this.input_history[ 0 ].joint = "verb_prep_noun_prep_noun";
input = replaced;
break;
}
}
this.game.log( "log", "high", "parseInput.js > joinVerbPrepNounPrepNouns returns: " + input, 'Parser' );
return input;
}
}());