rita.support.grammar
Class Grammar

java.lang.Object
  extended by rita.support.grammar.Grammar

public class Grammar
extends java.lang.Object

Simple context-free grammar based loosely on Mike Cleron's 'rsg-grammar'

Invisible:

Field Summary
static java.lang.String BN
           
static java.lang.String BR
           
static java.lang.String CLOSE_DEF
           
static java.lang.String CLOSE_QUANT
           
static java.lang.String CLOSE_TOKEN
           
static java.lang.String COMMENT
           
 java.util.Map definitions
           
static java.lang.String END_PROD
           
static java.lang.String EXEC_CHAR
           
static java.lang.String EXEC_POST
           
 java.lang.String lineBreakIndent
           
static java.lang.String OPEN_DEF
           
static java.lang.String OPEN_QUANT
           
static java.lang.String OPEN_TOKEN
           
static java.lang.String SPACE
           
static java.lang.String START_SYM
           
 
Constructor Summary
Grammar(java.lang.Object callbackParent, java.lang.CharSequence input)
           
Grammar(java.lang.Object callbackParent, java.io.InputStream is, java.lang.String grammarFileName)
           
Grammar(java.lang.Object callbackParent, java.net.URL url)
           
 
Method Summary
 void addDefinition(java.lang.String name, java.util.List l)
           
 Grammar copy()
           
 void dumpDefinitions()
           
 java.lang.String expand(boolean preserveBuffer)
           
 java.lang.String expand(java.lang.String token, boolean preserveBuffer)
           
 java.lang.String expandWith(java.lang.String literal, java.lang.String symbol, boolean preserveBuffer)
          Expands the grammar after replacing an instance of the non-terminal 'symbol' with the String in 'literal'.
 java.lang.String getBuffer()
          Return all the text generated thus far, that is, since the last call to expand(), expandFrom(), or expandWith().
 Definition getDefinition(java.lang.String name)
           
 java.util.Map getDefinitions()
          Returns a Map of the current Definitions, with names as keys and String-representations of each Definition as values.
 java.lang.String getGrammarFileName()
           
 java.lang.String getLineBreak()
           
 java.util.List getProductions(java.lang.String defName)
           
static boolean isExecEnabled()
          Returns the state of the execEnabled flag
 boolean isInsertSpaces()
           
static void main(java.lang.String[] args)
           
static void mainX(java.lang.String[] args)
           
 void resetDefinition(java.lang.String name, java.util.List l)
           
 void setBuffer(java.lang.CharSequence contents)
          Resets the contents of the current buffer
static void setExecEnabled(boolean enableExec)
          Set to false (default=true) if you don't want to use the exec() mechanism for callbacks to a parent class.
 void setInsertSpaces(boolean insertSpaces)
           
 void setLineBreak(java.lang.String lineBreak)
           
static void testHistory(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXEC_CHAR

public static final java.lang.String EXEC_CHAR
See Also:
Constant Field Values

EXEC_POST

public static final java.lang.String EXEC_POST
See Also:
Constant Field Values

START_SYM

public static final java.lang.String START_SYM
See Also:
Constant Field Values

OPEN_DEF

public static final java.lang.String OPEN_DEF
See Also:
Constant Field Values

CLOSE_DEF

public static final java.lang.String CLOSE_DEF
See Also:
Constant Field Values

OPEN_QUANT

public static final java.lang.String OPEN_QUANT
See Also:
Constant Field Values

CLOSE_QUANT

public static final java.lang.String CLOSE_QUANT
See Also:
Constant Field Values

END_PROD

public static final java.lang.String END_PROD
See Also:
Constant Field Values

BN

public static final java.lang.String BN
See Also:
Constant Field Values

BR

public static final java.lang.String BR
See Also:
Constant Field Values

OPEN_TOKEN

public static final java.lang.String OPEN_TOKEN
See Also:
Constant Field Values

CLOSE_TOKEN

public static final java.lang.String CLOSE_TOKEN
See Also:
Constant Field Values

COMMENT

public static final java.lang.String COMMENT
See Also:
Constant Field Values

SPACE

public static final java.lang.String SPACE
See Also:
Constant Field Values

definitions

public java.util.Map definitions

lineBreakIndent

public java.lang.String lineBreakIndent
Constructor Detail

Grammar

public Grammar(java.lang.Object callbackParent,
               java.net.URL url)

Grammar

public Grammar(java.lang.Object callbackParent,
               java.lang.CharSequence input)

Grammar

public Grammar(java.lang.Object callbackParent,
               java.io.InputStream is,
               java.lang.String grammarFileName)
Method Detail

getBuffer

public java.lang.String getBuffer()
Return all the text generated thus far, that is, since the last call to expand(), expandFrom(), or expandWith().


setBuffer

public void setBuffer(java.lang.CharSequence contents)
Resets the contents of the current buffer


copy

public Grammar copy()
Parameters:
callbackHandler - the callbackHandler to set

getLineBreak

public java.lang.String getLineBreak()
Returns:
the lineBreak

setLineBreak

public void setLineBreak(java.lang.String lineBreak)
Parameters:
lineBreak - the lineBreak to use

dumpDefinitions

public void dumpDefinitions()

getDefinitions

public java.util.Map getDefinitions()
Returns a Map of the current Definitions, with names as keys and String-representations of each Definition as values.


getDefinition

public Definition getDefinition(java.lang.String name)

getProductions

public java.util.List getProductions(java.lang.String defName)

addDefinition

public void addDefinition(java.lang.String name,
                          java.util.List l)

resetDefinition

public void resetDefinition(java.lang.String name,
                            java.util.List l)

expand

public java.lang.String expand(boolean preserveBuffer)

expand

public java.lang.String expand(java.lang.String token,
                               boolean preserveBuffer)

setExecEnabled

public static void setExecEnabled(boolean enableExec)
Set to false (default=true) if you don't want to use the exec() mechanism for callbacks to a parent class. Useful if you want to include backticks or method calls as terminals in your grammar. Note: this must be called before loading a grammar file.

Invisible:

isExecEnabled

public static boolean isExecEnabled()
Returns the state of the execEnabled flag

Invisible:

expandWith

public java.lang.String expandWith(java.lang.String literal,
                                   java.lang.String symbol,
                                   boolean preserveBuffer)
Expands the grammar after replacing an instance of the non-terminal 'symbol' with the String in 'literal'.

Guarantees that 'literal' will be in the final expanded String, assuming at least one instance of 'symbol' in the Grammar.

Note: this method has been debugged/refactored for v79, please make sure you are using a current RiTa version.

Throws:
RiTaException - if 'symbol' is not found.

testHistory

public static void testHistory(java.lang.String[] args)
                        throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

isInsertSpaces

public boolean isInsertSpaces()

setInsertSpaces

public void setInsertSpaces(boolean insertSpaces)

getGrammarFileName

public java.lang.String getGrammarFileName()

mainX

public static void mainX(java.lang.String[] args)
                  throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException

main

public static void main(java.lang.String[] args)
                 throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException