Search in sources :

Example 61 with Expression

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;
}
Also used : Function(lucee.transformer.bytecode.statement.udf.Function) CFFunction(lucee.runtime.functions.system.CFFunction) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) Return(lucee.transformer.bytecode.statement.Return) Argument(lucee.transformer.bytecode.statement.Argument) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) FunctionBody(lucee.transformer.bytecode.FunctionBody) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) Lambda(lucee.transformer.bytecode.statement.udf.Lambda)

Example 62 with Expression

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;
}
Also used : Return(lucee.transformer.bytecode.statement.Return) Position(lucee.transformer.Position) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression)

Example 63 with Expression

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;
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) Position(lucee.transformer.Position) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) ArrayList(java.util.ArrayList) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 64 with Expression

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");
}
Also used : Variable(lucee.transformer.expression.var.Variable) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) For(lucee.transformer.bytecode.statement.For) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase) ForEach(lucee.transformer.bytecode.statement.ForEach)

Example 65 with Expression

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");
}
Also used : Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Expression(lucee.transformer.expression.Expression) LitBoolean(lucee.transformer.expression.literal.LitBoolean) ParserString(lucee.commons.lang.ParserString)

Aggregations

Expression (lucee.transformer.expression.Expression)74 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)34 LitString (lucee.transformer.expression.literal.LitString)25 TemplateException (lucee.runtime.exp.TemplateException)19 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)16 Variable (lucee.transformer.expression.var.Variable)16 Body (lucee.transformer.bytecode.Body)11 ExprString (lucee.transformer.expression.ExprString)11 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)11 Position (lucee.transformer.Position)10 OpVariable (lucee.transformer.bytecode.op.OpVariable)10 LitBoolean (lucee.transformer.expression.literal.LitBoolean)8 Literal (lucee.transformer.expression.literal.Literal)8 ArrayList (java.util.ArrayList)7 TransformerException (lucee.transformer.TransformerException)7 BodyBase (lucee.transformer.bytecode.BodyBase)7 Statement (lucee.transformer.bytecode.Statement)7 Argument (lucee.transformer.bytecode.expression.var.Argument)7 PrintOut (lucee.transformer.bytecode.statement.PrintOut)6 FunctionBody (lucee.transformer.bytecode.FunctionBody)5