use of lucee.transformer.Position in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method forStatement.
/**
* Liest ein for Statement ein.
* <br />
* EBNF:<br />
* <code>expression spaces ";" spaces condition spaces ";" spaces expression spaces ")" spaces block;</code>
* @return for Statement
* @throws TemplateException
*/
private final Statement forStatement(ExprData data) throws TemplateException {
int pos = data.srcCode.getPos();
// id
String id = variableDec(data, false);
if (id == null) {
data.srcCode.setPos(pos);
return null;
}
if (id.equalsIgnoreCase("for")) {
id = null;
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent('(')) {
data.srcCode.setPos(pos);
return null;
}
} else {
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent(':')) {
data.srcCode.setPos(pos);
return null;
}
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent("for", '(')) {
data.srcCode.setPos(pos);
return null;
}
}
// if(!data.srcCode.forwardIfCurrent("for",'('))
// return null;
Expression left = null;
Body body = new BodyBase(data.factory);
Position line = data.srcCode.getPosition();
comments(data);
if (!data.srcCode.isCurrent(';')) {
// left
left = expression(data);
comments(data);
}
// middle for
if (data.srcCode.forwardIfCurrent(';')) {
Expression cont = null;
Expression update = null;
// condition
comments(data);
if (!data.srcCode.isCurrent(';')) {
cont = condition(data);
comments(data);
}
// middle
if (!data.srcCode.forwardIfCurrent(';'))
throw new TemplateException(data.srcCode, "invalid syntax in for statement");
// update
comments(data);
if (!data.srcCode.isCurrent(')')) {
update = expression(data);
comments(data);
}
// start )
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "invalid syntax in for statement, for statement must end with a [)]");
// ex block
statement(data, body, CTX_FOR);
return new For(data.factory, left, cont, update, body, line, data.srcCode.getPosition(), id);
} else // middle foreach
if (data.srcCode.forwardIfCurrent("in")) {
// condition
comments(data);
Expression value = expression(data);
comments(data);
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "invalid syntax in for statement, for statement must end with a [)]");
// ex block
statement(data, body, CTX_FOR);
if (!(left instanceof Variable))
throw new TemplateException(data.srcCode, "invalid syntax in for statement, left value is invalid");
// throw new TemplateException(data.srcCode,"invalid syntax in for statement, right value is invalid");
return new ForEach((Variable) left, value, body, line, data.srcCode.getPosition(), id);
} else
throw new TemplateException(data.srcCode, "invalid syntax in for statement");
}
use of lucee.transformer.Position in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method staticStatement.
private final Tag staticStatement(ExprData data, Body parent) throws TemplateException {
if (!data.srcCode.forwardIfCurrent("static", '{'))
return null;
// get one back to have again { so the parser works
data.srcCode.previous();
Position start = data.srcCode.getPosition();
TagOther tag = createStaticTag(data, start);
statement(data, tag.getBody(), CTX_STATIC);
return tag;
}
use of lucee.transformer.Position in project Lucee by lucee.
the class AbstrCFMLExprTransformer method notOp.
/**
* Transfomiert eine Not (not) Operation. Im Gegensatz zu CFMX ,
* wird das "!" Zeichen auch als Not Operator anerkannt.
* <br />
* EBNF:<br />
* <code>[("not"|"!") spaces] decsionOp; (* "!" Existiert in CFMX nicht *)</code>
* @return CFXD Element
* @throws TemplateException
*/
private Expression notOp(ExprData data) throws TemplateException {
// And Operation
Position line = data.srcCode.getPosition();
if (data.srcCode.isCurrent('!') && !data.srcCode.isCurrent("!=")) {
data.srcCode.next();
comments(data);
return OpNegate.toExprBoolean(notOp(data), line, data.srcCode.getPosition());
} else if (data.srcCode.forwardIfCurrentAndNoWordAfter("not")) {
comments(data);
return OpNegate.toExprBoolean(notOp(data), line, data.srcCode.getPosition());
}
return decsionOp(data);
}
use of lucee.transformer.Position in project Lucee by lucee.
the class AbstrCFMLExprTransformer method negatePlusMinusOp.
/**
* Negate Numbers
* @return CFXD Element
* @throws TemplateException
*/
private Expression negatePlusMinusOp(ExprData data) throws TemplateException {
// And Operation
Position line = data.srcCode.getPosition();
if (data.srcCode.forwardIfCurrent('-')) {
// pre increment
if (data.srcCode.forwardIfCurrent('-')) {
comments(data);
Expression expr = clip(data);
return new OPUnary((Variable) expr, data.factory.DOUBLE_ONE(), OPUnary.PRE, OpDouble.MINUS, line, data.srcCode.getPosition());
// ExprDouble res = OpDouble.toExprDouble(expr, LitDouble.toExprDouble(1D),OpDouble.MINUS);
// return new OpVariable((Variable)expr,res,data.cfml.getPosition());
}
comments(data);
return OpNegateNumber.toExprDouble(clip(data), OpNegateNumber.MINUS, line, data.srcCode.getPosition());
} else if (data.srcCode.forwardIfCurrent('+')) {
if (data.srcCode.forwardIfCurrent('+')) {
comments(data);
Expression expr = clip(data);
return new OPUnary((Variable) expr, data.factory.DOUBLE_ONE(), OPUnary.PRE, OpDouble.PLUS, line, data.srcCode.getPosition());
}
comments(data);
// OpNegateNumber.toExprDouble(clip(),OpNegateNumber.PLUS,line);
return data.factory.toExprDouble(clip(data));
}
return clip(data);
}
use of lucee.transformer.Position in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method ifStatement.
/**
* Liest ein if Statement ein.
* <br />
* EBNF:<br />
* <code>spaces condition spaces ")" spaces block {"else if" spaces "(" elseifStatement spaces }
* [("else" spaces "(" | "else ") elseStatement spaces];</code>
* @return if Statement
* @throws TemplateException
*/
private final Statement ifStatement(ExprData data) throws TemplateException {
if (!data.srcCode.forwardIfCurrent("if", '('))
return null;
Position line = data.srcCode.getPosition();
Body body = new BodyBase(data.factory);
Condition cont = new Condition(data.factory, condition(data), body, line, null);
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "if statement must end with a [)]");
// ex block
statement(data, body, CTX_IF);
// else if
comments(data);
while (elseifStatement(data, cont)) {
comments(data);
}
// else
if (elseStatement(data, cont)) {
comments(data);
}
cont.setEnd(data.srcCode.getPosition());
return cont;
}
Aggregations