Search in sources :

Example 51 with TemplateException

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

the class JavaScriptTransformer method transform.

@Override
public Body transform(Factory factory, Root root, EvaluatorPool ep, TagLib[][] tlibs, FunctionLib[] flibs, String surroundingTagName, TagLibTag[] scriptTags, SourceCode cfml, TransfomerSettings settings) throws TemplateException {
    StringBuilder sb = new StringBuilder();
    // MUST add again int startline=cfml.getLine();
    while (!cfml.isAfterLast() && !cfml.isCurrent("</", surroundingTagName)) {
        sb.append(cfml.getCurrent());
        cfml.next();
    }
    // int endline=cfml.getLine();
    if (cfml.isAfterLast())
        // TODO better error message
        throw new TemplateException(cfml, "missing end tag");
    if (true)
        throw new RuntimeException("not implemented");
    try {
        // MUST add again CompilationUnit cu = JavaParser.parse(bais);
        // MUST add again DataBag db = new DataBag();
        ScriptBody body = new ScriptBody(factory);
        return body;
    // MUST add again new JavaParserVisitor(body,start,end).visit(cu, db);
    } catch (Exception e) {
        throw new TemplateException(cfml, e);
    }
}
Also used : TemplateException(lucee.runtime.exp.TemplateException) ScriptBody(lucee.transformer.bytecode.ScriptBody) TemplateException(lucee.runtime.exp.TemplateException)

Example 52 with TemplateException

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

the class AbstrCFMLExprTransformer method getFunctionMemberAttrs.

private int getFunctionMemberAttrs(ExprData data, ExprString name, boolean checkLibrary, Func fm, FunctionLibFunction flf) throws TemplateException {
    // Function Attributes
    ArrayList<FunctionLibFunctionArg> arrFuncLibAtt = null;
    // int libLen = 0;
    if (checkLibrary) {
        arrFuncLibAtt = flf.getArg();
    // libLen = arrFuncLibAtt.size();
    }
    int count = 0;
    do {
        data.srcCode.next();
        comments(data);
        // finish
        if (count == 0 && data.srcCode.isCurrent(')'))
            break;
        // Argument arg;
        if (checkLibrary && flf.getArgType() != FunctionLibFunction.ARG_DYNAMIC) {
            // current attribues from library
            String _type;
            try {
                _type = arrFuncLibAtt.get(count).getTypeAsString();
            } catch (IndexOutOfBoundsException e) {
                _type = null;
            }
            fm.addArgument(functionArgument(data, _type, false));
        } else {
            fm.addArgument(functionArgument(data, false));
        }
        comments(data);
        count++;
        if (data.srcCode.isCurrent(')'))
            break;
    } while (data.srcCode.isCurrent(','));
    if (!data.srcCode.forwardIfCurrent(')')) {
        if (name != null) {
            throw new TemplateException(data.srcCode, "Invalid Syntax Closing [)] for function [" + (flf != null ? flf.getName() : ASMUtil.display(name)) + "] not found");
        }
        throw new TemplateException(data.srcCode, "Invalid Syntax Closing [)] not found");
    }
    return count;
}
Also used : TemplateException(lucee.runtime.exp.TemplateException) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) FunctionLibFunctionArg(lucee.transformer.library.function.FunctionLibFunctionArg)

Example 53 with TemplateException

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

the class AbstrCFMLExprTransformer method sharp.

/**
 * Sharps (#) die innerhalb von Expressions auftauchen haben in CFML keine weitere Beteutung
 * und werden durch diese Methode einfach entfernt.
 * <br />
 * Beispiel:<br />
 * <code>arrayLen(#arr#)</code> und <code>arrayLen(arr)</code> sind identisch.
 * EBNF:<br />
 * <code>"#" checker "#";</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression sharp(ExprData data) throws TemplateException {
    if (!data.srcCode.forwardIfCurrent('#'))
        return null;
    Expression expr;
    comments(data);
    boolean old = data.allowLowerThan;
    data.allowLowerThan = true;
    expr = assignOp(data);
    data.allowLowerThan = old;
    comments(data);
    if (!data.srcCode.forwardIfCurrent('#'))
        throw new TemplateException(data.srcCode, "Syntax Error, Invalid Construct " + (data.srcCode.length() < 30 ? data.srcCode.toString() : ""));
    comments(data);
    return expr;
}
Also used : FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) TemplateException(lucee.runtime.exp.TemplateException)

Example 54 with TemplateException

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

the class AbstrCFMLScriptTransformer method validateAttributeName.

private final String validateAttributeName(String idOC, SourceCode cfml, ArrayList<String> args, TagLibTag tag, RefBoolean dynamic, StringBuffer sbType, boolean allowTwiceAttr) throws TemplateException {
    String idLC = idOC.toLowerCase();
    if (args.contains(idLC) && !allowTwiceAttr)
        throw new TemplateException(cfml, "you can't use the same attribute [" + idOC + "] twice");
    args.add(idLC);
    if (tag == null)
        return idOC;
    int typeDef = tag.getAttributeType();
    if ("attributecollection".equals(idLC)) {
        dynamic.setValue(tag.getAttribute(idLC, true) == null);
        sbType.append("struct");
    } else if (typeDef == TagLibTag.ATTRIBUTE_TYPE_FIXED || typeDef == TagLibTag.ATTRIBUTE_TYPE_MIXED) {
        TagLibTagAttr attr = tag.getAttribute(idLC, true);
        if (attr == null) {
            if (typeDef == TagLibTag.ATTRIBUTE_TYPE_FIXED) {
                String names = tag.getAttributeNames();
                if (StringUtil.isEmpty(names))
                    throw new TemplateException(cfml, "Attribute " + idOC + " is not allowed for tag " + tag.getFullName());
                throw new TemplateException(cfml, "Attribute " + idOC + " is not allowed for statement " + tag.getName(), "valid attribute names are [" + names + "]");
            }
            dynamic.setValue(true);
        } else {
            idOC = attr.getName();
            idLC = idOC.toLowerCase();
            sbType.append(attr.getType());
        // parseExpression[0]=attr.getRtexpr();
        }
    } else if (typeDef == TagLibTag.ATTRIBUTE_TYPE_DYNAMIC) {
        dynamic.setValue(true);
    }
    return idOC;
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) TemplateException(lucee.runtime.exp.TemplateException)

Example 55 with TemplateException

use of lucee.runtime.exp.TemplateException 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

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