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

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

	var p = adventurejs.Parser.prototype;

  /**
   * <p>
   * In order to handle sentences with multiple clauses 
   * connected by conjunctions 'and' or 'but', we convert
   * them to symbols we can use down the line.
   * </p>
   * @memberOf adventurejs.Parser
   * @method adventurejs.Parser#stripConjunctions
   * @param {String} input Player input.
   * @returns {String}
   */
   p.stripConjunctions = function Parser_stripConjunctions( input ) 
  {    

    /* *
     * Convert " and " to "&" for later noun parsing
     * We've already removed instances of " and then " 
     * and we're assuming that any other use of "and" is in 
     * the form of "verb noun and noun".
     * We also look for ", and" as in "take x, and y"  
     * which seems less likely to be input, but not impossible.
     * Another possibility: "look between noun and noun" - may need a lookBetweenAnd verb
     * "put noun between noun and noun" - might need a putBetweenAnd verb
     */
    input = input.replace(/, and /g, "&");
    input = input.replace(/ and /g, "&");


    /* *
     * Also convert ", " to "&", for instances of:
     *  take sword, shield
     * 
     * There is an additional comma check in splitByThens,
     * because we assume English speakers will input things like
     *  take sword, then go north
     * But in that case we want to strip the comma.
     */
		input = input.replace(/, /g, "&");


    /* *
     * Convert " but " to " -". Used  
     * to omit specific items from collections.
     * Example:
     *  take all but sword
     */
    input = input.replace(/ but /g, " -");

		return input;
  }  
}());