|
http://www.eteks.com | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.eteks.parser.AbstractSyntax
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 :
setBinaryOperatorKey ("+", OPERATOR_ADD)
associates the lexical
+
to the key OPERATOR_ADD
of a syntax, so the getBinaryOperatorKey ("+")
method will return the key OPERATOR_ADD
for the +
lexical at parsing time
(all the constants, operators and functions are stored in different hashtables associating a
string to a syntactic key).setOpeningBracket ('(')
stores the character (
, that will be returned
by the getOpeningBracket ()
method.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.
ResourceSyntax
,
JavaSyntax
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 |
public AbstractSyntax()
public AbstractSyntax(boolean caseSensitive)
caseSensitive
caseSensitive
- true
if case sensitive.Method Detail |
public java.lang.Object getConstantKey(java.lang.String constant)
constant
. The association is made
with the setConstantKey ()
.getConstantKey
in interface Syntax
constant
- the string to test.constant
.public void setConstantKey(java.lang.String constant, java.lang.Object constantKey)
constant
to the syntactic key
constantKey
.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).public java.lang.Object getUnaryOperatorKey(java.lang.String unaryOperator)
unaryOperator
. The association is made
with the setUnaryOperatorKey ()
method.getUnaryOperatorKey
in interface Syntax
unaryOperator
- the string to test.unaryOperator
.public void setUnaryOperatorKey(java.lang.String unaryOperator, java.lang.Object unaryOperatorKey)
unaryOperator
to the syntactic key
unaryOperatorKey
.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).public java.lang.Object getBinaryOperatorKey(java.lang.String binaryOperator)
binaryOperator
. The association is made
with the setBinaryOperatorKey ()
method.getBinaryOperatorKey
in interface Syntax
binaryOperator
- the string to test.binaryOperator
.public void setBinaryOperatorKey(java.lang.String binaryOperator, java.lang.Object binaryOperatorKey)
binaryOperator
to the syntactic key
binaryOperatorKey
.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)public java.lang.Object getConditionPartKey(java.lang.String conditionPart)
conditionPart
. The association is made
with the setConditionPartKey ()
method.getConditionPartKey
in interface Syntax
conditionPart
- the string to test.conditionPart
.public int getConditionPartCount()
CONDITION_IF
with
the setConditionPartKey
method, it returns 3 otherwise it returns 2.getConditionPartCount
in interface Syntax
public void setConditionPartKey(java.lang.String conditionPart, java.lang.Object conditionPartKey)
conditionPart
to the syntactic key
conditionPartKey
.conditionPart
- a conditional part.conditionPartKey
- a conditional part key (one of CONDITION_IF
,
CONDITION_THEN
, CONDITION_ELSE
).public java.lang.Object getCommonFunctionKey(java.lang.String commonFunction)
commonFunction
. The association is made
with the setCommonFunctionKey ()
method.getCommonFunctionKey
in interface Syntax
commonFunction
- the string to test.commonFunction
.public void setCommonFunctionKey(java.lang.String commonFunction, java.lang.Object commonFunctionKey)
commonFunction
to the syntax key
commonFunctionKey
.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).public Function getFunction(java.lang.String functionName)
Function
whose name is functionName
.
The addFunction ()
method records the functions that a user wants to
add to a syntax.getFunction
in interface Syntax
functionName
- the string to test.Function
reference of name functionName
.public void addFunction(Function function)
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.function
- the function to add.public void removeFunction(Function function)
function
from the functions of this syntax.function
- the function to remove.public int getBinaryOperatorPriority(java.lang.Object binaryOperatorKey)
binaryOperatorKey
.getBinaryOperatorPriority
in interface Syntax
binaryOperatorKey
- a binary operator key.binaryOperatorKey
set with the
setBinaryOperatorPriority ()
method or 0 (the lowest priority).public void setBinaryOperatorPriority(java.lang.Object binaryOperatorKey, int priority)
binaryOperatorKey
.binaryOperatorKey
- a binary operator key.priority
- a positive value equal to the priority of the operator.public java.lang.String getWhiteSpaceCharacters()
getWhiteSpaceCharacters
in interface Syntax
null
by default.public void setWhiteSpaceCharacters(java.lang.String whiteSpaceCharacters)
whiteSpaces
- the white spaces.public char getOpeningBracket()
getOpeningBracket
in interface Syntax
public void setOpeningBracket(char openingBracket)
openingBracket
- the opening bracket.public char getClosingBracket()
getClosingBracket
in interface Syntax
public void setClosingBracket(char closingBracket)
closingBracket
- the closing bracket.public char getParameterSeparator()
getParameterSeparator
in interface Syntax
public void setParameterSeparator(char parameterSeparator)
parameterSeparator
- the separator of parameters.public java.lang.String getDelimiters()
isValidIdentifier ()
method.getDelimiters
in interface Syntax
com.eteks.syntax#isValidIdentifier
public java.lang.String getAssignmentOperator()
getAssignmentOperator
in interface Syntax
null
by default.public void setAssignmentOperator(java.lang.String assignmentOperator)
the
- operator of assignment.public final boolean isCaseSensitive()
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.isCaseSensitive
in interface Syntax
false
by default.public boolean isShortSyntax()
true
if expressions parsed with this syntax supports short cuts.isShortSyntax
in interface Syntax
false
by default.public void setShortSyntax(boolean shortSyntax)
shortSyntax
- true
to enable the support of short cuts.Syntax.isShortSyntax()
|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |