// tokenizeStrings.js
(function () {
/* global AdventureJS A */
var p = AdventureJS.Parser.prototype;
/**
* In dehydrateStrings() we converted arbitrary
* quote delimited substrings that aren't meant
* to be parsed, into symbols, basically to store
* them away so they didn't get transformed by
* other parser operations, and now we want
* to replace with the GlobalString placeholder class.
* <br><br>
* Example:<br>
* type "foo" on keyboard<br>
* Became:<br>
* type $0 on keyboard<br>
* And now becomes:<br>
* type global_string on keyboard<br>
* @memberOf AdventureJS.Parser
* @method AdventureJS.Parser#tokenizeStrings
* @param {String} input Player input.
* @returns {String}
*/
p.tokenizeStrings = function Parser_tokenizeStrings(input) {
this.game.log(
"L1559",
"log",
"high",
`[tokenizeStrings.js] tokenizeStrings() receive: ${input}`,
"Parser"
);
this.game.world.global_string.set({ values: [] });
const this_turn = this.input_history[0];
input = input.replace(/\$\d/g, (match) => {
const found = this_turn.quote_tokens[match];
if (found) {
this.game.log(
"L1278",
"log",
"high",
`tokenizeStrings > found quoted substring: ${found}`,
"Parser"
);
// save it to the global string object
this.game.world.global_string.values.push(found);
// @NOTE global_string.values gets reset at start
// of each turn save it to input as a backup
this_turn.strings.push(found);
return "global_string";
} else {
return match;
}
});
this.game.log(
"L1279",
"log",
"high",
`[tokenizeStrings.js] tokenizeStrings() return:\n${input}`,
"Parser"
);
return input;
};
})();