use of lucee.transformer.Position 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.Position in project Lucee by lucee.
the class ExpressionUtil method writeOutSilent.
/**
* write out expression without LNT
* @param value
* @param bc
* @param mode
* @throws TransformerException
*/
public static void writeOutSilent(Expression value, BytecodeContext bc, int mode) throws TransformerException {
Position start = value.getStart();
Position end = value.getEnd();
value.setStart(null);
value.setEnd(null);
value.writeOut(bc, mode);
value.setStart(start);
value.setEnd(end);
}
use of lucee.transformer.Position in project Lucee by lucee.
the class AbstrCFMLExprTransformer method number.
/**
* Transfomiert einen numerische Wert.
* Die Laenge des numerischen Wertes interessiert nicht zu uebersetzungszeit,
* ein "Overflow" fuehrt zu einem Laufzeitfehler.
* Da die zu erstellende CFXD, bzw. dieser Transfomer, keine Vorwegnahme des Laufzeitsystems vornimmt.
* <br />
* EBNF:<br />
* <code>["+"|"-"] digit {digit} {"." digit {digit}};</code>
* @return CFXD Element
* @throws TemplateException
*/
private LitDouble number(ExprData data) throws TemplateException {
// check first character is a number literal representation
if (!(data.srcCode.isCurrentBetween('0', '9') || data.srcCode.isCurrent('.')))
return null;
Position line = data.srcCode.getPosition();
StringBuffer rtn = new StringBuffer();
// get digit on the left site of the dot
if (data.srcCode.isCurrent('.'))
rtn.append('0');
else
rtn.append(digit(data));
// read dot if exist
if (data.srcCode.forwardIfCurrent('.')) {
rtn.append('.');
String rightSite = digit(data);
if (rightSite.length() > 0 && data.srcCode.forwardIfCurrent('e')) {
Boolean expOp = null;
if (data.srcCode.forwardIfCurrent('+'))
expOp = Boolean.TRUE;
else if (data.srcCode.forwardIfCurrent('-'))
expOp = Boolean.FALSE;
if (data.srcCode.isCurrentBetween('0', '9')) {
if (expOp == Boolean.FALSE)
rightSite += "e-";
else if (expOp == Boolean.TRUE)
rightSite += "e+";
else
rightSite += "e";
rightSite += digit(data);
} else {
if (expOp != null)
data.srcCode.previous();
data.srcCode.previous();
}
}
// read right side of the dot
if (rightSite.length() == 0)
// throw new TemplateException(cfml, "Number can't end with [.]"); // DIFF 23
rightSite = "0";
rtn.append(rightSite);
} else // scientific notation
if (data.srcCode.forwardIfCurrent('e')) {
Boolean expOp = null;
if (data.srcCode.forwardIfCurrent('+'))
expOp = Boolean.TRUE;
else if (data.srcCode.forwardIfCurrent('-'))
expOp = Boolean.FALSE;
if (data.srcCode.isCurrentBetween('0', '9')) {
String rightSite = "e";
if (expOp == Boolean.FALSE)
rightSite += "-";
else if (expOp == Boolean.TRUE)
rightSite += "+";
rightSite += digit(data);
rtn.append(rightSite);
} else {
if (expOp != null)
data.srcCode.previous();
data.srcCode.previous();
}
}
comments(data);
try {
return data.factory.createLitDouble(Caster.toDoubleValue(rtn.toString()), line, data.srcCode.getPosition());
} catch (CasterException e) {
throw new TemplateException(data.srcCode, e.getMessage());
}
}
use of lucee.transformer.Position in project Lucee by lucee.
the class AbstrCFMLExprTransformer method simple.
/**
* @param data
* @return parsed Element
* @throws TemplateException
*/
private Expression simple(ExprData data, String[] breakConditions) throws TemplateException {
StringBuffer sb = new StringBuffer();
Position line = data.srcCode.getPosition();
outer: while (data.srcCode.isValidIndex()) {
for (int i = 0; i < breakConditions.length; i++) {
if (data.srcCode.isCurrent(breakConditions[i]))
break outer;
}
if (data.srcCode.isCurrent('"') || data.srcCode.isCurrent('#') || data.srcCode.isCurrent('\'')) {
throw new TemplateException(data.srcCode, "simple attribute value can't contain [" + data.srcCode.getCurrent() + "]");
}
sb.append(data.srcCode.getCurrent());
data.srcCode.next();
}
comments(data);
return data.factory.createLitString(sb.toString(), line, data.srcCode.getPosition());
}
use of lucee.transformer.Position in project Lucee by lucee.
the class AbstrCFMLExprTransformer method json.
protected Expression json(ExprData data, FunctionLibFunction flf, char start, char end) throws TemplateException {
if (!data.srcCode.forwardIfCurrent(start))
return null;
Position line = data.srcCode.getPosition();
data.srcCode.removeSpace();
// [:|=]
if (data.srcCode.forwardIfCurrent(':', ']') || data.srcCode.forwardIfCurrent('=', ']')) {
flf = flf.getFunctionLib().getFunction("_literalOrderedStruct");
BIF bif = new BIF(data.factory, data.settings, flf);
bif.setArgType(flf.getArgType());
try {
bif.setClassDefinition(flf.getFunctionClassDefinition());
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw new PageRuntimeException(t);
}
bif.setReturnType(flf.getReturnTypeAsString());
data.ep.add(flf, bif, data.srcCode);
Variable var = data.factory.createVariable(line, data.srcCode.getPosition());
var.addMember(bif);
return var;
}
BIF bif = new BIF(data.factory, data.settings, flf);
bif.setArgType(flf.getArgType());
try {
bif.setClassDefinition(flf.getFunctionClassDefinition());
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw new PageRuntimeException(t);
}
bif.setReturnType(flf.getReturnTypeAsString());
do {
comments(data);
if (data.srcCode.isCurrent(end))
break;
bif.addArgument(functionArgument(data, data.settings.dotNotationUpper));
comments(data);
} while (data.srcCode.forwardIfCurrent(','));
comments(data);
if (!data.srcCode.forwardIfCurrent(end))
throw new TemplateException(data.srcCode, "Invalid Syntax Closing [" + end + "] not found");
comments(data);
if (flf.hasTteClass()) {
FunctionLibFunction tmp = flf.getEvaluator().pre(bif, flf);
if (tmp != null && tmp != flf) {
bif.setFlf(flf = tmp);
bif.setArgType(flf.getArgType());
try {
bif.setClassDefinition(flf.getFunctionClassDefinition());
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw new PageRuntimeException(t);
}
bif.setReturnType(flf.getReturnTypeAsString());
}
}
data.ep.add(flf, bif, data.srcCode);
Variable var = data.factory.createVariable(line, data.srcCode.getPosition());
var.addMember(bif);
return var;
}
Aggregations