Home pageFind It!Contact JeksJeks documentation

Jeks

 Jeks forum

This forum is dedicated to Jeks.
You may read freely the messages it contents. If you want to write a message or answer to a subject, subscribe to it first.

Subjects Recent messages Login Subscribe

Messages of subject String-Constants in ExpressionParser

dondon

Member since : Sep 18, 2003
Messages : 2
 Sep 18, 2003 at 11:11 AM
Hello,

I need expressions like this:

= if(AA = 'StringConstantEnteredByUserInRuntime') then true else false

AA is a parameter, however the 'StringConstantEnteredByUserInRuntime' is (variable) constant.

I solved the problem not very elegantly:

public final class StringConstantExpressionParser extends ExpressionParser {
public StringConstantExpressionParser(Syntax syntax, ExpressionParameter expressionParameter) {
super(syntax, expressionParameter);
}
protected Parser.Lexical getLexical(
String expressionDefinition,
int definitionIndex,
Object parserData)
throws CompilationException {
try {
return super.getLexical(expressionDefinition, definitionIndex, parserData);
}
catch (CompilationException ex) {
// Catch the exception to check if the extracted lexical is a parameter
String extractedString = ex.getExtractedString();
if (ex.getErrorNumber() == CompilationException.SYNTAX_ERROR && extractedString != null) {

if (extractedString.startsWith("'") && extractedString.endsWith("'")) {
return new Parser.Lexical(
FunctionParser.LEXICAL_CONSTANT,
extractedString,
extractedString);
}
}
// Not a string-constant of the expression
throw ex;
}
}
}

This works for simple cases. But as soon as the StringConstant contains characters from syntax.getDelimiters() I do get a syntax error. What can I do about this?

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Sep 20, 2003 at 8:59 AM
Instead of creating a new parser class, you should create a new Syntax class that implements the getLiteral method correctly. You can extends the com.eteks.parser.DefaultSyntax for example and override its getLiteral method. Please have a look at the implementation of this method in JavaSyntax to get a better idea of the way to do it.

You should also use a new Interpreter class at run time that enables the comparison of two Strings with the equal operator in a getBinaryOperatorValue method. For example, you could extends the com.eteks.parser.WrapperInterpreter and implements the getBinaryOperatorValue method that way :

public Object getBinaryOperatorValue (Object binaryOperatorKey, Object param1, Object param2)
{
if ( binaryOperatorKey.equals (Syntax.OPERATOR_EQUAL)
&& param1 instanceof String
&& param2 instanceof String)
return param1.equals(param2);
else
return super.getBinaryOperatorValue (binaryOperatorKey, param1, param2);
}
---
Manu (moderator/modérateur)

dondon

Member since : Sep 18, 2003
Messages : 2
 Sep 23, 2003 at 11:50 AM
Thanks a lot for your help. In spite of the few messages in the forum, Jeks seems to be alive. Is there still any active development? If so, what changes can we expect in the future?

I do have a small comment:
I would like to have a setCaseSensitive(boolean) in AbstractSyntax.

Thanks.

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Feb 10, 2004 at 11:10 PM
> Is there still any active development?

Yes, this product is still alive and there should be a major update this year.

> If so, what changes can we expect in the future?

Mainly in Jeks spreadsheet (cell format and printing most probably).
---
Manu (moderator/modérateur)


Home pageFind It!ContactTop

© Copyrights 1997-2023 eTeks - All rights reserved

JeksJeks documentation