Stellent
HowToComponents
JavaDoc

intradoc.common
Class GrammarParser

java.lang.Object
  |
  +--intradoc.common.GrammarParser

public class GrammarParser
extends java.lang.Object

Utilities for parsing a string into a tree of GrammarElements.

See Also:
GrammarElement

Field Summary
static char m_decimalPoint
          Holds floating point information.
static java.lang.String m_identifierChars
          Special characters that are legal in variable or function names.
static boolean m_isInit
          Used to indicate whether this static object has been fully initialized.
static java.lang.String m_operatorChars
          Special characters that are legal in operators.
static java.lang.String[] m_operators
          Operators in precedence order.
static int m_plusMinusPriorityDiff
          Difference between priority of '-' and '+'.
 
Constructor Summary
GrammarParser()
           
 
Method Summary
static void adjustElementLocation(int startLine, int startOffset, GrammarElement elt)
           
static GrammarElement collapseElements(GrammarParseState parseState, java.util.Vector v)
          Evaluates operators in precedence order.
static void convertSubElementsToArray(GrammarElement elt)
           
static GrammarElement createElement(GrammarParseState parseState, boolean insideOp, boolean insideId, int startElt, int lineCount, int lineOffset, int end)
           
static void createParseException(int line, int offset, java.lang.String msg)
           
static void createParseExceptionElt(GrammarElement elt, java.lang.String msg)
           
static void createParseExceptionEx(int line, int offset, java.lang.String msg, boolean outerOffsetsUsed)
           
static int determineFormatContent(char[] buf, int offset, int end)
          Utility service to determine what single format content the string contains.
static GrammarElement getRepresentativeElement(GrammarElement elt)
           
static java.lang.String getSubstring(GrammarParseState parseState, int startOffset, int endOffset)
          In theory since the String object keeps offset and length attributes, a substring does not require the allocation of memory and only increases a reference counter.
static void init()
          Does one time only computations.
static boolean isAdditiveBoolean(GrammarElement elt)
           
static boolean isAdditiveNumeric(GrammarElement elt)
           
static boolean isIdentifierChar(char ch)
          Utility service determines if a character is part of a substitutable variable.
static boolean isOperatorChar(char ch)
          Utility service determines if a character is part of an operator.
static GrammarElement parseElement(GrammarParseState parseState, java.lang.String fileName, int startLine, int startOffset)
          Parses a GrammarElement and properly reports the absolute location of a problem ParseState holds the relative location being parsed.
static GrammarElement parseElement(java.lang.String str)
          Parses a GrammarElement from a String.
static GrammarElement parseSubElement(GrammarParseState parseState, int startLine, int startOffset)
          Creates an array of grammar elements.
static void validateOperand(GrammarParseState parseState, java.lang.String op, GrammarElement operand, boolean isLeftOperand)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_operators

public static final java.lang.String[] m_operators
Operators in precedence order.


m_plusMinusPriorityDiff

public static final int m_plusMinusPriorityDiff
Difference between priority of '-' and '+'.

See Also:
Constant Field Values

m_operatorChars

public static final java.lang.String m_operatorChars
Special characters that are legal in operators.

See Also:
Constant Field Values

m_identifierChars

public static final java.lang.String m_identifierChars
Special characters that are legal in variable or function names.

See Also:
Constant Field Values

m_decimalPoint

public static char m_decimalPoint
Holds floating point information.


m_isInit

public static boolean m_isInit
Used to indicate whether this static object has been fully initialized. This object is self initializing. We use this attribute to do some computations only once.

Constructor Detail

GrammarParser

public GrammarParser()
Method Detail

init

public static void init()
Does one time only computations.


parseElement

public static GrammarElement parseElement(java.lang.String str)
                                   throws ParseSyntaxException
Parses a GrammarElement from a String.

ParseSyntaxException

parseElement

public static GrammarElement parseElement(GrammarParseState parseState,
                                          java.lang.String fileName,
                                          int startLine,
                                          int startOffset)
                                   throws ParseSyntaxException
Parses a GrammarElement and properly reports the absolute location of a problem ParseState holds the relative location being parsed. The parameters startLine and startOffset are used to compute the absolute location. This method assumes that the expression being parsed is not a nested element (that is it cannot be called recursively).

Parameters:
parseState - Holds information about active state of string being parsed.
fileName - Path to file being parsed. Used for reporting purposes only.
startLine - The line number where string being parsed starts.
startOffset - The column offset of the string being parsed.
ParseSyntaxException
See Also:
parseElement

convertSubElementsToArray

public static void convertSubElementsToArray(GrammarElement elt)

parseSubElement

public static GrammarElement parseSubElement(GrammarParseState parseState,
                                             int startLine,
                                             int startOffset)
                                      throws ParseSyntaxException
Creates an array of grammar elements. Stops on a ',', ')' or end of string. Updates parseState.m_startOffset to last parsed character and parseState.m_terminateChar to character that caused parsing to stop or zero if end of buffer was reached.

Parameters:
parseState - State of string being parsed.
startLine - The line number where string being parsed starts.
startOffset - The column offset of the string being parsed.
Throws:
ParseSyntaxException - Exception thrown when grammar of expression is incorrect.

collapseElements

public static GrammarElement collapseElements(GrammarParseState parseState,
                                              java.util.Vector v)
                                       throws ParseSyntaxException
Evaluates operators in precedence order.

ParseSyntaxException

getRepresentativeElement

public static GrammarElement getRepresentativeElement(GrammarElement elt)

isAdditiveNumeric

public static boolean isAdditiveNumeric(GrammarElement elt)

isAdditiveBoolean

public static boolean isAdditiveBoolean(GrammarElement elt)

validateOperand

public static void validateOperand(GrammarParseState parseState,
                                   java.lang.String op,
                                   GrammarElement operand,
                                   boolean isLeftOperand)
                            throws ParseSyntaxException
ParseSyntaxException

createElement

public static GrammarElement createElement(GrammarParseState parseState,
                                           boolean insideOp,
                                           boolean insideId,
                                           int startElt,
                                           int lineCount,
                                           int lineOffset,
                                           int end)
                                    throws ParseSyntaxException
ParseSyntaxException

adjustElementLocation

public static void adjustElementLocation(int startLine,
                                         int startOffset,
                                         GrammarElement elt)

createParseException

public static void createParseException(int line,
                                        int offset,
                                        java.lang.String msg)
                                 throws ParseSyntaxException
ParseSyntaxException

createParseExceptionElt

public static void createParseExceptionElt(GrammarElement elt,
                                           java.lang.String msg)
                                    throws ParseSyntaxException
ParseSyntaxException

createParseExceptionEx

public static void createParseExceptionEx(int line,
                                          int offset,
                                          java.lang.String msg,
                                          boolean outerOffsetsUsed)
                                   throws ParseSyntaxException
ParseSyntaxException

getSubstring

public static java.lang.String getSubstring(GrammarParseState parseState,
                                            int startOffset,
                                            int endOffset)
In theory since the String object keeps offset and length attributes, a substring does not require the allocation of memory and only increases a reference counter. This should mean that this approach is much faster than creating a string from a character array. However, because of the poor state of Java VMs, method calls of any type are so expensive it is unclear which approach is actually faster. So this method is created more in hope than in reality.


isOperatorChar

public static boolean isOperatorChar(char ch)
Utility service determines if a character is part of an operator.


isIdentifierChar

public static boolean isIdentifierChar(char ch)
Utility service determines if a character is part of a substitutable variable.


determineFormatContent

public static int determineFormatContent(char[] buf,
                                         int offset,
                                         int end)
Utility service to determine what single format content the string contains. Returns a value from the enum list in GrammarElement. This service assumes that the value has been trimmed of whitespace. Warning: This method treats '-' as an operator value not as part of a number. It should only be used for values being parsed in grammatical expressions (or for those who are willing to deal with the overhead of eliminating the operator expressions in numbers before calling this method).



(c) 1996-2005  All rights reserved.  Stellent, Inc.