Search in sources :

Example 1 with TagParam

use of lucee.transformer.bytecode.statement.tag.TagParam in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method _paramStatement.

private Tag _paramStatement(ExprData data, Body parent) throws TemplateException {
    if (!data.srcCode.forwardIfCurrent("param "))
        return null;
    Position line = data.srcCode.getPosition();
    TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode, "param", data.config.getIdentification());
    TagParam param = new TagParam(data.factory, line, null);
    // type
    boolean hasType = false;
    boolean hasName = false;
    int pos = data.srcCode.getPos();
    // first 2 arguments can be type/name directly
    String tmp = variableDec(data, true);
    do {
        if (!StringUtil.isEmpty(tmp)) {
            TagLibTagAttr attr = tlt.getAttribute(tmp.toLowerCase(), true);
            // name is not a defined attribute
            if (attr == null) {
                comments(data);
                // it could be a name followed by default value
                if (data.srcCode.forwardIfCurrent('=')) {
                    comments(data);
                    Expression v = attributeValue(data, true);
                    param.addAttribute(new Attribute(false, "name", data.factory.createLitString(tmp), "string"));
                    param.addAttribute(new Attribute(false, "default", v, "string"));
                    hasName = true;
                    // if we had a value this was already name
                    break;
                }
                // can be type or name
                int pos2 = data.srcCode.getPos();
                // first could be type, followed by name
                comments(data);
                String tmp2 = variableDec(data, true);
                if (!StringUtil.isEmpty(tmp2)) {
                    attr = tlt.getAttribute(tmp2.toLowerCase(), true);
                    if (attr == null) {
                        param.addAttribute(new Attribute(false, "name", data.factory.createLitString(tmp2), "string"));
                        param.addAttribute(new Attribute(false, "type", data.factory.createLitString(tmp), "string"));
                        if (data.srcCode.forwardIfCurrent('=')) {
                            Expression v = attributeValue(data, true);
                            param.addAttribute(new Attribute(false, "default", v, "string"));
                        }
                        hasName = true;
                        hasType = true;
                        break;
                    }
                }
                param.addAttribute(new Attribute(false, "name", data.factory.createLitString(tmp), "string"));
                data.srcCode.setPos(pos2);
                hasName = true;
            } else
                data.srcCode.setPos(pos);
        } else
            data.srcCode.setPos(pos);
    } while (false);
    // folgend wird tlt extra nicht uebergeben, sonst findet pruefung statt
    Attribute[] attrs = attributes(param, tlt, data, SEMI, data.factory.NULL(), Boolean.TRUE, "name", true, ',', false);
    checkSemiColonLineFeed(data, true, true, true);
    param.setTagLibTag(tlt);
    param.setScriptBase(true);
    Attribute attr;
    // first fill all regular attribute -> name="value"
    boolean hasDynamic = false;
    for (int i = attrs.length - 1; i >= 0; i--) {
        attr = attrs[i];
        if (!attr.getValue().equals(data.factory.NULL())) {
            if (attr.getName().equalsIgnoreCase("name")) {
                hasName = true;
                param.addAttribute(attr);
            } else if (attr.getName().equalsIgnoreCase("type")) {
                hasType = true;
                param.addAttribute(attr);
            } else if (attr.isDynamicType()) {
                hasName = true;
                if (hasDynamic)
                    throw attrNotSupported(data.srcCode, tlt, attr.getName());
                hasDynamic = true;
                param.addAttribute(new Attribute(false, "name", data.factory.createLitString(attr.getName()), "string"));
                param.addAttribute(new Attribute(false, "default", attr.getValue(), "any"));
            } else
                param.addAttribute(attr);
        }
    }
    // now fill name named attributes -> attr1 attr2
    String first = null, second = null;
    for (int i = 0; i < attrs.length; i++) {
        attr = attrs[i];
        if (attr.getValue().equals(data.factory.NULL())) {
            // type
            if (first == null && (!hasName || !hasType)) {
                first = attr.getName();
            } else // name
            if (second == null && !hasName && !hasType) {
                second = attr.getName();
            } else // attr with no value
            {
                attr = new Attribute(true, attr.getName(), data.factory.EMPTY(), "string");
                param.addAttribute(attr);
            }
        }
    }
    if (first != null) {
        if (second != null) {
            hasName = true;
            hasType = true;
            if (hasDynamic)
                throw attrNotSupported(data.srcCode, tlt, first);
            hasDynamic = true;
            param.addAttribute(new Attribute(false, "name", data.factory.createLitString(second), "string"));
            param.addAttribute(new Attribute(false, "type", data.factory.createLitString(first), "string"));
        } else {
            param.addAttribute(new Attribute(false, hasName ? "type" : "name", data.factory.createLitString(first), "string"));
            hasName = true;
        }
    }
    if (!hasName)
        throw new TemplateException(data.srcCode, "missing name declaration for param");
    param.setEnd(data.srcCode.getPosition());
    return param;
}
Also used : TagLibTagAttr(lucee.transformer.library.tag.TagLibTagAttr) TagLibTag(lucee.transformer.library.tag.TagLibTag) TagParam(lucee.transformer.bytecode.statement.tag.TagParam) Position(lucee.transformer.Position) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) TemplateException(lucee.runtime.exp.TemplateException)

Aggregations

TemplateException (lucee.runtime.exp.TemplateException)1 Position (lucee.transformer.Position)1 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)1 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)1 TagParam (lucee.transformer.bytecode.statement.tag.TagParam)1 Expression (lucee.transformer.expression.Expression)1 TagLibTag (lucee.transformer.library.tag.TagLibTag)1 TagLibTagAttr (lucee.transformer.library.tag.TagLibTagAttr)1