use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLExprTransformer method staticScope.
private Expression staticScope(ExprData data, Expression expr) throws TemplateException {
if (data.srcCode.forwardIfCurrent("::")) {
if (!(expr instanceof Variable))
throw new TemplateException(data.srcCode, "invalid syntax before [::]");
Variable old = (Variable) expr;
// set back to read again as a component path
data.srcCode.setPos(old.getStart().pos);
// now we read the component path
ExprString componentPath = readComponentPath(data);
if (!data.srcCode.forwardIfCurrent("::"))
throw new TemplateException(data.srcCode, "invalid syntax before [::]" + data.srcCode.getCurrent());
comments(data);
BIF bif = null;
if (componentPath instanceof LitString) {
LitString ls = (LitString) componentPath;
if ("super".equalsIgnoreCase(ls.getString())) {
bif = ASMUtil.createBif(data, GET_SUPER_STATIC_SCOPE);
}
}
// now we generate a _getStaticScope function call with that path
if (bif == null) {
bif = ASMUtil.createBif(data, GET_STATIC_SCOPE);
bif.addArgument(new Argument(componentPath, "string"));
}
Variable var = data.factory.createVariable(old.getStart(), data.srcCode.getPosition());
var.addMember(bif);
// now we are reading what is coming after ":::"
Expression sd = subDynamic(data, var, false, true);
return sd;
}
return null;
}
use of lucee.runtime.exp.TemplateException 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;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLExprTransformer method string.
/*private Expression variable(Data data) throws TemplateException {
Expression expr=null;
// Dynamic
if((expr=dynamic(data))!=null) {
expr = subDynamic(data,expr);
data.mode=DYNAMIC;
return expr;
}
return null;
}*/
/**
* Transfomiert einen lierale Zeichenkette.
* <br />
* EBNF:<br />
* <code>("'" {"##"|"''"|"#" impOp "#"| ?-"#"-"'" } "'") |
* (""" {"##"|""""|"#" impOp "#"| ?-"#"-""" } """);</code>
* @param data
* @return CFXD Element
* @throws TemplateException
*/
protected Expression string(ExprData data) throws TemplateException {
// check starting character for a string literal
if (!data.srcCode.isCurrent('"') && !data.srcCode.isCurrent('\''))
return null;
Position line = data.srcCode.getPosition();
// Init Parameter
char quoter = data.srcCode.getCurrentLower();
StringBuilder str = new StringBuilder();
Expression expr = null;
while (data.srcCode.hasNext()) {
data.srcCode.next();
// check sharp
if (data.srcCode.isCurrent('#')) {
// Ecaped sharp
if (data.srcCode.isNext('#')) {
data.srcCode.next();
str.append('#');
} else // get Content of sharp
{
data.srcCode.next();
comments(data);
Expression inner = assignOp(data);
comments(data);
if (!data.srcCode.isCurrent('#'))
throw new TemplateException(data.srcCode, "Invalid Syntax Closing [#] not found");
ExprString exprStr = null;
if (str.length() != 0) {
exprStr = data.factory.createLitString(str.toString(), line, data.srcCode.getPosition());
if (expr != null) {
expr = data.factory.opString(expr, exprStr);
} else
expr = exprStr;
str = new StringBuilder();
}
if (expr == null) {
expr = inner;
} else {
expr = data.factory.opString(expr, inner);
}
}
} else // check quoter
if (data.srcCode.isCurrent(quoter)) {
// Ecaped sharp
if (data.srcCode.isNext(quoter)) {
data.srcCode.next();
str.append(quoter);
} else // finsish
{
break;
}
} else // all other character
{
str.append(data.srcCode.getCurrent());
}
}
if (!data.srcCode.forwardIfCurrent(quoter))
throw new TemplateException(data.srcCode, "Invalid Syntax Closing [" + quoter + "] not found");
if (expr == null)
expr = data.factory.createLitString(str.toString(), line, data.srcCode.getPosition());
else if (str.length() != 0) {
expr = data.factory.opString(expr, data.factory.createLitString(str.toString(), line, data.srcCode.getPosition()));
}
comments(data);
if (expr instanceof Variable) {
Variable var = (Variable) expr;
var.fromHash(true);
}
return expr;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class SimpleExprTransformer method string.
/**
* Liest den String ein
* @return Element
* @throws TemplateException
*/
public Expression string(Factory f, SourceCode cfml) throws TemplateException {
cfml.removeSpace();
char quoter = cfml.getCurrentLower();
if (quoter != '"' && quoter != '\'')
return null;
StringBuffer str = new StringBuffer();
boolean insideSpecial = false;
Position line = cfml.getPosition();
while (cfml.hasNext()) {
cfml.next();
// check special
if (cfml.isCurrent(specialChar)) {
insideSpecial = !insideSpecial;
str.append(specialChar);
} else // check quoter
if (!insideSpecial && cfml.isCurrent(quoter)) {
// Ecaped sharp
if (cfml.isNext(quoter)) {
cfml.next();
str.append(quoter);
} else // finsish
{
break;
}
} else // all other character
{
str.append(cfml.getCurrent());
}
}
if (!cfml.forwardIfCurrent(quoter))
throw new TemplateException(cfml, "Invalid Syntax Closing [" + quoter + "] not found");
LitString rtn = f.createLitString(str.toString(), line, cfml.getPosition());
cfml.removeSpace();
return rtn;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class SimpleExprTransformer method simple.
/**
* Liest ein
* @return Element
* @throws TemplateException
*/
public Expression simple(Factory f, SourceCode cfml) throws TemplateException {
StringBuffer sb = new StringBuffer();
Position line = cfml.getPosition();
while (cfml.isValidIndex()) {
if (cfml.isCurrent(' ') || cfml.isCurrent('>') || cfml.isCurrent("/>"))
break;
else if (cfml.isCurrent('"') || cfml.isCurrent('#') || cfml.isCurrent('\'')) {
throw new TemplateException(cfml, "simple attribute value can't contain [" + cfml.getCurrent() + "]");
} else
sb.append(cfml.getCurrent());
cfml.next();
}
cfml.removeSpace();
return f.createLitString(sb.toString(), line, cfml.getPosition());
}
Aggregations