Class Index | File Index

Classes


Class com.jiffeegames.Parser_en_us

A Parse object parses user input and translates it into canonical form.
Defined in: jiffee-parser-en-us.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Create a Parser object.
Method Summary
Method Attributes Method Name and Description
 
Add a translation for every verb and noun that does not already have one.
 
addNoun(internal, external)
Add a word or phrase (external form) to the list of known nouns.
 
addPhrase_(hash, internal, external)
Add a word or phrase to a list of known phrases.
 
addToken_(tok)
Tell the parser about a possible input token.
 
addVerb(internal, external)
Add a word or phrase (external form) to the list of known verbs.
 
Retrieve the next command typed by the user.
 
init(locate, language)
 
Tell the parser that we've received input from the user.
 
Parse a simple command of the form " []" and convert it to a Command.
 
Parse a single command that has already been split.
 
Pattern(internal, tokens)
 
 
Start this module.
 
tokenize(raw)
Convert an input line into a list of token codes.
 
Ask the parser for the code (number) of a given token.
 
wordify_(raw)
Convert an input line into a list of words.
Class Detail
com.jiffeegames.Parser_en_us()
Create a Parser object. The normal call is
var parser = new com.jiffeegames.Parser['en-us']();
There is a different parser for each language, but you only use one of them in any given game so they all use the same dependency name. This makes for less code churn when you switch languages, since all you have to do is to select the one you want as you initialize the Engine.
Requires:
com.jiffeegames.Checks
Method Detail
{void} addDefaults_()
Add a translation for every verb and noun that does not already have one. Example call:
parser.addDefaults_();

{void} addNoun(internal, external)
Add a word or phrase (external form) to the list of known nouns. Example:
parser.addNoun('candy', 'candy', 'sweet', 'peppermint', 'peppermint stick');
Parameters:
{String} internal
The name of the noun, in author language.
{String} external
One or more forms of the noun, in player language.

{void} addPhrase_(hash, internal, external)
Add a word or phrase to a list of known phrases.
Parameters:
{Hash} hash
The set of known phrases to be augmented.
{String} internal
The internal name.
{String} external
The external form of the word or phrase.

{Integer} addToken_(tok)
Tell the parser about a possible input token.
Parameters:
{String} tok
The token that may appear in user input.
Returns:
The tokenValue of this token.

{void} addVerb(internal, external)
Add a word or phrase (external form) to the list of known verbs.
parser.addVerb('sing', 'sing', 'hum', 'whistle');
Parameters:
{String} internal
The name of the verb, in author language.
{String} external
One or more forms of the verb, in player language.

getCommand()
Retrieve the next command typed by the user. The original user input gets split into simple commands, and this method retrieves a single one of those commands.
Returns:
A single command object, or undefined if there are no commands left to process.

init(locate, language)
Parameters:
locate
language

{void} notifyUserInput(raw)
Tell the parser that we've received input from the user. We immediately parse it into commands and store them for later execution. This is where "do A, then do B" gets parsed and split into multiple commands.
Parameters:
{String} raw
The raw input typed by the user.

parseCommands(raw)
Parse a simple command of the form " []" and convert it to a Command. This will be made much more sophisticated later.
Parameters:
{String} raw
The raw input from the user.
Returns:
A list of the Commands that result (currently always 0 or 1). If there is an unknown word, the "word" property will be set to the unknown word. If the grammar cannot be parsed, the verb will be "BAD-GRAMMAR". In each case the "raw" property will be set to the original input.

parseOneCommand_(raw)
Parse a single command that has already been split.
Parameters:
raw

Pattern(internal, tokens)
Parameters:
internal
tokens

setStrictTranslation(strict)
Parameters:
strict

{void} start()
Start this module.

tokenize(raw)
Convert an input line into a list of token codes.
Parameters:
{String} raw
The input line, as typed by the user.
Returns:
A list of tokens, each of which is an integer code. If a word is unrecognized, its token code is -1 and its value is placed in res.word. (If more than one is unrecognized, the value of the first one is placed in res.word.)

{int} tokenValue_(tok)
Ask the parser for the code (number) of a given token.
Parameters:
{String} tok
The token that appeared in user input.
Returns:
The code number of the token, or undefined if the token is not recognized.

wordify_(raw)
Convert an input line into a list of words.
Parameters:
{String} raw
The input line, as typed by the user.
Returns:
A list of strings, one for each word or known punctuation mark.

Documentation generated by JsDoc Toolkit 2.3.2 on Sun Jul 25 2010 13:49:31 GMT-0700 (PDT)