use of lucee.runtime.interpreter.ref.literal.LString in project Lucee by lucee.
the class BIF method callWithNamedValues.
@Override
public Object callWithNamedValues(PageContext pageContext, Struct values, boolean doIncludePath) throws PageException {
ArrayList<FunctionLibFunctionArg> flfas = flf.getArg();
Iterator<FunctionLibFunctionArg> it = flfas.iterator();
FunctionLibFunctionArg arg;
Object val;
List<Ref> refs = new ArrayList<Ref>();
while (it.hasNext()) {
arg = it.next();
// match by name
val = values.get(arg.getName(), null);
// match by alias
if (val == null) {
String alias = arg.getAlias();
if (!StringUtil.isEmpty(alias, true)) {
String[] aliases = lucee.runtime.type.util.ListUtil.trimItems(lucee.runtime.type.util.ListUtil.listToStringArray(alias, ','));
for (int x = 0; x < aliases.length; x++) {
val = values.get(aliases[x], null);
if (val != null)
break;
}
}
}
if (val == null) {
if (arg.getRequired()) {
String[] names = flf.getMemberNames();
String n = ArrayUtil.isEmpty(names) ? "" : names[0];
throw new ExpressionException("missing required argument [" + arg.getName() + "] for build in function call [" + n + "]");
}
} else {
refs.add(new Casting(arg.getTypeAsString(), arg.getType(), new LFunctionValue(new LString(arg.getName()), val)));
}
}
BIFCall call = new BIFCall(flf, refs.toArray(new Ref[refs.size()]));
return call.getValue(pageContext);
}
use of lucee.runtime.interpreter.ref.literal.LString in project Lucee by lucee.
the class CFMLExpressionInterpreter method checker.
/**
* Hier werden die verschiedenen Moeglichen Werte erkannt
* und jenachdem wird mit der passenden Methode weitergefahren
* <br />
* EBNF:<br />
* <code>string | number | dynamic | sharp;</code>
* @return CFXD Element
* @throws PageException
*/
private Ref checker() throws PageException {
Ref ref = null;
// String
if (cfml.isCurrentQuoter()) {
// mode=STATIC; is at the end of the string function because must set after execution
return string();
}
// Number
if (cfml.isCurrentDigit() || cfml.isCurrent('.')) {
// mode=STATIC; is at the end of the string function because must set after execution
return number();
}
// Dynamic
if ((ref = dynamic()) != null) {
mode = DYNAMIC;
return ref;
}
// Sharp
if (!limited && (ref = sharp()) != null) {
mode = DYNAMIC;
return ref;
}
// JSON
if ((ref = json(isJson ? JSON_ARRAY : LITERAL_ARRAY, '[', ']')) != null) {
mode = DYNAMIC;
return ref;
}
if ((ref = json(isJson ? JSON_STRUCT : LITERAL_STRUCT, '{', '}')) != null) {
mode = DYNAMIC;
return ref;
}
if (cfml.isAfterLast() && cfml.toString().trim().length() == 0)
return new LString("");
// else Error
String str = cfml.toString();
int pos = cfml.getPos();
if (str.length() > 100) {
// Failure is in the beginning
if (pos <= 10) {
str = str.substring(0, 20) + " ...";
} else // Failure is in the end
if ((str.length() - pos) <= 10) {
str = "... " + str.substring(str.length() - 20, str.length());
} else {
str = "... " + str.substring(pos - 10, pos + 10) + " ...";
}
}
throw new InterpreterException("Syntax Error, Invalid Construct", "at position " + (pos + 1) + " in [" + str + "]");
}
use of lucee.runtime.interpreter.ref.literal.LString in project Lucee by lucee.
the class CFMLExpressionInterpreter 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 PageException
*/
private Ref dynamic() throws PageException {
// get First Element of the Variable
int pos = cfml.getPos();
String name = identifier(false);
if (name == null) {
if (!cfml.forwardIfCurrent('('))
return null;
cfml.removeSpace();
Ref ref = assignOp();
if (!cfml.forwardIfCurrent(')'))
throw new InterpreterException("Invalid Syntax Closing [)] not found");
cfml.removeSpace();
return limited ? ref : subDynamic(ref);
}
cfml.removeSpace();
// Boolean constant
if (name.equalsIgnoreCase("TRUE")) {
cfml.removeSpace();
return LBoolean.TRUE;
} else if (name.equalsIgnoreCase("FALSE")) {
cfml.removeSpace();
return LBoolean.FALSE;
} else if (!isJson && name.equalsIgnoreCase("YES")) {
cfml.removeSpace();
return LBoolean.TRUE;
} else if (!isJson && name.equalsIgnoreCase("NO")) {
cfml.removeSpace();
return LBoolean.FALSE;
} else if (allowNullConstant && name.equalsIgnoreCase("NULL")) {
cfml.removeSpace();
return new LString(null);
} else if (!limited && name.equalsIgnoreCase("NEW")) {
Ref res = newOp();
if (res != null)
return res;
}
return limited ? startElement(name) : subDynamic(startElement(name));
}
use of lucee.runtime.interpreter.ref.literal.LString in project Lucee by lucee.
the class CFMLExpressionInterpreter method newOp.
private Ref newOp() throws PageException {
int start = cfml.getPos();
String name = null;
cfml.removeSpace();
// first identifier
name = identifier(true);
Ref refName = null;
if (name != null) {
StringBuilder fullName = new StringBuilder();
fullName.append(name);
// Loop over addional identifier
while (cfml.isValidIndex()) {
if (cfml.forwardIfCurrent('.')) {
cfml.removeSpace();
name = identifier(true);
if (name == null)
throw new InterpreterException("invalid Component declaration");
cfml.removeSpace();
fullName.append('.');
fullName.append(name);
} else
break;
}
refName = new LString(fullName.toString());
} else {
if (cfml.isCurrentQuoter())
refName = string();
if (refName == null) {
cfml.setPos(start);
return null;
}
}
cfml.removeSpace();
if (cfml.isCurrent('(')) {
FunctionLibFunction function = fld.getFunction("_createComponent");
Ref[] arguments = functionArg("_createComponent", true, function, ')');
Ref[] args = new Ref[arguments.length + 1];
for (int i = 0; i < arguments.length; i++) {
args[i] = arguments[i];
}
args[args.length - 1] = refName;
BIFCall bif = new BIFCall(function, args);
cfml.removeSpace();
return bif;
}
throw new InterpreterException("invalid Component declaration ");
}
use of lucee.runtime.interpreter.ref.literal.LString in project Lucee by lucee.
the class MemberUtil method callWithNamedValues.
public static Object callWithNamedValues(PageContext pc, Object coll, Collection.Key methodName, Struct args, short type, String strType) throws PageException {
Map<Key, FunctionLibFunction> members = getMembers(pc, type);
FunctionLibFunction member = members.get(methodName);
if (member != null) {
List<FunctionLibFunctionArg> _args = member.getArg();
FunctionLibFunctionArg arg;
if (args.size() < _args.size()) {
Object val;
ArrayList<Ref> refs = new ArrayList<Ref>();
arg = _args.get(0);
refs.add(new Casting(arg.getTypeAsString(), arg.getType(), new LFunctionValue(new LString(arg.getName()), coll)));
for (int y = 1; y < _args.size(); y++) {
arg = _args.get(y);
// match by name
val = args.get(arg.getName(), null);
// match by alias
if (val == null) {
String alias = arg.getAlias();
if (!StringUtil.isEmpty(alias, true)) {
String[] aliases = lucee.runtime.type.util.ListUtil.trimItems(lucee.runtime.type.util.ListUtil.listToStringArray(alias, ','));
for (int x = 0; x < aliases.length; x++) {
val = args.get(aliases[x], null);
if (val != null)
break;
}
}
}
if (val == null) {
if (arg.getRequired()) {
String[] names = member.getMemberNames();
String n = ArrayUtil.isEmpty(names) ? "" : names[0];
throw new ExpressionException("missing required argument [" + arg.getName() + "] for member function call [" + n + "]");
}
} else {
refs.add(new Casting(arg.getTypeAsString(), arg.getType(), new LFunctionValue(new LString(arg.getName()), val)));
// refs.add(new LFunctionValue(new LString(arg.getName()),new Casting(pc,arg.getTypeAsString(),arg.getType(),val)));
}
}
return new BIFCall(coll, member, refs.toArray(new Ref[refs.size()])).getValue(pc);
}
}
throw new ExpressionException("No matching function member [" + methodName + "] for call with named arguments found, available function members are [" + lucee.runtime.type.util.ListUtil.sort(CollectionUtil.getKeyList(members.keySet().iterator(), ","), "textnocase", "asc", ",") + "]");
}
Aggregations