Search in sources :

Example 16 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class AbstrCFMLExprTransformer method staticScope.

private Expression staticScope(ExprData data, Expression expr) throws TemplateException {
    if (data.srcCode.forwardIfCurrent("::")) {
        if (!(expr instanceof Variable))
            throw new TemplateException(data.srcCode, "invalid syntax before [::]");
        Variable old = (Variable) expr;
        // set back to read again as a component path
        data.srcCode.setPos(old.getStart().pos);
        // now we read the component path
        ExprString componentPath = readComponentPath(data);
        if (!data.srcCode.forwardIfCurrent("::"))
            throw new TemplateException(data.srcCode, "invalid syntax before [::]" + data.srcCode.getCurrent());
        comments(data);
        BIF bif = null;
        if (componentPath instanceof LitString) {
            LitString ls = (LitString) componentPath;
            if ("super".equalsIgnoreCase(ls.getString())) {
                bif = ASMUtil.createBif(data, GET_SUPER_STATIC_SCOPE);
            }
        }
        // now we generate a _getStaticScope function call with that path
        if (bif == null) {
            bif = ASMUtil.createBif(data, GET_STATIC_SCOPE);
            bif.addArgument(new Argument(componentPath, "string"));
        }
        Variable var = data.factory.createVariable(old.getStart(), data.srcCode.getPosition());
        var.addMember(bif);
        // now we are reading what is coming after ":::"
        Expression sd = subDynamic(data, var, false, true);
        return sd;
    }
    return null;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) NamedArgument(lucee.transformer.bytecode.expression.var.NamedArgument) Argument(lucee.transformer.bytecode.expression.var.Argument) TemplateException(lucee.runtime.exp.TemplateException) ExprString(lucee.transformer.expression.ExprString) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 17 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class AbstrCFMLExprTransformer method json.

protected Expression json(ExprData data, FunctionLibFunction flf, char start, char end) throws TemplateException {
    if (!data.srcCode.forwardIfCurrent(start))
        return null;
    Position line = data.srcCode.getPosition();
    data.srcCode.removeSpace();
    // [:|=]
    if (data.srcCode.forwardIfCurrent(':', ']') || data.srcCode.forwardIfCurrent('=', ']')) {
        flf = flf.getFunctionLib().getFunction("_literalOrderedStruct");
        BIF bif = new BIF(data.factory, data.settings, flf);
        bif.setArgType(flf.getArgType());
        try {
            bif.setClassDefinition(flf.getFunctionClassDefinition());
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            throw new PageRuntimeException(t);
        }
        bif.setReturnType(flf.getReturnTypeAsString());
        data.ep.add(flf, bif, data.srcCode);
        Variable var = data.factory.createVariable(line, data.srcCode.getPosition());
        var.addMember(bif);
        return var;
    }
    BIF bif = new BIF(data.factory, data.settings, flf);
    bif.setArgType(flf.getArgType());
    try {
        bif.setClassDefinition(flf.getFunctionClassDefinition());
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw new PageRuntimeException(t);
    }
    bif.setReturnType(flf.getReturnTypeAsString());
    do {
        comments(data);
        if (data.srcCode.isCurrent(end))
            break;
        bif.addArgument(functionArgument(data, data.settings.dotNotationUpper));
        comments(data);
    } while (data.srcCode.forwardIfCurrent(','));
    comments(data);
    if (!data.srcCode.forwardIfCurrent(end))
        throw new TemplateException(data.srcCode, "Invalid Syntax Closing [" + end + "] not found");
    comments(data);
    if (flf.hasTteClass()) {
        FunctionLibFunction tmp = flf.getEvaluator().pre(bif, flf);
        if (tmp != null && tmp != flf) {
            bif.setFlf(flf = tmp);
            bif.setArgType(flf.getArgType());
            try {
                bif.setClassDefinition(flf.getFunctionClassDefinition());
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                throw new PageRuntimeException(t);
            }
            bif.setReturnType(flf.getReturnTypeAsString());
        }
    }
    data.ep.add(flf, bif, data.srcCode);
    Variable var = data.factory.createVariable(line, data.srcCode.getPosition());
    var.addMember(bif);
    return var;
}
Also used : OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 18 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class AbstrCFMLExprTransformer method string.

/*private Expression variable(Data data) throws TemplateException {
		Expression expr=null;
		
		// Dynamic
		if((expr=dynamic(data))!=null) {
			expr = subDynamic(data,expr);
			data.mode=DYNAMIC;
			return expr;
		} 
		return null;
	}*/
/**
 * Transfomiert einen lierale Zeichenkette.
 * <br />
 * EBNF:<br />
 * <code>("'" {"##"|"''"|"#" impOp "#"| ?-"#"-"'" } "'") |
 *	                 (""" {"##"|""""|"#" impOp "#"| ?-"#"-""" } """);</code>
 * @param data
 * @return CFXD Element
 * @throws TemplateException
 */
protected Expression string(ExprData data) throws TemplateException {
    // check starting character for a string literal
    if (!data.srcCode.isCurrent('"') && !data.srcCode.isCurrent('\''))
        return null;
    Position line = data.srcCode.getPosition();
    // Init Parameter
    char quoter = data.srcCode.getCurrentLower();
    StringBuilder str = new StringBuilder();
    Expression expr = null;
    while (data.srcCode.hasNext()) {
        data.srcCode.next();
        // check sharp
        if (data.srcCode.isCurrent('#')) {
            // Ecaped sharp
            if (data.srcCode.isNext('#')) {
                data.srcCode.next();
                str.append('#');
            } else // get Content of sharp
            {
                data.srcCode.next();
                comments(data);
                Expression inner = assignOp(data);
                comments(data);
                if (!data.srcCode.isCurrent('#'))
                    throw new TemplateException(data.srcCode, "Invalid Syntax Closing [#] not found");
                ExprString exprStr = null;
                if (str.length() != 0) {
                    exprStr = data.factory.createLitString(str.toString(), line, data.srcCode.getPosition());
                    if (expr != null) {
                        expr = data.factory.opString(expr, exprStr);
                    } else
                        expr = exprStr;
                    str = new StringBuilder();
                }
                if (expr == null) {
                    expr = inner;
                } else {
                    expr = data.factory.opString(expr, inner);
                }
            }
        } else // check quoter
        if (data.srcCode.isCurrent(quoter)) {
            // Ecaped sharp
            if (data.srcCode.isNext(quoter)) {
                data.srcCode.next();
                str.append(quoter);
            } else // finsish
            {
                break;
            }
        } else // all other character
        {
            str.append(data.srcCode.getCurrent());
        }
    }
    if (!data.srcCode.forwardIfCurrent(quoter))
        throw new TemplateException(data.srcCode, "Invalid Syntax Closing [" + quoter + "] not found");
    if (expr == null)
        expr = data.factory.createLitString(str.toString(), line, data.srcCode.getPosition());
    else if (str.length() != 0) {
        expr = data.factory.opString(expr, data.factory.createLitString(str.toString(), line, data.srcCode.getPosition()));
    }
    comments(data);
    if (expr instanceof Variable) {
        Variable var = (Variable) expr;
        var.fromHash(true);
    }
    return expr;
}
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) TemplateException(lucee.runtime.exp.TemplateException) ExprString(lucee.transformer.expression.ExprString)

Example 19 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class SimpleExprTransformer method string.

/**
 * Liest den String ein
 * @return Element
 * @throws TemplateException
 */
public Expression string(Factory f, SourceCode cfml) throws TemplateException {
    cfml.removeSpace();
    char quoter = cfml.getCurrentLower();
    if (quoter != '"' && quoter != '\'')
        return null;
    StringBuffer str = new StringBuffer();
    boolean insideSpecial = false;
    Position line = cfml.getPosition();
    while (cfml.hasNext()) {
        cfml.next();
        // check special
        if (cfml.isCurrent(specialChar)) {
            insideSpecial = !insideSpecial;
            str.append(specialChar);
        } else // check quoter
        if (!insideSpecial && cfml.isCurrent(quoter)) {
            // Ecaped sharp
            if (cfml.isNext(quoter)) {
                cfml.next();
                str.append(quoter);
            } else // finsish
            {
                break;
            }
        } else // all other character
        {
            str.append(cfml.getCurrent());
        }
    }
    if (!cfml.forwardIfCurrent(quoter))
        throw new TemplateException(cfml, "Invalid Syntax Closing [" + quoter + "] not found");
    LitString rtn = f.createLitString(str.toString(), line, cfml.getPosition());
    cfml.removeSpace();
    return rtn;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException)

Example 20 with TemplateException

use of lucee.runtime.exp.TemplateException in project Lucee by lucee.

the class SimpleExprTransformer method simple.

/**
 * Liest ein
 * @return Element
 * @throws TemplateException
 */
public Expression simple(Factory f, SourceCode cfml) throws TemplateException {
    StringBuffer sb = new StringBuffer();
    Position line = cfml.getPosition();
    while (cfml.isValidIndex()) {
        if (cfml.isCurrent(' ') || cfml.isCurrent('>') || cfml.isCurrent("/>"))
            break;
        else if (cfml.isCurrent('"') || cfml.isCurrent('#') || cfml.isCurrent('\'')) {
            throw new TemplateException(cfml, "simple attribute value can't contain [" + cfml.getCurrent() + "]");
        } else
            sb.append(cfml.getCurrent());
        cfml.next();
    }
    cfml.removeSpace();
    return f.createLitString(sb.toString(), line, cfml.getPosition());
}
Also used : Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException)

Aggregations

TemplateException (lucee.runtime.exp.TemplateException)55 Position (lucee.transformer.Position)21 Expression (lucee.transformer.expression.Expression)18 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)15 LitString (lucee.transformer.expression.literal.LitString)14 ScriptBody (lucee.transformer.bytecode.ScriptBody)9 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)9 Body (lucee.transformer.bytecode.Body)8 BodyBase (lucee.transformer.bytecode.BodyBase)8 FunctionBody (lucee.transformer.bytecode.FunctionBody)8 ComponentTemplateException (lucee.transformer.cfml.script.AbstrCFMLScriptTransformer.ComponentTemplateException)8 Variable (lucee.transformer.expression.var.Variable)8 ExprString (lucee.transformer.expression.ExprString)7 TagLibTag (lucee.transformer.library.tag.TagLibTag)6 PageSourceCode (lucee.transformer.util.PageSourceCode)6 ArrayList (java.util.ArrayList)5 OpVariable (lucee.transformer.bytecode.op.OpVariable)5 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)5 Resource (lucee.commons.io.res.Resource)4 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)4