Pre-release
AdventureJS Docs Downloads
Score: 0 Moves: 0

Defined in: Adventure/Parser.js, line 5

Description

The Parser class is the core that interprets player input. It takes a string from the player, sanitizes it of undesirable characters, strips away extraneous grammar such as definite/indefinite articles, performs a number of regular expression searches, compares the input against different verb/noun patterns stored in lookup tables, and streamlines the input into a verb, asset IDs, and prepositions. A sentence can be made up of one verb and up to three nouns. Clauses joined by 'and' or 'then' are split into multiple inputs and queued for serial handling. If you would like to see a detailed diagram of the process, see How the Parser Works.

This is an internal class that authors should not need to construct, though there are methods to allow authors to inject their own custom parser code. See Custom Parsers for more info.

Private Constructor:

var foo = new AdventureJS.Parser(game)

Parameters:

  • game Game
    A reference to the game instance.

Engine Classes

  • Input Parser class, used as a property of the parser instance, that stores a turn's parsed input.
  • ParsedNoun Special class used to store metadata about an asset and lists of all possible matches for that asset.

Asset Classes

Inherited Overrides

Index

Methods:

Properties:

Methods Collapse all  |  Expand all

categorizeAssets
categorizeAssets() → {object}

Defined in: Adventure/Parser/categorizeAssets.js, line 8

Categorize a list of asset ids for use with handleSentence.

Returns:

object
createParser
createParser(parsers)

Defined in: Adventure/Parser/createParser.js, line 7

Parameters:

  • parsers Object
    An object containing one or more parser functions.
Install custom parser(s) defined by author.
dehydrateStrings
dehydrateStrings(input) → {String|Boolean}

Defined in: Adventure/Parser/dehydrateStrings.js, line 8

Todos: escape $ in input

Parameters:

  • input String
Dehydration is a temporary step where we convert quoted substrings to simple symbols. Example: 'type "foo" on keyboard' => `type $0 on keyboard` We do this to preserve the contents of the substring exactly as entered rather than subjecting them to interpretation, even across queued turns.

Returns:

String | Boolean
disableParser
disableParser(parser)

Defined in: Adventure/Parser/disableParser.js, line 7

Parameters:

  • parser String
    The name of a previously created parser that has been stored at game.parser.custom_parsers[name].
Disable a custom parser(s) created by author.
enableParser
enableParser(parser)

Defined in: Adventure/Parser/enableParser.js, line 7

Parameters:

  • parser String
    The name of a previously created parser that has been stored at game.parser.custom_parsers[name].
Enable a custom parser(s) created by author.
excludeFromParsedNoun
excludeFromParsedNoun() → {object}

Defined in: Adventure/Parser.js, line 399

Exclude excludable assets from a parsedNoun.

Returns:

object
findMatchIn
findMatchIn(newQualified, oldQualified) → {Object}

Defined in: Adventure/Parser/findMatchIn.js, line 8

Parameters:

  • newQualified Object
  • oldQualified Object
Used by noun disambiguation in handleWord.js, typically in cases where user has been asked a question like "Which thing do you want, 1) A or 2) B ?", to compare this turn's input against last turn's input.

Returns:

Object foundMatch
getInputCount
getInputCount() → {int}

Defined in: Adventure/Parser.js, line 389

Get a count of input history.

Returns:

int
getLastInput
getLastInput() → {String}

Defined in: Adventure/Parser.js, line 379

Get input from last turn.

Returns:

String
getNewerInput
getNewerInput()

Defined in: Adventure/Parser.js, line 325

Listen for arrowDown key, used to present player input from previous turns in the input field, as in a terminal.
getOlderInput
getOlderInput()

Defined in: Adventure/Parser.js, line 306

Track input for display, used to present player input from previous turns in the input field, like a terminal does.
getRecentPronouns
getRecentPronouns()

Defined in: Adventure/Parser.js, line 256

Get the recent pronoun tracker.
handleSentence
handleSentence()

Defined in: Adventure/Parser/handleSentence.js, line 8

Handle multi-word input.
handleWord
handleWord()

Defined in: Adventure/Parser/handleWord.js, line 8

Handle single-word input.
isParsingMultiple
isParsingMultiple()

Defined in: Adventure/Parser.js, line 347

Todos: Is this and is_input_queued duplicative?

Method to get whether we're parsing through a queue of inputs. Possible redundant with is_input_queued?
normalizeInput
normalizeInput(input) → {String}

Defined in: Adventure/Parser/normalizeInput.js, line 8

Parameters:

  • input String
Normalize input addresses several common typos.
  • convert tabs to spaces
  • trim()
  • reduce multiple spaces
  • replace " ," with ","
  • replace " ." with "."

Returns:

String
parseInput
parseInput(input)

Defined in: Adventure/Parser/parseInput.js, line 8

Parameters:

  • input String
    Player input.
Parse an input string.
parseNoInput
parseNoInput()

Defined in: Adventure/Parser.js, line 358

Respond to blank input from player with settings.response_to_empty_input.
parseNoun
parseNoun(word) → {adventurejs.parsedNoun}

Defined in: Adventure/Parser/parseNoun.js, line 8

Parameters:

  • word String
Handle noun input by creating a new ParsedNoun object and then populating it. In other words parseNoun results in a ParsedNoun.

Returns:

adventurejs.parsedNoun
parseNumbers
parseNumbers(input) → {String}

Defined in: Adventure/Parser/parseNumbers.js, line 8

Parameters:

  • input String
    Player input.
Look for numbers, and replace with the GlobalNumber placeholder class.

Example:
type 10 on keyboard
Becomes:
type global_number on keyboard

Returns:

String
parseSentence
parseSentence()

Defined in: Adventure/Parser/parseSentence.js, line 8

Parse each word in a sentence.
parseVerb
parseVerb(verb) → {String}

Defined in: Adventure/Parser/parseVerb.js, line 8

Parameters:

  • verb String
    One word from input string.
Handle verb input. Verify a string against dictionary verbs. If string is a verb alias (ex: 'look at' is an alias for 'examine'), replace it with the primary verb.

Returns:

String
printNounDisambiguation
printNounDisambiguation(params)

Defined in: Adventure/Parser/printNounDisambiguation.js, line 8

Todos: support for platonics, ie which did you mean, a pistachio from the pouch, or the one | one that you're carrying?

Parameters:

  • params Object
qualifyParsedNoun
qualifyParsedNoun(params) → {adventurejs.parsedNoun}

Defined in: Adventure/Parser/qualifyParsedNoun.js, line 8

Parameters:

  • params Object
Exclude nouns found by parseNoun that don't meet requirements for verb found by parseVerb. Unique handling for each condition allows for precise responses. If it appears that the parser has found an unambiguous object, we refer directly to that object. When possible, we return that asset's name as the player input it rather than returning the object's proper name.

Returns:

adventurejs.parsedNoun
qualifyParsedVerb
qualifyParsedVerb(params)

Defined in: Adventure/Parser/qualifyParsedVerb.js, line 8

Parameters:

  • params Object
End turn if input verb can't act upon noun or in current circumstance.

Returns:

Object
rehydrateStrings
rehydrateStrings(input) → {String|Boolean}

Defined in: Adventure/Parser/rehydrateStrings.js, line 8

Parameters:

  • input String
Rehydrate substrings that have been reduced to symbols. Ex: 'type $0 on keyboard' => 'type "querty" on keyboard'.

Returns:

String | Boolean
resetRecentPronouns
resetRecentPronouns()

Defined in: Adventure/Parser.js, line 265

Todos: how to handle custom pronouns

Reset the recent pronoun tracker.
roboticizeInput
roboticizeInput(input) → {String}

Defined in: Adventure/Parser/roboticizeInput.js, line 8

Parameters:

  • input String
Remove some common phrases that are polite but unhelpful.

Returns:

String
saveVerbPhrase
saveVerbPhrase()

Defined in: Adventure/Parser/saveVerbPhrase.js, line 8

Record the verb phrase we wound up with after verifySentenceStructure. This makes up for the loss of same that we used to get from the tokenizeVerbs pass.
selectAll
selectAll(word) → {Array}

Defined in: Adventure/Parser/selectAll.js, line 8

Parameters:

  • word String
Get all gettable assets in current room.

Returns:

Array
selectCarried
selectCarried(list) → {Array}

Defined in: Adventure/Parser/selectCarried.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not carried by player.

Returns:

Array
selectCharacter
selectCharacter(list) → {Array}

Defined in: Adventure/Parser/selectCharacter.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not characters.

Returns:

Array
selectDOV
selectDOV(list) → {Array}

Defined in: Adventure/Parser/selectDOV.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not direct objects of verb.

Returns:

Array
selectEntity
selectEntity(list) → {Array}

Defined in: Adventure/Parser/selectEntity.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all non-entity assets.

Returns:

Array
selectEntityOrSubstance
selectEntityOrSubstance(list) → {Array}

Defined in: Adventure/Parser/selectEntityOrSubstance.js, line 8

Deprecated
  • Yes

Parameters:

  • list Array
Exclude from a list of assets all non-tangible assets.

Returns:

Array
selectExtant
selectExtant(list) → {Array}

Defined in: Adventure/Parser/selectExtant.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that have been destroyed.

Returns:

Array
selectGlobalSubstance
selectGlobalSubstance(list) → {Array}

Defined in: Adventure/Parser/selectGlobalSubstance.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not global substances.

Returns:

Array
selectHeld
selectHeld(list) → {Array}

Defined in: Adventure/Parser/selectHeld.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not being held by subject.

Returns:

Array
selectInHands
selectInHands(list) → {Array}

Defined in: Adventure/Parser/selectInHands.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not in subject's hands.

Returns:

Array
selectInHandsUnlessReservoir
selectInHandsUnlessReservoir(list) → {Array}

Defined in: Adventure/Parser/selectInHandsUnlessReservoir.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not in subject's hands, unless asset is a reservoir (such as "throw sand" while standing in desert).

Returns:

Array
selectInInventory
selectInInventory(list) → {Array}

Defined in: Adventure/Parser/selectInInventory.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not in subject's inventory.

Returns:

Array
selectInInventoryIfTakeable
selectInInventoryIfTakeable(list) → {Array}

Defined in: Adventure/Parser/selectInInventoryIfTakeable.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not takeable from subject inventory.

Returns:

Array
selectIntangible
selectIntangible(list) → {Array}

Defined in: Adventure/Parser/selectIntangible.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all non-intangible assets.

Returns:

Array
selectIOV
selectIOV(list) → {Array}

Defined in: Adventure/Parser/selectIOV.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not direct objects of verb.

Returns:

Array
selectKnown
selectKnown(list) → {Array}

Defined in: Adventure/Parser/selectKnown.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are unknown by player.

Returns:

Array
selectNotExit
selectNotExit(list) → {Array}

Defined in: Adventure/Parser/selectNotExit.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are exits.

Returns:

Array
selectNotGlobal
selectNotGlobal(list) → {Array}

Defined in: Adventure/Parser/selectNotGlobal.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all global assets.

Returns:

Array
selectNotInHands
selectNotInHands(list) → {Array}

Defined in: Adventure/Parser/selectNotInHands.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets held in player's hands.

Returns:

Array
selectNotInInventory
selectNotInInventory(list) → {Array}

Defined in: Adventure/Parser/selectNotInInventory.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets in player's inventory.

Returns:

Array
selectNotNestedIfAll
selectNotNestedIfAll(list, context) → {Array}

Defined in: Adventure/Parser/selectNotNestedIfAll.js, line 8

Parameters:

  • list Array
  • context Object
    An optional context asset, for "take from asset"
Exclude from a list of assets all assets in subject's inventory.

Returns:

Array
selectNotParent
selectNotParent(list) → {Array}

Defined in: Adventure/Parser/selectNotParent.js, line 8

Parameters:

  • list Array
Exclude the subject's parent from a list of assets.

Returns:

Array
selectNotParentOrRoom
selectNotParentOrRoom(list) → {Array}

Defined in: Adventure/Parser/selectNotParentOrRoom.js, line 8

Parameters:

  • list Array
Exclude the subject's parent and room from a list of assets.

Returns:

Array
selectNotPlayer
selectNotPlayer(list) → {Array}

Defined in: Adventure/Parser/selectNotPlayer.js, line 8

Parameters:

  • list Array
Exclude the player from a list of assets.

Returns:

Array
selectNotScenery
selectNotScenery(list) → {Array}

Defined in: Adventure/Parser/selectNotScenery.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all scenery assets.

Returns:

Array
selectNotSelf
selectNotSelf(list) → {Array}

Defined in: Adventure/Parser/selectNotSelf.js, line 8

Parameters:

  • list Array
Exclude the subject of this turn's input from a list of assets. By default this is the player, but may be an NPC in cases like "Floyd, go east".

Returns:

Array
selectNotSubstance
selectNotSubstance(list) → {Array}

Defined in: Adventure/Parser/selectNotSubstance.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all substance assets.

Returns:

Array
selectNotWorn
selectNotWorn(list) → {Array}

Defined in: Adventure/Parser/selectNotWorn.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets worn by player.

Returns:

Array
selectNotWornIfAll
selectNotWornIfAll(list) → {Array}

Defined in: Adventure/Parser/selectNotWornIfAll.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all worn assets if player input "all".

Returns:

Array
selectParent
selectParent(list) → {Array}

Defined in: Adventure/Parser/selectParent.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets but subject's parent. Should only ever return one object.

Returns:

Array
selectParentOrRoom
selectParentOrRoom(list) → {Array}

Defined in: Adventure/Parser/selectParentOrRoom.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets but subject's parent. Should only ever return one object.

Returns:

Array
selectPlayer
selectPlayer(list) → {Array}

Defined in: Adventure/Parser/selectPlayer.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not the player.

Returns:

Array
selectPresent
selectPresent(list) → {Array}

Defined in: Adventure/Parser/selectPresent.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not present in current room.

Returns:

Array
selectPresentIfEntity
selectPresentIfEntity(list) → {Array}

Defined in: Adventure/Parser/selectPresentIfEntity.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all entity assets that are not present in current room.

Returns:

Array
selectReachable
selectReachable(list) → {Array}

Defined in: Adventure/Parser/selectReachable.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not reachable by subject.

Returns:

Array
selectReachableIfEntity
selectReachableIfEntity(list) → {Array}

Defined in: Adventure/Parser/selectReachableIfEntity.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not reachable by subject.

Returns:

Array
selectReservoir
selectReservoir(list) → {Array}

Defined in: Adventure/Parser/selectReservoir.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not substance reservoirs such as a lake or a beach.

Returns:

Array
selectReservoirIfSubstance
selectReservoirIfSubstance(list) → {Array}

Defined in: Adventure/Parser/selectReservoirIfSubstance.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not substance reservoirs such as a lake or a beach, only if a substance was specified.

Returns:

Array
selectReservoirOrCarriedIfSubstance
selectReservoirOrCarriedIfSubstance(list) → {Array}

Defined in: Adventure/Parser/selectReservoirOrCarriedIfSubstance.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not substance reservoirs such as a lake or a beach, or vessels carried by player, only if a substance was specified.

Returns:

Array
selectSelf
selectSelf(list) → {Array}

Defined in: Adventure/Parser/selectSelf.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not the subject of this turn's input. By default this is the player, but may be an NPC in cases like "Floyd, go east".

Returns:

Array
selectSingular
selectSingular(list) → {Array}

Defined in: Adventure/Parser/selectSingular.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all objects that are collections.

Returns:

Array
selectSubstance
selectSubstance(list) → {Array}

Defined in: Adventure/Parser/selectSubstance.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not substances.

Returns:

Array
selectTakeable
selectTakeable(list) → {Array}

Defined in: Adventure/Parser/selectTakeable.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that can't be taken by subject.

Returns:

Array
selectTangible
selectTangible(list) → {Array}

Defined in: Adventure/Parser/selectTangible.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all non-tangible assets.

Returns:

Array
selectVisible
selectVisible(list) → {Array}

Defined in: Adventure/Parser/selectVisible.js, line 8

Todos: consider global darkness

Parameters:

  • list Array
Exclude from a list of assets all assets that are not visible to subject.

Returns:

Array
selectVisible
selectVisible(list) → {Array}

Defined in: Adventure/Parser/selectWorn.js, line 8

Parameters:

  • list Array
Exclude from a list of assets all assets that are not worn by player.

Returns:

Array
selectVisibleIfEntity
selectVisibleIfEntity(list) → {Array}

Defined in: Adventure/Parser/selectVisibleIfEntity.js, line 8

Todos: consider global darkness

Parameters:

  • list Array
Exclude from a list of assets all assets that are not visible to subject.

Returns:

Array
set
set(props) → {AdventureJS.Parser}

Defined in: Adventure/Parser.js, line 416

Parameters:

  • props Object
    A generic object containing properties to copy to the Object instance.
Provides a chainable shortcut method for setting a number of properties on the instance.

Returns:

AdventureJS.Parser Returns the instance the method is called on (useful for chaining calls.)
setRecentPronouns
setRecentPronouns()

Defined in: Adventure/Parser.js, line 169

Todos: this needs additional logic to handle custom pronouns

Set the recent pronoun tracker.
splitSentences
splitSentences(input) → {String}

Defined in: Adventure/Parser/splitSentences.js, line 8

Todos: multi-turn handling for instructions given to NPCs ex: Roger, go east then drop lamp

Parameters:

  • input String
Calls split by periods and enqueues the results.

Returns:

String
stripArticles
stripArticles(input) → {String}

Defined in: Adventure/Parser/stripArticles.js, line 8

Parameters:

  • input String
    Player input.

Convert some common compound prepositions into single words to streamline preposition handling.

Returns:

String
tokenizeAnd
tokenizeAnd(input) → {String}

Defined in: Adventure/Parser/tokenizeAnd.js, line 8

Parameters:

  • input String
",", "and", and ", and" can be used in multiple ways:
  1. as a conjunction
    • "take glass key and silver key"
    • "take all but glass key and silver key"
    • "take glass key, silver key"
    • "take all but glass key, silver key"
  2. as a sentence boundary (like "then")
    • "take glass key and go north"
    • "jump and go north"
    • "jump up and go north"
    • "go east and go north"
    • STRETCH: "put a in b and c in d"
When "and" is used as a conjunction in phrases like "take sword and stone", convert "and" to "&" to make plural noun string "sword&stone".

When used as a sentence boundary, we convert "and" to " | ", which will be used to split sentences in a later step.

We also look for chained prepositional phrases:
"put a in b and c in d (ad infinitum)"

Returns:

String
tokenizeBoundaries
tokenizeBoundaries(input) → {String}

Defined in: Adventure/Parser/tokenizeBoundaries.js, line 8

Parameters:

  • input String
Convert periods used as sentence boundaries to pipes and insert a space to help parsing compound words. The inciting example is: "take all but glass key." which was being parsed as "take all -glass key." instead of "take all -glass_key."

Returns:

String
tokenizeBut
tokenizeBut(input_string) → {String}

Defined in: Adventure/Parser/tokenizeBut.js, line 8

Parameters:

  • input_string String
    Player input string.

In order to handle sentences with multiple nouns connected by 'but', we convert 'but' to a symbol we can use down the line.

Returns:

String
tokenizeCommands
tokenizeCommands(input) → {String|Boolean}

Defined in: Adventure/Parser/tokenizeCommands.js, line 8

Parameters:

  • input String
    Player input.
Look for an NPC directive in the form of input that begins with a character name. The name may or may not be followed by a comma, as in "Conan, give me the ax" If the input starts with one word followed by a comma, we always take it to mean that a character has been addressed and issue a success or failure depending on circumstances. ie: "roger, make shrubbery" If we find a character directive, we save a record of the target character back to the input.

Returns:

String | Boolean
tokenizeNouns
tokenizeNouns(input) → {String}

Defined in: Adventure/Parser/tokenizeNouns.js, line 8

Todos: This might be too greedy, or perhaps need to exclude first word of input. I had a room called "Put Plug In This" and this method parsed "put plug in sink" to "put_plug_in_this in sink" Alternately, revise the method that populates world_lookup for instance world_lookup has keys for "Plug Something With Something" and "sink with"

Parameters:

  • input String
    Player input.

Search input for multi-word phrases that are not names, such as "north door" to describe an aperture related to a north exit, by comparing the input string against entries in game.world_lookup, which contains space delimited phrases as well as single words which make up those phrases.

For example if we had an object named: "Maxwell's silver hammer"

User might ask for "hammer" or "silver hammer" or "maxwell's silver hammer" In order to maximize chances of understanding partial user input, each word of the phrase becomes a separate entry in world_lookup.

When performing search/replace we don't want to accidentally replace substrings of larger phrases, which means we need to search for longer phrases first and work our way down. We also need to ensure we don't substitute words in phrases we've already serialized.

Unfortunately we can't just sort world_lookup by word count because JS object properties aren't indexed, by definition. Instead we figure out the longest word count property and do a loop for each word count from the longest down to two words. (No substitution is needed for single words.)

Returns:

String
tokenizePrepositions
tokenizePrepositions(input) → {String}

Defined in: Adventure/Parser/tokenizePrepositions.js, line 8

Parameters:

  • input String
    Player input.
Convert some common compound prepositions into single words to streamline preposition handling.

Returns:

String
tokenizeStrings
tokenizeStrings(input) → {String}

Defined in: Adventure/Parser/tokenizeStrings.js, line 8

Parameters:

  • input String
    Player input.
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.

Example:
type "foo" on keyboard
Became:
type $0 on keyboard
And now becomes:
type global_string on keyboard

Returns:

String
tokenizeThen
tokenizeThen(input) → {String}

Defined in: Adventure/Parser/tokenizeThen.js, line 8

Todos: what about "take sword then shield" ?

Parameters:

  • input String
Convert any of these FROM
  • "verb1 noun1, then verb2 noun2"
  • "verb1 noun1 then verb2 noun2"
  • "verb1 noun1 and then verb2 noun2"
  • TO
  • "verb1 noun1. verb2 noun2."
  • Try to convert FROM
  • "verb1 then verb2 noun1"
  • TO
  • "verb1 noun1. verb2 noun2."

  • Each clause separated by 'then' is a distinct input. We treat clauses as unrelated without dependencies and stack each into a queue.

    Example: "take sword then go north"

    Returns:

    String
    tokenizeTryGerunds
    tokenizeTryGerunds(input) → {String}

    Defined in: Adventure/Parser/tokenizeTryGerunds.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "try verbing". We compare the input string against entries in dictionary.try_gerunds, which was populated automatically at initialization. If we find a set of words that match an entry, we save a record for use with future verb logic.

    For example:
    "try swimming" is identified as "swim"

    Returns:

    String
    tokenizeTryToVerbs
    tokenizeTryToVerbs(input) → {String}

    Defined in: Adventure/Parser/tokenizeTryToVerbs.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "try to verb". We compare the input string against entries in dictionary.try_to_verbs, which was populated automatically at initialization. If we find a set of words that match an entry, we save a record for use with future verb logic.

    For example:
    "try to swim" is identified as "swim"

    Returns:

    String
    tokenizeVerbGerunds
    tokenizeVerbGerunds(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbGerunds.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "verb gerund" such as "go swimming". We compare the input string against entries in dictionary.verb_gerunds, which was populated by Verb definitions. If we find a set of words that match an entry, we save a record for use with future verb logic.

    For example:
    "go swimming" is identified as "swim"

    Returns:

    String
    tokenizeVerbNounPrepNounPrepNouns
    tokenizeVerbNounPrepNounPrepNouns(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbNounPrepNounPrepNouns.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "verb noun prep noun prep noun". We compare the input string against entries in dictionary.verb_noun_prep_noun_prep_nouns, which was populated by Verb definitions. If we find a set of words that matches an entry, we save a record for use with future verb logic.

    For example:
    "tie dog to tree with rope" is identified as "tie_to_with dog tree rope"

    Returns:

    String
    tokenizeVerbNounPrepNouns
    tokenizeVerbNounPrepNouns(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbNounPrepNouns.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "verb noun preposition noun". We compare the input string against entries in dictionary.verb_noun_prep_nouns, which was populated by Verb definitions. If we find a set of words that match an entry, we save a record for use with future verb logic.

    For example:
    "ask grocer about eggplant" is identified as "ask_about grocer eggplant"

    Returns:

    String
    tokenizeVerbNounPrepPrepNouns
    tokenizeVerbNounPrepPrepNouns(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbNounPrepPrepNouns.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "verb noun preposition preposition noun". We compare the input string against entries in dictionary.verb_noun_prep_prep_nouns, which was populated by Verb definitions. If we find a set of words that match an entry, we save a record for use with future verb logic.

    For example:
    "take skateboard from under bed" is identified as "take_from skateboard bed"

    Returns:

    String
    tokenizeVerbNounPreps
    tokenizeVerbNounPreps(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbNounPreps.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "verb noun preposition". We compare the input string against entries in dictionary.verb_noun_preps, which was populated by Verb definitions. If we find a set of words that match an entry, we save a record for use with future verb logic.

    For example:
    "lock chest up" is identified as "lockUp chest"

    Returns:

    String
    tokenizeVerbPrepNounPrepNounPrepNouns
    tokenizeVerbPrepNounPrepNounPrepNouns(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbPrepNounPrepNounPrepNouns.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "verb preposition noun preposition noun preposition noun". We compare the input string against entries in dictionary.verb_prep_noun_prep_noun_prep_nouns, which was populated by Verb definitions. If we find a set of words that match an entry, we save a record for use with future verb logic.

    For example:
    "swing from tree to stalactite on vine" is identified as "swing_from_to_on tree stalactite vine".

    Returns:

    String
    tokenizeVerbPrepNounPrepNouns
    tokenizeVerbPrepNounPrepNouns(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbPrepNounPrepNouns.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "verb prep noun prep noun". We compare 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 save a record for use with future verb logic.

    For example:
    "jump from branch to vine" is identified as "jumpFrom_to branch vine"

    Returns:

    String
    tokenizeVerbPrepNouns
    tokenizeVerbPrepNouns(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbPrepNouns.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "verb prep noun". We compare 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 save a record for use with future verb logic.

    For example:
    "look in desk" is identified as "lookIn desk"

    Returns:

    String
    tokenizeVerbPrepPrepNouns
    tokenizeVerbPrepPrepNouns(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbPrepPrepNouns.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "verb prep prep noun". We compare 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 save a record for use with future verb logic.

    For example:
    "get out of boat" is identified as "go_out boat"

    Returns:

    String
    tokenizeVerbPrepPrepPrepNouns
    tokenizeVerbPrepPrepPrepNouns(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbPrepPrepPrepNouns.js, line 8

    Parameters:

    • input String
      Player input.

    Search input for verb phrases in the format of "verb prep prep prep noun". We compare the input string against entries in dictionary.verb_prep_prep_prep_nouns, which was populated by Verb definitions. If we find a set of words that match an entry, we save a record for use with future verb logic.

    For example:
    "get out from behind boulder" is identified as "go_out_from_behind boulder"

    Returns:

    String
    tokenizeVerbs
    tokenizeVerbs(input) → {String}

    Defined in: Adventure/Parser/tokenizeVerbs.js, line 29

    Parameters:

    • input String
      Player input.
    tokenizeVerbs identifies phrasal or compound verb patterns such as "swing from tree to cliff on vine". This feature is mostly retired but for use in a small few instances such as aiding in identifying "plug in computer" vs "plug drain". An earlier version of the parser used this extensively to join phrasal verbs into distinct verbs such as "swing_from_to_on tree cliff vine", which worked well but ultimately proved to be inflexible.

    The listed order of regex operations is important. We're calling them in order of longest to shortest, to ensure we don't accidentally catch partial phrases, like only finding "swing_from" out of "swing from tree to cliff on vine", and then not finding "swing_from_to_on", which is a distinct pattern.

    Returns:

    String
    verifyAdverbs
    verifyAdverbs()

    Defined in: Adventure/Parser/verifyAdverb.js, line 8

    Verify that any adverb received is accepted by current verb.
    verifyCharacterVerb
    verifyCharacterVerb(optional_verb)

    Defined in: Adventure/Parser/verifyCharacterVerb.js, line 8

    Parameters:

    • optional_verb string
      An optional verb. If not provided, method uses this_turn.input_verb.
    Verify that a character commanded to perform a verb can do that verb, as in "Floyd, go east".

    Returns:

    boolean
    verifySentence
    verifySentence()

    Defined in: Adventure/Parser/verifySentence.js, line 8

    After parse, verify each word in sentence.
    verifySentenceStructure
    verifySentenceStructure()

    Defined in: Adventure/Parser/verifySentenceStructure.js, line 8

    Verify that the active verb accepts the sentence structure.

    Properties  | 

    custom_parsers
    custom_parsers :Object

    Defined in: Adventure/Parser.js, line 58

    Default value: {}

    Used to store custom parser code that might be written by authors.
    custom_parsers_enabled
    custom_parsers_enabled :Object

    Defined in: Adventure/Parser.js, line 65

    Default value: {}

    If custom parsers have been written by author, this provides a way to turn them on/off, something you might want to do depending on context.
    dictionary
    dictionary :Object

    Defined in: Adventure/Parser.js, line 44

    Default value: {}

    A reference back to the main Game Dictionary object.
    display
    display :Object

    Defined in: Adventure/Parser.js, line 51

    Default value: {}

    A reference back to the main Game Display object.
    game
    game :Object

    Defined in: Adventure/Parser.js, line 37

    Default value: {}

    A reference back to the main Game object.
    input_history
    input_history :Array

    Defined in: Adventure/Parser.js, line 88

    Default value: []

    Stores all player input. Used for Undo and Again, and in letting player use arrow keys to recall prior turns' input, as in a terminal application.
    input_history_index
    input_history_index :int

    Defined in: Adventure/Parser.js, line 105

    When player uses arrow keys to navigate between old inputs, this stores player's position in the history array.
    input_object
    input_object :Object

    Defined in: Adventure/Parser.js, line 121

    Default value: {}

    Todos: Is this irrelevant?

    Unused?
    input_queue
    input_queue :Array

    Defined in: Adventure/Parser.js, line 112

    Default value: []

    When player uses conjuctive clauses joined by 'and' or 'then' we split the input into separate inputs and queue them up to handle in sequence. Queued inputs are saved here.
    input_string
    input_string :String

    Defined in: Adventure/Parser.js, line 74

    Default value: ""

    Used to store a copy of player input when player hits enter and before parsing.
    is_input_queued
    is_input_queued :Boolean

    Defined in: Adventure/Parser.js, line 129

    Default value: false

    Save (this.input_queue.length > 0) during parse, because at some point later in the parse we shift input_queue, but later than that we still need to know whether we're queued.
    phrasal_patterns
    phrasal_patterns :Array

    Defined in: Adventure/Parser/tokenizeVerbs.js, line 8

    List of methods to be called during parse that perform regex operations on input in order to join phrasal verbs.
    recent_pronouns
    recent_pronouns :Object

    Defined in: Adventure/Parser.js, line 138

    Default value: {}

    Todos: how to handle custom pronouns

    Used to keep track of recently referred assets by pronoun.