use of lucee.transformer.Position 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.transformer.Position 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.transformer.Position 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());
}
use of lucee.transformer.Position in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method tryStatement.
/**
* Liest eine try Block ein
* <br />
* EBNF:<br />
* <code>;</code>
* @return Try Block
* @throws TemplateException
*/
private final TryCatchFinally tryStatement(ExprData data) throws TemplateException {
if (!data.srcCode.forwardIfCurrent("try", '{') && !data.srcCode.forwardIfCurrent("try ") && !data.srcCode.forwardIfCurrent("try", '/'))
return null;
data.srcCode.previous();
Body body = new BodyBase(data.factory);
TryCatchFinally tryCatchFinally = new TryCatchFinally(data.factory, body, data.srcCode.getPosition(), null);
statement(data, body, CTX_TRY);
comments(data);
// catches
short catchCount = 0;
while (data.srcCode.forwardIfCurrent("catch", '(')) {
catchCount++;
comments(data);
// type
int pos = data.srcCode.getPos();
Position line = data.srcCode.getPosition();
Expression name = null, type = null;
StringBuffer sbType = new StringBuffer();
String id;
while (true) {
id = identifier(data, false);
if (id == null)
break;
sbType.append(id);
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent('.'))
break;
sbType.append('.');
data.srcCode.removeSpace();
}
if (sbType.length() == 0) {
type = string(data);
if (type == null)
throw new TemplateException(data.srcCode, "a catch statement must begin with the throwing type (query, application ...).");
} else {
type = data.factory.createLitString(sbType.toString());
}
// name = expression();
comments(data);
// name
if (!data.srcCode.isCurrent(')')) {
name = expression(data);
} else {
data.srcCode.setPos(pos);
name = expression(data);
type = data.factory.createLitString("any");
}
comments(data);
Body b = new BodyBase(data.factory);
try {
tryCatchFinally.addCatch(type, name, b, line);
} catch (TransformerException e) {
throw new TemplateException(data.srcCode, e.getMessage());
}
comments(data);
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "invalid catch statement, missing closing )");
statement(data, b, CTX_CATCH);
comments(data);
}
// finally
if (finallyStatement(data, tryCatchFinally)) {
comments(data);
} else if (catchCount == 0)
throw new TemplateException(data.srcCode, "a try statement must have at least one catch statement");
// if(body.isEmpty()) return null;
tryCatchFinally.setEnd(data.srcCode.getPosition());
return tryCatchFinally;
}
use of lucee.transformer.Position in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method switchStatement.
/**
* Liest ein switch Statment ein
* @return switch Statement
* @throws TemplateException
*/
private final Switch switchStatement(ExprData data) throws TemplateException {
if (!data.srcCode.forwardIfCurrent("switch", '('))
return null;
Position line = data.srcCode.getPosition();
comments(data);
Expression expr = super.expression(data);
comments(data);
// end )
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "switch statement must end with a [)]");
comments(data);
if (!data.srcCode.forwardIfCurrent('{'))
throw new TemplateException(data.srcCode, "switch statement must have a starting [{]");
Switch swit = new Switch(expr, line, null);
// cases
// Node child=null;
comments(data);
while (caseStatement(data, swit)) {
comments(data);
}
// default
if (defaultStatement(data, swit)) {
comments(data);
}
while (caseStatement(data, swit)) {
comments(data);
}
// }
if (!data.srcCode.forwardIfCurrent('}'))
throw new TemplateException(data.srcCode, "invalid construct in switch statement");
swit.setEnd(data.srcCode.getPosition());
return swit;
}
Aggregations