Search in sources :

Example 1 with Identifier

use of lucee.transformer.bytecode.literal.Identifier in project Lucee by lucee.

the class AbstrCFMLExprTransformer method dynamic.

/**
 * Liest den folgenden idetifier ein und prueft ob dieser ein boolscher Wert ist.
 * Im Gegensatz zu CFMX wird auch "yes" und "no" als bolscher <wert akzeptiert,
 * was bei CFMX nur beim Umwandeln einer Zeichenkette zu einem boolschen Wert der Fall ist.<br />
 * Wenn es sich um keinen bolschen Wert handelt wird der folgende Wert eingelesen mit seiner ganzen Hirarchie.
 * <br />
 * EBNF:<br />
 * <code>"true" | "false" | "yes" | "no" | startElement {("." identifier | "[" structElement "]" )[function] };</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression dynamic(ExprData data) throws TemplateException {
    // Die Implementation weicht ein wenig von der Grammatik ab,
    // aber nicht in der Logik sondern rein wie es umgesetzt wurde.
    // get First Element of the Variable
    Position line = data.srcCode.getPosition();
    Identifier id = identifier(data, false, true);
    if (id == null) {
        if (!data.srcCode.forwardIfCurrent('('))
            return null;
        comments(data);
        Expression expr = assignOp(data);
        if (!data.srcCode.forwardIfCurrent(')'))
            throw new TemplateException(data.srcCode, "Invalid Syntax Closing [)] not found");
        comments(data);
        // subDynamic(expr);
        return expr;
    }
    Variable var;
    comments(data);
    // Boolean constant
    if (id.getString().equalsIgnoreCase("TRUE")) {
        // || name.equals("YES"))	{
        comments(data);
        return id.getFactory().createLitBoolean(true, line, data.srcCode.getPosition());
    } else if (id.getString().equalsIgnoreCase("FALSE")) {
        // || name.equals("NO"))	{
        comments(data);
        return id.getFactory().createLitBoolean(false, line, data.srcCode.getPosition());
    } else if ((data.srcCode.getDialect() != CFMLEngine.DIALECT_CFML || data.config.getFullNullSupport()) && id.getString().equalsIgnoreCase("NULL")) {
        comments(data);
        return id.getFactory().createNull(line, data.srcCode.getPosition());
    }
    // Extract Scope from the Variable
    var = startElement(data, id, line);
    var.setStart(line);
    var.setEnd(data.srcCode.getPosition());
    return var;
}
Also used : Identifier(lucee.transformer.bytecode.literal.Identifier) 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)

Example 2 with Identifier

use of lucee.transformer.bytecode.literal.Identifier in project Lucee by lucee.

the class AbstrCFMLExprTransformer method scope.

/**
 * Liest einen CFML Scope aus,
 * falls der folgende identifier keinem Scope entspricht,
 * gibt die Variable null zurueck.
 * <br />
 * EBNF:<br />
 * <code>"variable" | "cgi" | "url" | "form" | "session" | "application" | "arguments" | "cookie" | " client";</code>
 * @param id String identifier,
 * wird aus Optimierungszwechen nicht innerhalb dieser Funktion ausgelsen.
 * @return CFXD Variable Element oder null
 * @throws TemplateException
 */
private Variable scope(ExprData data, Identifier id, Position line) throws TemplateException {
    String idStr = id.getUpper();
    if (idStr.equals("ARGUMENTS"))
        return data.factory.createVariable(Scope.SCOPE_ARGUMENTS, line, data.srcCode.getPosition());
    else if (idStr.equals("LOCAL"))
        return data.factory.createVariable(Scope.SCOPE_LOCAL, line, data.srcCode.getPosition());
    else if (idStr.equals("VAR")) {
        Identifier _id = identifier(data, false, true);
        if (_id != null) {
            comments(data);
            Variable local = data.factory.createVariable(ScopeSupport.SCOPE_VAR, line, data.srcCode.getPosition());
            if (!"LOCAL".equalsIgnoreCase(_id.getString()))
                local.addMember(data.factory.createDataMember(_id));
            else {
                local.ignoredFirstMember(true);
            }
            return local;
        }
    } else if (idStr.equals("VARIABLES"))
        return data.factory.createVariable(Scope.SCOPE_VARIABLES, line, data.srcCode.getPosition());
    else if (idStr.equals("REQUEST"))
        return data.factory.createVariable(Scope.SCOPE_REQUEST, line, data.srcCode.getPosition());
    else if (idStr.equals("SERVER"))
        return data.factory.createVariable(Scope.SCOPE_SERVER, line, data.srcCode.getPosition());
    if (data.settings.ignoreScopes)
        return null;
    if (idStr.equals("CGI"))
        return data.factory.createVariable(Scope.SCOPE_CGI, line, data.srcCode.getPosition());
    else if (idStr.equals("SESSION"))
        return data.factory.createVariable(Scope.SCOPE_SESSION, line, data.srcCode.getPosition());
    else if (idStr.equals("APPLICATION"))
        return data.factory.createVariable(Scope.SCOPE_APPLICATION, line, data.srcCode.getPosition());
    else if (idStr.equals("FORM"))
        return data.factory.createVariable(Scope.SCOPE_FORM, line, data.srcCode.getPosition());
    else if (idStr.equals("URL"))
        return data.factory.createVariable(Scope.SCOPE_URL, line, data.srcCode.getPosition());
    else if (idStr.equals("CLIENT"))
        return data.factory.createVariable(Scope.SCOPE_CLIENT, line, data.srcCode.getPosition());
    else if (idStr.equals("COOKIE"))
        return data.factory.createVariable(Scope.SCOPE_COOKIE, line, data.srcCode.getPosition());
    else if (idStr.equals("CLUSTER"))
        return data.factory.createVariable(Scope.SCOPE_CLUSTER, line, data.srcCode.getPosition());
    return null;
}
Also used : Identifier(lucee.transformer.bytecode.literal.Identifier) OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString)

Example 3 with Identifier

use of lucee.transformer.bytecode.literal.Identifier in project Lucee by lucee.

the class VariableString method variableToStringArray.

public static String[] variableToStringArray(Variable var, boolean rawIfPossible) throws TransformerException {
    List<Member> members = var.getMembers();
    List<String> arr = new ArrayList<String>();
    if (var.getScope() != Scope.SCOPE_UNDEFINED)
        arr.add(ScopeFactory.toStringScope(var.getScope(), "undefined"));
    Iterator<Member> it = members.iterator();
    DataMember dm;
    Expression n;
    while (it.hasNext()) {
        Object o = it.next();
        if (!(o instanceof DataMember))
            throw new TransformerException("can't translate Variable to a String", var.getStart());
        dm = (DataMember) o;
        n = dm.getName();
        if (n instanceof Literal) {
            if (rawIfPossible && n instanceof Identifier) {
                arr.add(((Identifier) n).getRaw());
            } else {
                arr.add(((Literal) n).getString());
            }
        } else
            throw new TransformerException("argument name must be a constant value", var.getStart());
    }
    return arr.toArray(new String[arr.size()]);
}
Also used : Identifier(lucee.transformer.bytecode.literal.Identifier) Expression(lucee.transformer.expression.Expression) Literal(lucee.transformer.expression.literal.Literal) ArrayList(java.util.ArrayList) DataMember(lucee.transformer.expression.var.DataMember) ExprString(lucee.transformer.expression.ExprString) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member) TransformerException(lucee.transformer.TransformerException)

Aggregations

Identifier (lucee.transformer.bytecode.literal.Identifier)3 OpVariable (lucee.transformer.bytecode.op.OpVariable)2 ExprString (lucee.transformer.expression.ExprString)2 Expression (lucee.transformer.expression.Expression)2 Variable (lucee.transformer.expression.var.Variable)2 ArrayList (java.util.ArrayList)1 TemplateException (lucee.runtime.exp.TemplateException)1 Position (lucee.transformer.Position)1 TransformerException (lucee.transformer.TransformerException)1 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)1 LitString (lucee.transformer.expression.literal.LitString)1 Literal (lucee.transformer.expression.literal.Literal)1 DataMember (lucee.transformer.expression.var.DataMember)1 Member (lucee.transformer.expression.var.Member)1