Search in sources :

Example 11 with Position

use of lucee.transformer.Position in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method doStatement.

/**
 * Liest ein do Statement ein.
 * <br />
 * EBNF:<br />
 * <code>block spaces "while" spaces "(" spaces condition spaces ")";</code>
 * @return do Statement
 * @throws TemplateException
 */
private final DoWhile doStatement(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("do")) {
        id = null;
        if (!data.srcCode.isCurrent('{') && !data.srcCode.isCurrent(' ') && !data.srcCode.isCurrent('/')) {
            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("do", '{') && !data.srcCode.forwardIfCurrent("do ") && !data.srcCode.forwardIfCurrent("do", '/')) {
            data.srcCode.setPos(pos);
            return null;
        }
        data.srcCode.previous();
    }
    // if(!data.srcCode.forwardIfCurrent("do",'{') && !data.srcCode.forwardIfCurrent("do ") && !data.srcCode.forwardIfCurrent("do",'/'))
    // return null;
    Position line = data.srcCode.getPosition();
    Body body = new BodyBase(data.factory);
    // data.srcCode.previous();
    statement(data, body, CTX_DO_WHILE);
    comments(data);
    if (!data.srcCode.forwardIfCurrent("while", '('))
        throw new TemplateException(data.srcCode, "do statement must have a while at the end");
    DoWhile doWhile = new DoWhile(condition(data), body, line, data.srcCode.getPosition(), id);
    if (!data.srcCode.forwardIfCurrent(')'))
        throw new TemplateException(data.srcCode, "do statement must end with a [)]");
    return doWhile;
}
Also used : Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) DoWhile(lucee.transformer.bytecode.statement.DoWhile) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 12 with Position

use of lucee.transformer.Position 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)

Example 13 with Position

use of lucee.transformer.Position in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method _propertyStatement.

private final Tag _propertyStatement(ExprData data, Body parent) throws TemplateException {
    if (data.context != CTX_CFC || !data.srcCode.forwardIfCurrent("property "))
        return null;
    Position line = data.srcCode.getPosition();
    TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode, "property", data.config.getIdentification());
    Tag property = new TagOther(data.factory, line, null);
    addMetaData(data, property, IGNORE_LIST_PROPERTY);
    boolean hasName = false, hasType = false;
    int pos = data.srcCode.getPos();
    String tmp = variableDec(data, true);
    if (!StringUtil.isEmpty(tmp)) {
        if (tmp.indexOf('.') != -1) {
            property.addAttribute(new Attribute(false, "type", data.factory.createLitString(tmp), "string"));
            hasType = true;
        } else {
            data.srcCode.setPos(pos);
        }
    } else
        data.srcCode.setPos(pos);
    // folgend wird tlt extra nicht uebergeben, sonst findet pruefung statt
    Attribute[] attrs = attributes(property, tlt, data, SEMI, data.factory.NULL(), Boolean.FALSE, "name", true, NO_ATTR_SEP, false);
    checkSemiColonLineFeed(data, true, true, false);
    property.setTagLibTag(tlt);
    property.setScriptBase(true);
    Attribute attr;
    // first fill all regular attribute -> name="value"
    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;
            } else if (attr.getName().equalsIgnoreCase("type")) {
                hasType = true;
            }
            property.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) || !hasName)) {
                first = attr.getNameOC();
            } else // name
            if (second == null && !hasName && !hasType) {
                second = attr.getNameOC();
            } else // attr with no value
            {
                attr = new Attribute(true, attr.getName(), data.factory.EMPTY(), "string");
                property.addAttribute(attr);
            }
        }
    }
    if (first != null) {
        hasName = true;
        if (second != null) {
            hasType = true;
            property.addAttribute(new Attribute(false, "name", data.factory.createLitString(second), "string"));
            property.addAttribute(new Attribute(false, "type", data.factory.createLitString(first), "string"));
        } else {
            property.addAttribute(new Attribute(false, "name", data.factory.createLitString(first), "string"));
        }
    }
    if (!hasType) {
        property.addAttribute(new Attribute(false, "type", data.factory.createLitString("any"), "string"));
    }
    if (!hasName)
        throw new TemplateException(data.srcCode, "missing name declaration for property");
    /*Tag property=new TagBase(line);
		property.setTagLibTag(tlt);
		property.addAttribute(new Attribute(false,"name",data.factory.createLitString(name),"string"));
		property.addAttribute(new Attribute(false,"type",data.factory.createLitString(type),"string"));
		*/
    property.setEnd(data.srcCode.getPosition());
    return property;
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) Position(lucee.transformer.Position) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) TemplateException(lucee.runtime.exp.TemplateException) TagOther(lucee.transformer.bytecode.statement.tag.TagOther) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag)

Example 14 with Position

use of lucee.transformer.Position in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method whileStatement.

/**
 * Liest ein while Statement ein.
 * <br />
 * EBNF:<br />
 * <code>spaces condition spaces ")" spaces block;</code>
 * @return while Statement
 * @throws TemplateException
 */
private final While whileStatement(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("while")) {
        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("while", '(')) {
            data.srcCode.setPos(pos);
            return null;
        }
    }
    Position line = data.srcCode.getPosition();
    Body body = new BodyBase(data.factory);
    While whil = new While(condition(data), body, line, null, id);
    if (!data.srcCode.forwardIfCurrent(')'))
        throw new TemplateException(data.srcCode, "while statement must end with a [)]");
    statement(data, body, CTX_WHILE);
    whil.setEnd(data.srcCode.getPosition());
    return whil;
}
Also used : Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) DoWhile(lucee.transformer.bytecode.statement.DoWhile) While(lucee.transformer.bytecode.statement.While) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase)

Example 15 with Position

use of lucee.transformer.Position in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method elseifStatement.

/**
 * Liest ein else if Statement ein.
 * <br />
 * EBNF:<br />
 * <code>spaces condition spaces ")" spaces block;</code>
 * @return else if Statement
 * @throws TemplateException
 */
private final boolean elseifStatement(ExprData data, Condition cont) throws TemplateException {
    int pos = data.srcCode.getPos();
    if (!data.srcCode.forwardIfCurrent("else"))
        return false;
    comments(data);
    if (!data.srcCode.forwardIfCurrent("if", '(')) {
        data.srcCode.setPos(pos);
        return false;
    }
    Position line = data.srcCode.getPosition();
    Body body = new BodyBase(data.factory);
    Pair pair = cont.addElseIf(condition(data), body, line, null);
    if (!data.srcCode.forwardIfCurrent(')'))
        throw new TemplateException(data.srcCode, "else if statement must end with a [)]");
    // ex block
    statement(data, body, CTX_ELSE_IF);
    pair.end = data.srcCode.getPosition();
    return true;
}
Also used : 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) Pair(lucee.transformer.bytecode.statement.Condition.Pair)

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