http://www.eteks.com

com.eteks.parser
Class AbstractSyntax

java.lang.Object
  |
  +--com.eteks.parser.AbstractSyntax
All Implemented Interfaces:
Syntax
Direct Known Subclasses:
DefaultSyntax, JavaSyntax, ResourceSyntax

public abstract class AbstractSyntax
extends java.lang.Object
implements Syntax

Class that helps to define the constants, operators, functions and other required elements of a class implementing the Syntax interface. This class implements all the methods of Syntax except the isValidIdentifier (String identifier) method.
All the elements of a syntax returned by the getter methods of the Syntax interface are stored in internal fields that can be set with the setter respective methods of this class. Examples :

The getDelimiters () method is implemented in such a way it returns a string containing the white spaces, the brackets, the parameter separator and all the characters of the (unary and binary) operators and the condition parts that are not valid identifiers with the isValidIdentifier () method.
The case sensitivity of the elements of the syntax is set at creation and can't be changed. By default, a syntax isn't case sensitive.

Since:
Jeks 1.0
Version:
1.0.2
Author:
Emmanuel Puybaret
See Also:
ResourceSyntax, JavaSyntax

Fields inherited from interface com.eteks.parser.Syntax
CONDITION_ELSE, CONDITION_IF, CONDITION_THEN, CONSTANT_E, CONSTANT_FALSE, CONSTANT_PI, CONSTANT_TRUE, FUNCTION_ABS, FUNCTION_ACOS, FUNCTION_ASIN, FUNCTION_ATAN, FUNCTION_CEIL, FUNCTION_COS, FUNCTION_COSH, FUNCTION_EXP, FUNCTION_FLOOR, FUNCTION_INTEGER, FUNCTION_LN, FUNCTION_LOG, FUNCTION_NOT, FUNCTION_OPPOSITE, FUNCTION_ROUND, FUNCTION_SIN, FUNCTION_SINH, FUNCTION_SQR, FUNCTION_SQRT, FUNCTION_TAN, FUNCTION_TANH, OPERATOR_ADD, OPERATOR_BITWISE_AND, OPERATOR_BITWISE_NOT, OPERATOR_BITWISE_OR, OPERATOR_BITWISE_XOR, OPERATOR_DIFFERENT, OPERATOR_DIVIDE, OPERATOR_EQUAL, OPERATOR_GREATER, OPERATOR_GREATER_OR_EQUAL, OPERATOR_LESS, OPERATOR_LESS_OR_EQUAL, OPERATOR_LOGICAL_AND, OPERATOR_LOGICAL_NOT, OPERATOR_LOGICAL_OR, OPERATOR_LOGICAL_XOR, OPERATOR_MODULO, OPERATOR_MULTIPLY, OPERATOR_OPPOSITE, OPERATOR_POSITIVE, OPERATOR_POWER, OPERATOR_REMAINDER, OPERATOR_SHIFT_LEFT, OPERATOR_SHIFT_RIGHT, OPERATOR_SHIFT_RIGHT_0, OPERATOR_SUBSTRACT, USER_STARTING_KEY
 
Constructor Summary
AbstractSyntax()
          Creates a syntax which is not case sensitive.
AbstractSyntax(boolean caseSensitive)
          Creates a syntax, case sensitive according to caseSensitive
 
Method Summary
 void addFunction(Function function)
          Adds function to the recognized functions of this syntax.
 java.lang.String getAssignmentOperator()
          Returns the string used as the operator of assignment.
 java.lang.Object getBinaryOperatorKey(java.lang.String binaryOperator)
          Returns the key matching binaryOperator.
 int getBinaryOperatorPriority(java.lang.Object binaryOperatorKey)
          Returns the priority of the binary operator matching the key binaryOperatorKey.
 char getClosingBracket()
          Returns the char used as the closing bracket of the syntax.
 java.lang.Object getCommonFunctionKey(java.lang.String commonFunction)
          Returns the key matching commonFunction.
 int getConditionPartCount()
          Returns 2 or 3 depending on whether the syntax using a condition with two or three parts.
 java.lang.Object getConditionPartKey(java.lang.String conditionPart)
          Returns the key matching conditionPart.
 java.lang.Object getConstantKey(java.lang.String constant)
          Returns the key matching constant.
 java.lang.String getDelimiters()
          Returns a string containing the white spaces, the brackets, the parameter separator and all the characters of the (unary and binary) operators and the condition parts that are not valid identifiers with the isValidIdentifier () method.
 Function getFunction(java.lang.String functionName)
          Returns a reference to the instance of Function whose name is functionName.
 char getOpeningBracket()
          Returns the char used as the opening bracket of the syntax.
 char getParameterSeparator()
          Returns the char used to separate parameters in a function call.
 java.lang.Object getUnaryOperatorKey(java.lang.String unaryOperator)
          Returns the key matching unaryOperator.
 java.lang.String getWhiteSpaceCharacters()
          Returns a string that contains all the delimiters allowed by the syntax as white spaces (tab, spaces,...).
 boolean isCaseSensitive()
          Returns true if identifiers, constants, operators and function of the syntax are case sensitive.
 boolean isShortSyntax()
          Returns true if expressions parsed with this syntax supports short cuts.
 void removeFunction(Function function)
          Removes function from the functions of this syntax.
 void setAssignmentOperator(java.lang.String assignmentOperator)
          Sets the string used as the operator of assignment.
 void setBinaryOperatorKey(java.lang.String binaryOperator, java.lang.Object binaryOperatorKey)
          Associates the binary operator binaryOperator to the syntactic key binaryOperatorKey.
 void setBinaryOperatorPriority(java.lang.Object binaryOperatorKey, int priority)
          Sets the priority of the binary operator matching the key binaryOperatorKey.
 void setClosingBracket(char closingBracket)
          Sets the char used as the closing bracket of the syntax.
 void setCommonFunctionKey(java.lang.String commonFunction, java.lang.Object commonFunctionKey)
          Associates the common function of name commonFunction to the syntax key commonFunctionKey.
 void setConditionPartKey(java.lang.String conditionPart, java.lang.Object conditionPartKey)
          Associates the condition part conditionPart to the syntactic key conditionPartKey.
 void setConstantKey(java.lang.String constant, java.lang.Object constantKey)
          Associates the constant constant to the syntactic key constantKey.
 void setOpeningBracket(char openingBracket)
          Sets the char used as the opening bracket of the syntax.
 void setParameterSeparator(char parameterSeparator)
          Sets the char used to separate parameters in a function call.
 void setShortSyntax(boolean shortSyntax)
          Sets the capabity of expressions parsed with this syntax to support syntax short cuts.
 void setUnaryOperatorKey(java.lang.String unaryOperator, java.lang.Object unaryOperatorKey)
          Associates the unary operator unaryOperator to the syntactic key unaryOperatorKey.
 void setWhiteSpaceCharacters(java.lang.String whiteSpaceCharacters)
          Sets the string that contains all the delimiters allowed by the syntax as white spaces (tab, spaces,...).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.eteks.parser.Syntax
getLiteral, isValidIdentifier
 

Constructor Detail

AbstractSyntax

public AbstractSyntax()
Creates a syntax which is not case sensitive.

AbstractSyntax

public AbstractSyntax(boolean caseSensitive)
Creates a syntax, case sensitive according to caseSensitive
Parameters:
caseSensitive - true if case sensitive.
Method Detail

getConstantKey

public java.lang.Object getConstantKey(java.lang.String constant)
Returns the key matching constant. The association is made with the setConstantKey ().
Specified by:
getConstantKey in interface Syntax
Parameters:
constant - the string to test.
Returns:
the key associated with the constant constant.

setConstantKey

public void setConstantKey(java.lang.String constant,
                           java.lang.Object constantKey)
Associates the constant constant to the syntactic key constantKey.
Parameters:
constant - a string describing a constant.
constantKey - a constant key (one of CONSTANT_PI, CONSTANT_E, CONSTANT_FALSE, CONSTANT_TRUE or an other user defined key).

getUnaryOperatorKey

public java.lang.Object getUnaryOperatorKey(java.lang.String unaryOperator)
Returns the key matching unaryOperator. The association is made with the setUnaryOperatorKey () method.
Specified by:
getUnaryOperatorKey in interface Syntax
Parameters:
unaryOperator - the string to test.
Returns:
the key associated with the unary operator unaryOperator.

setUnaryOperatorKey

public void setUnaryOperatorKey(java.lang.String unaryOperator,
                                java.lang.Object unaryOperatorKey)
Associates the unary operator unaryOperator to the syntactic key unaryOperatorKey.
Parameters:
unaryOperator - an unary operator.
unaryOperatorKey - an unary operator key (one of OPERATOR_POSITIVE, OPERATOR_OPPOSITE, OPERATOR_LOGICAL_NOT, OPERATOR_BITWISE_NOT or an other user defined key).

getBinaryOperatorKey

public java.lang.Object getBinaryOperatorKey(java.lang.String binaryOperator)
Returns the key matching binaryOperator. The association is made with the setBinaryOperatorKey () method.
Specified by:
getBinaryOperatorKey in interface Syntax
Parameters:
binaryOperator - the string to test.
Returns:
the key associated with the binary operator binaryOperator.

setBinaryOperatorKey

public void setBinaryOperatorKey(java.lang.String binaryOperator,
                                 java.lang.Object binaryOperatorKey)
Associates the binary operator binaryOperator to the syntactic key binaryOperatorKey.
Parameters:
binaryOperator - a binary operator.
binaryOperatorKey - a binary operator key (one of OPERATOR_ADD, OPERATOR_SUBSTRACT, OPERATOR_MODULO, OPERATOR_DIVIDE,... or an other user defined key)

getConditionPartKey

public java.lang.Object getConditionPartKey(java.lang.String conditionPart)
Returns the key matching conditionPart. The association is made with the setConditionPartKey () method.
Specified by:
getConditionPartKey in interface Syntax
Parameters:
conditionPart - the string to test.
Returns:
the key associated with the conditional part conditionPart.

getConditionPartCount

public int getConditionPartCount()
Returns 2 or 3 depending on whether the syntax using a condition with two or three parts. If a condition part was associated to the key CONDITION_IF with the setConditionPartKey method, it returns 3 otherwise it returns 2.
Specified by:
getConditionPartCount in interface Syntax
Returns:
2 or 3.

setConditionPartKey

public void setConditionPartKey(java.lang.String conditionPart,
                                java.lang.Object conditionPartKey)
Associates the condition part conditionPart to the syntactic key conditionPartKey.
Parameters:
conditionPart - a conditional part.
conditionPartKey - a conditional part key (one of CONDITION_IF, CONDITION_THEN, CONDITION_ELSE).

getCommonFunctionKey

public java.lang.Object getCommonFunctionKey(java.lang.String commonFunction)
Returns the key matching commonFunction. The association is made with the setCommonFunctionKey () method.
Specified by:
getCommonFunctionKey in interface Syntax
Parameters:
commonFunction - the string to test.
Returns:
the key associated with the common function commonFunction.

setCommonFunctionKey

public void setCommonFunctionKey(java.lang.String commonFunction,
                                 java.lang.Object commonFunctionKey)
Associates the common function of name commonFunction to the syntax key commonFunctionKey.
Parameters:
commonFunction - a function name.
commonFunctionKey - a common function key (one of FUNCTION_LN, FUNCTION_LOG, FUNCTION_EXP, FUNCTION_SQR,... or an other user defined key).

getFunction

public Function getFunction(java.lang.String functionName)
Returns a reference to the instance of Function whose name is functionName. The addFunction () method records the functions that a user wants to add to a syntax.
Specified by:
getFunction in interface Syntax
Parameters:
functionName - the string to test.
Returns:
the Function reference of name functionName.

addFunction

public void addFunction(Function function)
Adds function to the recognized functions of this syntax. The name used by the getSyntax () method is the value returned by function.getName ().
function may be a function previously parsed with FunctionParser or an intance of a Java written class implementing the Function interface.
Parameters:
function - the function to add.

removeFunction

public void removeFunction(Function function)
Removes function from the functions of this syntax.
Parameters:
function - the function to remove.

getBinaryOperatorPriority

public int getBinaryOperatorPriority(java.lang.Object binaryOperatorKey)
Returns the priority of the binary operator matching the key binaryOperatorKey.
Specified by:
getBinaryOperatorPriority in interface Syntax
Parameters:
binaryOperatorKey - a binary operator key.
Returns:
the priority of binaryOperatorKey set with the setBinaryOperatorPriority () method or 0 (the lowest priority).

setBinaryOperatorPriority

public void setBinaryOperatorPriority(java.lang.Object binaryOperatorKey,
                                      int priority)
Sets the priority of the binary operator matching the key binaryOperatorKey.
Parameters:
binaryOperatorKey - a binary operator key.
priority - a positive value equal to the priority of the operator.

getWhiteSpaceCharacters

public java.lang.String getWhiteSpaceCharacters()
Returns a string that contains all the delimiters allowed by the syntax as white spaces (tab, spaces,...).
Specified by:
getWhiteSpaceCharacters in interface Syntax
Returns:
null by default.

setWhiteSpaceCharacters

public void setWhiteSpaceCharacters(java.lang.String whiteSpaceCharacters)
Sets the string that contains all the delimiters allowed by the syntax as white spaces (tab, spaces,...).
Parameters:
whiteSpaces - the white spaces.

getOpeningBracket

public char getOpeningBracket()
Returns the char used as the opening bracket of the syntax.
Specified by:
getOpeningBracket in interface Syntax
Returns:
0 by default.

setOpeningBracket

public void setOpeningBracket(char openingBracket)
Sets the char used as the opening bracket of the syntax.
Parameters:
openingBracket - the opening bracket.

getClosingBracket

public char getClosingBracket()
Returns the char used as the closing bracket of the syntax.
Specified by:
getClosingBracket in interface Syntax
Returns:
0 by default.

setClosingBracket

public void setClosingBracket(char closingBracket)
Sets the char used as the closing bracket of the syntax.
Parameters:
closingBracket - the closing bracket.

getParameterSeparator

public char getParameterSeparator()
Returns the char used to separate parameters in a function call.
Specified by:
getParameterSeparator in interface Syntax
Returns:
0 by default.

setParameterSeparator

public void setParameterSeparator(char parameterSeparator)
Sets the char used to separate parameters in a function call.
Parameters:
parameterSeparator - the separator of parameters.

getDelimiters

public java.lang.String getDelimiters()
Returns a string containing the white spaces, the brackets, the parameter separator and all the characters of the (unary and binary) operators and the condition parts that are not valid identifiers with the isValidIdentifier () method.
Specified by:
getDelimiters in interface Syntax
Returns:
a string containing the set of characters of the syntax that may be used as delimiters between literals, constants or identifiers.
See Also:
com.eteks.syntax#isValidIdentifier

getAssignmentOperator

public java.lang.String getAssignmentOperator()
Returns the string used as the operator of assignment.
Specified by:
getAssignmentOperator in interface Syntax
Returns:
null by default.

setAssignmentOperator

public void setAssignmentOperator(java.lang.String assignmentOperator)
Sets the string used as the operator of assignment.
Parameters:
the - operator of assignment.

isCaseSensitive

public final boolean isCaseSensitive()
Returns true if identifiers, constants, operators and function of the syntax are case sensitive. This method is used by the parser for tests comparing the name of functions and parameters and also by getConstantKey (), getUnaryOperatorKey (), getBinaryOperatorKey (), getConditionPartKey (), getCommonFunctionKey () and getFunction () and their respective setter methods to compare strings respecting the case sensitivity set at creation of the syntax.
By default, a syntax isn't case sensitive.
Specified by:
isCaseSensitive in interface Syntax
Returns:
false by default.

isShortSyntax

public boolean isShortSyntax()
Returns true if expressions parsed with this syntax supports short cuts.
Specified by:
isShortSyntax in interface Syntax
Returns:
false by default.

setShortSyntax

public void setShortSyntax(boolean shortSyntax)
Sets the capabity of expressions parsed with this syntax to support syntax short cuts.
Parameters:
shortSyntax - true to enable the support of short cuts.
See Also:
Syntax.isShortSyntax()

&cp; 1998-2003 eTeks - All rights reserved