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;
}
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;
}
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()]);
}
Aggregations