use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class JavaScriptTransformer method transform.
@Override
public Body transform(Factory factory, Root root, EvaluatorPool ep, TagLib[][] tlibs, FunctionLib[] flibs, String surroundingTagName, TagLibTag[] scriptTags, SourceCode cfml, TransfomerSettings settings) throws TemplateException {
StringBuilder sb = new StringBuilder();
// MUST add again int startline=cfml.getLine();
while (!cfml.isAfterLast() && !cfml.isCurrent("</", surroundingTagName)) {
sb.append(cfml.getCurrent());
cfml.next();
}
// int endline=cfml.getLine();
if (cfml.isAfterLast())
// TODO better error message
throw new TemplateException(cfml, "missing end tag");
if (true)
throw new RuntimeException("not implemented");
try {
// MUST add again CompilationUnit cu = JavaParser.parse(bais);
// MUST add again DataBag db = new DataBag();
ScriptBody body = new ScriptBody(factory);
return body;
// MUST add again new JavaParserVisitor(body,start,end).visit(cu, db);
} catch (Exception e) {
throw new TemplateException(cfml, e);
}
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLExprTransformer method getFunctionMemberAttrs.
private int getFunctionMemberAttrs(ExprData data, ExprString name, boolean checkLibrary, Func fm, FunctionLibFunction flf) throws TemplateException {
// Function Attributes
ArrayList<FunctionLibFunctionArg> arrFuncLibAtt = null;
// int libLen = 0;
if (checkLibrary) {
arrFuncLibAtt = flf.getArg();
// libLen = arrFuncLibAtt.size();
}
int count = 0;
do {
data.srcCode.next();
comments(data);
// finish
if (count == 0 && data.srcCode.isCurrent(')'))
break;
// Argument arg;
if (checkLibrary && flf.getArgType() != FunctionLibFunction.ARG_DYNAMIC) {
// current attribues from library
String _type;
try {
_type = arrFuncLibAtt.get(count).getTypeAsString();
} catch (IndexOutOfBoundsException e) {
_type = null;
}
fm.addArgument(functionArgument(data, _type, false));
} else {
fm.addArgument(functionArgument(data, false));
}
comments(data);
count++;
if (data.srcCode.isCurrent(')'))
break;
} while (data.srcCode.isCurrent(','));
if (!data.srcCode.forwardIfCurrent(')')) {
if (name != null) {
throw new TemplateException(data.srcCode, "Invalid Syntax Closing [)] for function [" + (flf != null ? flf.getName() : ASMUtil.display(name)) + "] not found");
}
throw new TemplateException(data.srcCode, "Invalid Syntax Closing [)] not found");
}
return count;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLExprTransformer method sharp.
/**
* Sharps (#) die innerhalb von Expressions auftauchen haben in CFML keine weitere Beteutung
* und werden durch diese Methode einfach entfernt.
* <br />
* Beispiel:<br />
* <code>arrayLen(#arr#)</code> und <code>arrayLen(arr)</code> sind identisch.
* EBNF:<br />
* <code>"#" checker "#";</code>
* @return CFXD Element
* @throws TemplateException
*/
private Expression sharp(ExprData data) throws TemplateException {
if (!data.srcCode.forwardIfCurrent('#'))
return null;
Expression expr;
comments(data);
boolean old = data.allowLowerThan;
data.allowLowerThan = true;
expr = assignOp(data);
data.allowLowerThan = old;
comments(data);
if (!data.srcCode.forwardIfCurrent('#'))
throw new TemplateException(data.srcCode, "Syntax Error, Invalid Construct " + (data.srcCode.length() < 30 ? data.srcCode.toString() : ""));
comments(data);
return expr;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method validateAttributeName.
private final String validateAttributeName(String idOC, SourceCode cfml, ArrayList<String> args, TagLibTag tag, RefBoolean dynamic, StringBuffer sbType, boolean allowTwiceAttr) throws TemplateException {
String idLC = idOC.toLowerCase();
if (args.contains(idLC) && !allowTwiceAttr)
throw new TemplateException(cfml, "you can't use the same attribute [" + idOC + "] twice");
args.add(idLC);
if (tag == null)
return idOC;
int typeDef = tag.getAttributeType();
if ("attributecollection".equals(idLC)) {
dynamic.setValue(tag.getAttribute(idLC, true) == null);
sbType.append("struct");
} else if (typeDef == TagLibTag.ATTRIBUTE_TYPE_FIXED || typeDef == TagLibTag.ATTRIBUTE_TYPE_MIXED) {
TagLibTagAttr attr = tag.getAttribute(idLC, true);
if (attr == null) {
if (typeDef == TagLibTag.ATTRIBUTE_TYPE_FIXED) {
String names = tag.getAttributeNames();
if (StringUtil.isEmpty(names))
throw new TemplateException(cfml, "Attribute " + idOC + " is not allowed for tag " + tag.getFullName());
throw new TemplateException(cfml, "Attribute " + idOC + " is not allowed for statement " + tag.getName(), "valid attribute names are [" + names + "]");
}
dynamic.setValue(true);
} else {
idOC = attr.getName();
idLC = idOC.toLowerCase();
sbType.append(attr.getType());
// parseExpression[0]=attr.getRtexpr();
}
} else if (typeDef == TagLibTag.ATTRIBUTE_TYPE_DYNAMIC) {
dynamic.setValue(true);
}
return idOC;
}
use of lucee.runtime.exp.TemplateException in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method ifStatement.
/**
* Liest ein if Statement ein.
* <br />
* EBNF:<br />
* <code>spaces condition spaces ")" spaces block {"else if" spaces "(" elseifStatement spaces }
* [("else" spaces "(" | "else ") elseStatement spaces];</code>
* @return if Statement
* @throws TemplateException
*/
private final Statement ifStatement(ExprData data) throws TemplateException {
if (!data.srcCode.forwardIfCurrent("if", '('))
return null;
Position line = data.srcCode.getPosition();
Body body = new BodyBase(data.factory);
Condition cont = new Condition(data.factory, condition(data), body, line, null);
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "if statement must end with a [)]");
// ex block
statement(data, body, CTX_IF);
// else if
comments(data);
while (elseifStatement(data, cont)) {
comments(data);
}
// else
if (elseStatement(data, cont)) {
comments(data);
}
cont.setEnd(data.srcCode.getPosition());
return cont;
}
Aggregations