use of lucee.transformer.bytecode.BodyBase in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method __singleAttrStatement.
private final Statement __singleAttrStatement(Body parent, ExprData data, TagLibTag tlt, boolean allowTwiceAttr) throws TemplateException {
String tagName = tlt.getName();
if (data.srcCode.forwardIfCurrent(tagName)) {
if (!data.srcCode.isCurrent(' ') && !data.srcCode.isCurrent(';')) {
data.srcCode.setPos(data.srcCode.getPos() - tagName.length());
return null;
}
} else
return null;
int pos = data.srcCode.getPos() - tagName.length();
Position line = data.srcCode.getPosition();
// TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode,tagName.equals("pageencoding")?"processingdirective":tagName);
Tag tag = getTag(data, parent, tlt, line, null);
tag.setScriptBase(true);
tag.setTagLibTag(tlt);
comments(data);
// attribute
TagLibTagAttr attr = tlt.getScript().getSingleAttr();
String attrName = null;
Expression attrValue = null;
short attrType = ATTR_TYPE_NONE;
if (attr != null) {
attrType = attr.getScriptSupport();
char c = data.srcCode.getCurrent();
if (ATTR_TYPE_REQUIRED == attrType || (!data.srcCode.isCurrent(';') && ATTR_TYPE_OPTIONAL == attrType)) {
if (data.srcCode.isCurrent('{')) {
// this can be only a json string
int p = data.srcCode.getPos();
try {
attrValue = isSimpleValue(attr.getType()) ? null : json(data, JSON_STRUCT, '{', '}');
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
data.srcCode.setPos(p);
}
} else
attrValue = attributeValue(data, tlt.getScript().getRtexpr());
if (attrValue != null && isOperator(c)) {
data.srcCode.setPos(pos);
return null;
}
}
}
if (attrValue != null) {
attrName = attr.getName();
TagLibTagAttr tlta = tlt.getAttribute(attr.getName(), true);
tag.addAttribute(new Attribute(false, attrName, CastOther.toExpression(attrValue, tlta.getType()), tlta.getType()));
} else if (ATTR_TYPE_REQUIRED == attrType) {
data.srcCode.setPos(pos);
return null;
}
// body
if (tlt.getHasBody()) {
Body body = new BodyBase(data.factory);
boolean wasSemiColon = statement(data, body, tlt.getScript().getContext());
if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
tag.setBody(body);
} else
checkSemiColonLineFeed(data, true, true, true);
if (tlt.hasTTE())
data.ep.add(tlt, tag, data.flibs, data.srcCode);
if (!StringUtil.isEmpty(attrName))
validateAttributeName(attrName, data.srcCode, new ArrayList<String>(), tlt, new RefBooleanImpl(false), new StringBuffer(), allowTwiceAttr);
tag.setEnd(data.srcCode.getPosition());
eval(tlt, data, tag);
return tag;
}
use of lucee.transformer.bytecode.BodyBase in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method cftagStatement.
private Statement cftagStatement(ExprData data, Body parent) throws TemplateException {
// that is because cfloop-contition evaluator does not pass this
if (data.ep == null)
return null;
final int start = data.srcCode.getPos();
// namespace and separator
final TagLib tagLib = CFMLTransformer.nameSpace(data);
if (tagLib == null || !tagLib.isCore())
return null;
// print.e("namespace:"+tagLib.getNameSpaceAndSeparator());
// get the name of the tag
String id = CFMLTransformer.identifier(data.srcCode, false, true);
if (id == null) {
data.srcCode.setPos(start);
return null;
}
id = id.toLowerCase();
String appendix = null;
TagLibTag tlt = tagLib.getTag(id);
// get taglib
if (tlt == null) {
tlt = tagLib.getAppendixTag(id);
if (tlt == null) {
// if(tagLib.getIgnoreUnknowTags()){ if we do this a expression like the following no longer work cfwhatever=1;
data.srcCode.setPos(start);
return null;
// }
// throw new TemplateException(data.srcCode,"undefined tag ["+tagLib.getNameSpaceAndSeparator()+id+"]");
}
appendix = StringUtil.removeStartingIgnoreCase(id, tlt.getName());
}
if (tlt.getScript() == null) {
data.srcCode.setPos(start);
return null;
}
// check for opening bracked or closing semicolon
comments(data);
boolean noAttrs = false;
if (!data.srcCode.forwardIfCurrent('(')) {
if (checkSemiColonLineFeed(data, false, false, false)) {
noAttrs = true;
} else {
data.srcCode.setPos(start);
return null;
}
}
Position line = data.srcCode.getPosition();
// script specific behavior
short context = CTX_OTHER;
Boolean allowExpression = Boolean.TRUE;
{
TagLibTagScript script = tlt.getScript();
if (script != null) {
context = script.getContext();
// always true for this tags allowExpression=script.getRtexpr()?Boolean.TRUE:Boolean.FALSE;
if (context == CTX_CFC)
data.isCFC = true;
else if (context == CTX_INTERFACE)
data.isInterface = true;
}
}
Tag tag = getTag(data, parent, tlt, line, null);
if (appendix != null) {
tag.setAppendix(appendix);
tag.setFullname(tlt.getFullName().concat(appendix));
} else {
tag.setFullname(tlt.getFullName());
}
tag.setTagLibTag(tlt);
tag.setScriptBase(true);
// add component meta data
if (data.isCFC) {
addMetaData(data, tag, IGNORE_LIST_COMPONENT);
}
if (data.isInterface) {
addMetaData(data, tag, IGNORE_LIST_INTERFACE);
}
comments(data);
// attributes
Attribute[] attrs = noAttrs ? new Attribute[0] : attributes(tag, tlt, data, BRACKED, data.factory.EMPTY(), allowExpression, null, false, ',', true);
data.srcCode.forwardIfCurrent(')');
for (int i = 0; i < attrs.length; i++) {
tag.addAttribute(attrs[i]);
}
comments(data);
// body
if (tlt.getHasBody()) {
Body body = new BodyBase(data.factory);
boolean wasSemiColon = statement(data, body, context);
if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
tag.setBody(body);
} else
checkSemiColonLineFeed(data, true, true, true);
tag.setEnd(data.srcCode.getPosition());
eval(tlt, data, tag);
return tag;
}
use of lucee.transformer.bytecode.BodyBase in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method forStatement.
/**
* Liest ein for Statement ein.
* <br />
* EBNF:<br />
* <code>expression spaces ";" spaces condition spaces ";" spaces expression spaces ")" spaces block;</code>
* @return for Statement
* @throws TemplateException
*/
private final Statement forStatement(ExprData data) throws TemplateException {
int pos = data.srcCode.getPos();
// id
String id = variableDec(data, false);
if (id == null) {
data.srcCode.setPos(pos);
return null;
}
if (id.equalsIgnoreCase("for")) {
id = null;
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent('(')) {
data.srcCode.setPos(pos);
return null;
}
} else {
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent(':')) {
data.srcCode.setPos(pos);
return null;
}
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent("for", '(')) {
data.srcCode.setPos(pos);
return null;
}
}
// if(!data.srcCode.forwardIfCurrent("for",'('))
// return null;
Expression left = null;
Body body = new BodyBase(data.factory);
Position line = data.srcCode.getPosition();
comments(data);
if (!data.srcCode.isCurrent(';')) {
// left
left = expression(data);
comments(data);
}
// middle for
if (data.srcCode.forwardIfCurrent(';')) {
Expression cont = null;
Expression update = null;
// condition
comments(data);
if (!data.srcCode.isCurrent(';')) {
cont = condition(data);
comments(data);
}
// middle
if (!data.srcCode.forwardIfCurrent(';'))
throw new TemplateException(data.srcCode, "invalid syntax in for statement");
// update
comments(data);
if (!data.srcCode.isCurrent(')')) {
update = expression(data);
comments(data);
}
// start )
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "invalid syntax in for statement, for statement must end with a [)]");
// ex block
statement(data, body, CTX_FOR);
return new For(data.factory, left, cont, update, body, line, data.srcCode.getPosition(), id);
} else // middle foreach
if (data.srcCode.forwardIfCurrent("in")) {
// condition
comments(data);
Expression value = expression(data);
comments(data);
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "invalid syntax in for statement, for statement must end with a [)]");
// ex block
statement(data, body, CTX_FOR);
if (!(left instanceof Variable))
throw new TemplateException(data.srcCode, "invalid syntax in for statement, left value is invalid");
// throw new TemplateException(data.srcCode,"invalid syntax in for statement, right value is invalid");
return new ForEach((Variable) left, value, body, line, data.srcCode.getPosition(), id);
} else
throw new TemplateException(data.srcCode, "invalid syntax in for statement");
}
use of lucee.transformer.bytecode.BodyBase 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