use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class AbstrCFMLExprTransformer method conditionalOp.
private Expression conditionalOp(ExprData data) throws TemplateException {
Expression expr = impOp(data);
if (data.srcCode.forwardIfCurrent('?')) {
comments(data);
// Elvis
if (data.srcCode.forwardIfCurrent(':')) {
comments(data);
Expression right = assignOp(data);
if (expr instanceof ExprBoolean)
return expr;
if (!(expr instanceof Variable))
throw new TemplateException(data.srcCode, "left operand of the Elvis operator has to be a variable or a function call");
Variable left = (Variable) expr;
/*List<Member> members = left.getMembers();
Member last=null;
for(Member m:members) {
last=m;
m.setSafeNavigated(true);
}
if(last!=null) {
last.setSafeNavigatedValue(right);
}
return left;*/
return OpElvis.toExpr(left, right);
}
Expression left = assignOp(data);
comments(data);
if (!data.srcCode.forwardIfCurrent(':'))
throw new TemplateException(data.srcCode, "invalid conditional operator");
comments(data);
Expression right = assignOp(data);
expr = OpContional.toExpr(expr, left, right);
}
return expr;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class AbstrCFMLExprTransformer method checker.
/**
* Hier werden die verschiedenen Moeglichen Werte erkannt
* und jenachdem wird mit der passenden Methode weitergefahren
* <br />
* EBNF:<br />
* <code>string | number | dynamic | sharp;</code>
* @return CFXD Element
* @throws TemplateException
*/
private Expression checker(ExprData data) throws TemplateException {
Expression expr = null;
// String
if ((expr = string(data)) != null) {
expr = subDynamic(data, expr, false, false);
// (expr instanceof Literal)?STATIC:DYNAMIC;// STATIC
data.mode = STATIC;
return expr;
}
// Number
if ((expr = number(data)) != null) {
expr = subDynamic(data, expr, false, false);
// (expr instanceof Literal)?STATIC:DYNAMIC;// STATIC
data.mode = STATIC;
return expr;
}
// closure
if ((expr = closure(data)) != null) {
data.mode = DYNAMIC;
return expr;
}
// lambda
if ((expr = lambda(data)) != null) {
data.mode = DYNAMIC;
return expr;
}
// Dynamic
if ((expr = dynamic(data)) != null) {
expr = newOp(data, expr);
expr = subDynamic(data, expr, true, false);
data.mode = DYNAMIC;
return expr;
}
// Sharp
if ((expr = sharp(data)) != null) {
data.mode = DYNAMIC;
return expr;
}
// JSON
if ((expr = json(data, JSON_ARRAY, '[', ']')) != null) {
expr = subDynamic(data, expr, false, false);
data.mode = DYNAMIC;
return expr;
}
if ((expr = json(data, JSON_STRUCT, '{', '}')) != null) {
expr = subDynamic(data, expr, false, false);
data.mode = DYNAMIC;
return expr;
}
// else Error
throw new TemplateException(data.srcCode, "Syntax Error, Invalid Construct");
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class AbstrCFMLExprTransformer method subDynamic.
private Expression subDynamic(ExprData data, Expression expr, boolean tryStatic, boolean isStaticChild) throws TemplateException {
String name = null;
Invoker invoker = null;
// Loop over nested Variables
boolean safeNavigation;
while (data.srcCode.isValidIndex()) {
safeNavigation = false;
ExprString nameProp = null, namePropUC = null;
// []
if (data.srcCode.forwardIfCurrent('[')) {
isStaticChild = false;
// get Next Var
nameProp = structElement(data);
namePropUC = nameProp;
// Valid Syntax ???
if (!data.srcCode.forwardIfCurrent(']'))
throw new TemplateException(data.srcCode, "Invalid Syntax Closing []] not found");
} else // .
if (isStaticChild || data.srcCode.forwardIfCurrent('.') || (safeNavigation = data.srcCode.forwardIfCurrent('?', '.'))) {
isStaticChild = false;
// Extract next Var String
comments(data);
Position line = data.srcCode.getPosition();
name = identifier(data, true);
if (name == null)
throw new TemplateException(data.srcCode, "Invalid identifier");
comments(data);
nameProp = Identifier.toIdentifier(data.factory, name, line, data.srcCode.getPosition());
namePropUC = Identifier.toIdentifier(data.factory, name, data.settings.dotNotationUpper ? Identifier.CASE_UPPER : Identifier.CASE_ORIGNAL, line, data.srcCode.getPosition());
} else // finish
{
break;
}
comments(data);
if (expr instanceof Invoker) {
invoker = (Invoker) expr;
} else {
invoker = new ExpressionInvoker(expr);
expr = invoker;
}
// safe navigation
Member member;
if (safeNavigation) {
List<Member> members = invoker.getMembers();
if (members.size() > 0) {
member = members.get(members.size() - 1);
member.setSafeNavigated(true);
}
}
// Method
if (data.srcCode.isCurrent('(')) {
// properly this is never used
if (nameProp == null && name != null)
nameProp = Identifier.toIdentifier(data.factory, name, Identifier.CASE_ORIGNAL, null, null);
invoker.addMember(member = getFunctionMember(data, nameProp, false));
} else
// property
invoker.addMember(member = data.factory.createDataMember(namePropUC));
if (safeNavigation) {
member.setSafeNavigated(true);
}
}
// STATIC SCOPE CALL
if (tryStatic) {
comments(data);
Expression staticCall = staticScope(data, expr);
if (staticCall != null)
return staticCall;
}
return expr;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class AbstrCFMLExprTransformer method _plusMinusOp.
private Expression _plusMinusOp(ExprData data, Expression expr, int opr) throws TemplateException {
// plus|Minus Assignment
if (data.srcCode.isCurrent('=') && expr instanceof Variable) {
data.srcCode.next();
comments(data);
Expression value = assignOp(data);
// if(opr==OpDouble.MINUS) value=OpNegateNumber.toExprDouble(value, null, null);
expr = new OPUnary((Variable) expr, value, OPUnary.PRE, opr, expr.getStart(), data.srcCode.getPosition());
// ExprDouble res = OpDouble.toExprDouble(expr, right,opr);
// expr=new OpVariable((Variable)expr,res,data.cfml.getPosition());
} else {
comments(data);
expr = OpDouble.toExprDouble(expr, modOp(data), opr);
}
return expr;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method expressionStatement.
/**
* List mithilfe des data.CFMLExprTransformer einen Ausruck ein.
* <br />
* EBNF:<br />
* <code>expression ";";</code>
* @param parent
* @return Ausdruck
* @throws TemplateException
*/
private Statement expressionStatement(ExprData data, Body parent) throws TemplateException {
// first we check if we have a access modifier
int pos = data.srcCode.getPos();
int access = -1;
boolean _final = false;
if (data.context == CTX_CFC || data.context == CTX_STATIC) {
if (data.srcCode.forwardIfCurrent("final ")) {
_final = true;
comments(data);
}
if (data.srcCode.forwardIfCurrent("private ")) {
access = Component.ACCESS_PRIVATE;
comments(data);
} else if (data.srcCode.forwardIfCurrent("package ")) {
access = Component.ACCESS_PACKAGE;
comments(data);
} else if (data.srcCode.forwardIfCurrent("public ")) {
access = Component.ACCESS_PUBLIC;
comments(data);
} else if (data.srcCode.forwardIfCurrent("remote ")) {
access = Component.ACCESS_REMOTE;
// comments(data);
throw new TemplateException(data.srcCode, "access modifier [remote] not supported in this context");
}
if (!_final && data.srcCode.forwardIfCurrent("final ")) {
_final = true;
comments(data);
}
}
Expression expr = expression(data);
checkSemiColonLineFeed(data, true, true, false);
// variable declaration (variable in body)
if (expr instanceof Variable) {
Variable v = (Variable) expr;
if (ASMUtil.isOnlyDataMember(v)) {
expr = new Assign(v, data.srcCode.getDialect() == CFMLEngine.DIALECT_LUCEE || data.config.getFullNullSupport() ? data.factory.createNull() : data.factory.EMPTY(), data.srcCode.getPosition());
}
}
// if a specific access was defined
if (access > -1 || _final) {
if (!(expr instanceof Assign)) {
data.srcCode.setPos(pos);
throw new TemplateException(data.srcCode, "invalid syntax, access modifier cannot be used in this context");
}
if (access > -1) {
// this is only supported with the Lucee dialect
// if(data.srcCode.getDialect()==CFMLEngine.DIALECT_CFML)
// throw new TemplateException(data.srcCode,
// "invalid syntax, access modifier cannot be used in this context");
((Assign) expr).setAccess(access);
}
if (_final)
((Assign) expr).setModifier(Member.MODIFIER_FINAL);
}
if (expr instanceof FunctionAsExpression)
return ((FunctionAsExpression) expr).getFunction();
return new ExpressionAsStatement(expr);
}
Aggregations