use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method lambdaPart.
@Override
protected final Function lambdaPart(ExprData data, String id, int access, int modifier, String rtnType, Position line, ArrayList<Argument> args) throws TemplateException {
Body body = new FunctionBody(data.factory);
Function func = new Lambda(data.root, id, access, modifier, rtnType, body, line, null);
// new FunctionImpl(data.page,id,access,rtnType,body,line,null);
comments(data);
// add arguments
for (Argument arg : args) {
func.addArgument(arg.getName(), arg.getType(), arg.getRequired(), arg.getDefaultValue(), arg.isPassByReference(), arg.getDisplayName(), arg.getHint(), arg.getMetaData());
}
comments(data);
// body
boolean oldInsideFunction = data.insideFunction;
data.insideFunction = true;
try {
if (data.srcCode.isCurrent('{')) {
statement(data, body, CTX_FUNCTION);
} else {
if (data.srcCode.forwardIfCurrent("return ")) {
comments(data);
}
// ex block
short prior = data.context;
data.context = CTX_FUNCTION;
comments(data);
Expression expr = expression(data);
// checkSemiColonLineFeed( data, true ,true );
Return rtn = new Return(expr, line, data.srcCode.getPosition());
body.addStatement(rtn);
data.docComment = null;
data.context = prior;
}
} finally {
data.insideFunction = oldInsideFunction;
}
/*try {
// ex block
statement(data,body,CTX_FUNCTION);
}
finally{
data.insideFunction=oldInsideFunction;
}*/
func.setEnd(data.srcCode.getPosition());
comments(data);
return func;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method returnStatement.
/**
* Liest ein return Statement ein.
* <br />
* EBNF:<br />
* <code>spaces expressionStatement spaces;</code>
* @return return Statement
* @throws TemplateException
*/
private final Return returnStatement(ExprData data) throws TemplateException {
if (!data.srcCode.forwardIfCurrentAndNoVarExt("return"))
return null;
Position line = data.srcCode.getPosition();
Return rtn;
comments(data);
if (checkSemiColonLineFeed(data, false, false, false))
rtn = new Return(data.factory, line, data.srcCode.getPosition());
else {
Expression expr = expression(data);
checkSemiColonLineFeed(data, true, true, false);
rtn = new Return(expr, line, data.srcCode.getPosition());
}
comments(data);
return rtn;
}
use of lucee.transformer.expression.Expression in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method __singleAttrStatement.
private final Statement __singleAttrStatement(Body parent, ExprData data, TagLibTag tlt, boolean allowTwiceAttr) throws TemplateException {
String tagName = tlt.getName();
if (data.srcCode.forwardIfCurrent(tagName)) {
if (!data.srcCode.isCurrent(' ') && !data.srcCode.isCurrent(';')) {
data.srcCode.setPos(data.srcCode.getPos() - tagName.length());
return null;
}
} else
return null;
int pos = data.srcCode.getPos() - tagName.length();
Position line = data.srcCode.getPosition();
// TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode,tagName.equals("pageencoding")?"processingdirective":tagName);
Tag tag = getTag(data, parent, tlt, line, null);
tag.setScriptBase(true);
tag.setTagLibTag(tlt);
comments(data);
// attribute
TagLibTagAttr attr = tlt.getScript().getSingleAttr();
String attrName = null;
Expression attrValue = null;
short attrType = ATTR_TYPE_NONE;
if (attr != null) {
attrType = attr.getScriptSupport();
char c = data.srcCode.getCurrent();
if (ATTR_TYPE_REQUIRED == attrType || (!data.srcCode.isCurrent(';') && ATTR_TYPE_OPTIONAL == attrType)) {
if (data.srcCode.isCurrent('{')) {
// this can be only a json string
int p = data.srcCode.getPos();
try {
attrValue = isSimpleValue(attr.getType()) ? null : json(data, JSON_STRUCT, '{', '}');
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
data.srcCode.setPos(p);
}
} else
attrValue = attributeValue(data, tlt.getScript().getRtexpr());
if (attrValue != null && isOperator(c)) {
data.srcCode.setPos(pos);
return null;
}
}
}
if (attrValue != null) {
attrName = attr.getName();
TagLibTagAttr tlta = tlt.getAttribute(attr.getName(), true);
tag.addAttribute(new Attribute(false, attrName, CastOther.toExpression(attrValue, tlta.getType()), tlta.getType()));
} else if (ATTR_TYPE_REQUIRED == attrType) {
data.srcCode.setPos(pos);
return null;
}
// body
if (tlt.getHasBody()) {
Body body = new BodyBase(data.factory);
boolean wasSemiColon = statement(data, body, tlt.getScript().getContext());
if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
tag.setBody(body);
} else
checkSemiColonLineFeed(data, true, true, true);
if (tlt.hasTTE())
data.ep.add(tlt, tag, data.flibs, data.srcCode);
if (!StringUtil.isEmpty(attrName))
validateAttributeName(attrName, data.srcCode, new ArrayList<String>(), tlt, new RefBooleanImpl(false), new StringBuffer(), allowTwiceAttr);
tag.setEnd(data.srcCode.getPosition());
eval(tlt, data, tag);
return tag;
}
use of lucee.transformer.expression.Expression 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.expression.Expression in project Lucee by lucee.
the class DocCommentTransformer method param.
private Attribute param(Factory factory, ParserString ps) {
String name = paramName(ps);
if (name == null)
return new Attribute(true, "@", factory.TRUE(), "boolean");
// white space
while (ps.isValidIndex() && ps.isCurrentWhiteSpace()) {
if (ps.getCurrent() == '\n')
return new Attribute(true, name, factory.TRUE(), "boolean");
ps.next();
}
Expression value = paramValue(factory, ps);
return new Attribute(true, name, value, value instanceof LitBoolean ? "boolean" : "string");
}
Aggregations