Search in sources :

Example 26 with Position

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");
}
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 27 with Position

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;
}
Also used : Position(lucee.transformer.Position) TagOther(lucee.transformer.bytecode.statement.tag.TagOther)

Example 28 with Position

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);
}
Also used : Position(lucee.transformer.Position)

Example 29 with Position

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);
}
Also used : OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) Position(lucee.transformer.Position) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) OPUnary(lucee.transformer.bytecode.op.OPUnary)

Example 30 with Position

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;
}
Also used : Condition(lucee.transformer.bytecode.statement.Condition) Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Aggregations

Position (lucee.transformer.Position)30 TemplateException (lucee.runtime.exp.TemplateException)21 BodyBase (lucee.transformer.bytecode.BodyBase)10 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)10 Expression (lucee.transformer.expression.Expression)10 Body (lucee.transformer.bytecode.Body)9 FunctionBody (lucee.transformer.bytecode.FunctionBody)9 ScriptBody (lucee.transformer.bytecode.ScriptBody)9 TagLibTag (lucee.transformer.library.tag.TagLibTag)6 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)5 Tag (lucee.transformer.bytecode.statement.tag.Tag)5 LitString (lucee.transformer.expression.literal.LitString)5 Variable (lucee.transformer.expression.var.Variable)5 OpVariable (lucee.transformer.bytecode.op.OpVariable)4 TagOther (lucee.transformer.bytecode.statement.tag.TagOther)3 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)2 TransformerException (lucee.transformer.TransformerException)2 OPUnary (lucee.transformer.bytecode.op.OPUnary)2 DoWhile (lucee.transformer.bytecode.statement.DoWhile)2 ComponentTemplateException (lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException)2