edu.cmu.sphinx.tools.tags
Class ActionTagsParser

java.lang.Object
  extended byedu.cmu.sphinx.tools.tags.ActionTagsParser
Direct Known Subclasses:
ObjectTagsParser

public class ActionTagsParser
extends java.lang.Object

An ECMAScript action tags parser for tags embedded in JSGF RuleGrammars. A typical use of this class is to create an instance of it and then call the parseTags method using RuleParse's generated by a RuleGrammar. The instance will maintain a context/scope between calls to parseTags.

See Also:
parseTags(javax.speech.recognition.RuleParse), ActionTagsUtilities

Constructor Summary
ActionTagsParser()
          Create a new ECMATagsParser.
 
Method Summary
static java.lang.String debug(java.lang.String string)
          A debug utility that can be referenced within ECMAScript source.
 java.lang.Object evaluateString(java.lang.String script)
          Evaluate the given ECMAScript script as ECMAScript within the context/scope of this parser.
 java.lang.Object get(java.lang.String name)
          Get the given object from the result value after a RuleParse has been parsed with the parseTags method.
 java.lang.Object getGlobal(java.lang.String name)
          Get the given object from the global context/scope of the parser.
 void parseTags(RuleParse ruleParse)
          Convert the tags embedded in the RuleParse to ECMAScript and then process them within the scope of this parser.
static void print(java.lang.String string)
          A debug utility that can be referenced within ECMAScript source.
 java.lang.String showValue()
          A debug utility to show the result value after a RuleParse has been parsed with the parseTags method.
 java.lang.String toString()
          Recurse through the properties in the context/scope of this parser and generate a String from them.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActionTagsParser

public ActionTagsParser()
Create a new ECMATagsParser. This will generate an ECMAScript context that will be re-used each time the parse method is called. After creating an instance of this class, an application will typically call the parseTags method with RuleParses generated by a RuleGrammar.

See Also:
parseTags(javax.speech.recognition.RuleParse)
Method Detail

parseTags

public void parseTags(RuleParse ruleParse)
Convert the tags embedded in the RuleParse to ECMAScript and then process them within the scope of this parser. When the RuleParse has been parsed, the results can be obtained via the get method.

Parameters:
ruleParse - the RuleParse from a RuleGrammar.
See Also:
get(java.lang.String)

evaluateString

public java.lang.Object evaluateString(java.lang.String script)
Evaluate the given ECMAScript script as ECMAScript within the context/scope of this parser.

Parameters:
script - a String containing ECMAScript to be evaluated
Returns:
the result of evaluating the script

getGlobal

public java.lang.Object getGlobal(java.lang.String name)
Get the given object from the global context/scope of the parser.

Parameters:
name - the name of the object to get
Returns:
the object if found; otherwise null
See Also:
parseTags(javax.speech.recognition.RuleParse)

get

public java.lang.Object get(java.lang.String name)
Get the given object from the result value after a RuleParse has been parsed with the parseTags method. For example, an application might use "$value" or "$value.foo" for the name parameter. This is basically a shortcut for calling evaluateString with a parameter of "$." + name.

Parameters:
name - the name of the object to get
Returns:
null if the name does not exist
See Also:
parseTags(javax.speech.recognition.RuleParse)

print

public static void print(java.lang.String string)
A debug utility that can be referenced within ECMAScript source. For example, a RuleTag could contain the following ECMAScript: "{ this.$value = 7; print('Set value to 7'); }". The string will be sent to System.out.

Parameters:
string - the string to send to System.out

debug

public static java.lang.String debug(java.lang.String string)
A debug utility that can be referenced within ECMAScript source. This will send the given string to System.out, read a line from System.in, and then return that line. This is to be used in conjunction with the ActionTagsUtilities debugging capabilities.

See Also:
ActionTagsUtilities.setDebugging(boolean)

toString

public java.lang.String toString()
Recurse through the properties in the context/scope of this parser and generate a String from them.


showValue

public java.lang.String showValue()
A debug utility to show the result value after a RuleParse has been parsed with the parseTags method.