use of com.laytonsmith.core.constructs.Construct in project CommandHelper by EngineHub.
the class Script method seval.
/**
* Runs eval on the code tree, and if it returns an ival, resolves it.
*
* @param c
* @param env
* @return
*/
public Construct seval(ParseTree c, final Environment env) {
Construct ret = eval(c, env);
while (ret instanceof IVariable) {
IVariable cur = (IVariable) ret;
ret = env.getEnv(GlobalEnv.class).GetVarList().get(cur.getVariableName(), cur.getTarget()).ival();
}
return ret;
}
use of com.laytonsmith.core.constructs.Construct in project CommandHelper by EngineHub.
the class Script method checkAmbiguous.
public void checkAmbiguous(List<Script> scripts) throws ConfigCompileException {
List<Construct> thisCommand = this.cleft;
for (Script script : scripts) {
List<Construct> thatCommand = script.cleft;
if (thatCommand == null) {
// It hasn't been compiled yet.
return;
}
if (this.cleft == script.cleft) {
// Of course this command is going to match its own signature.
continue;
}
matchScope: {
for (int k = 0; k < thisCommand.size(); k++) {
Construct c1 = thisCommand.get(k);
if (k < thatCommand.size()) {
Construct c2 = thatCommand.get(k);
// the same argument position.
if (c1.getCType() == c2.getCType() && (c1.getCType() == ConstructType.STRING || c1.getCType() == ConstructType.COMMAND)) {
if (c1.nval() != c2.nval() && (c1.nval() == null || !c1.nval().equals(c2.nval()))) {
break matchScope;
}
}
} else {
// after the last Construct in thatCommand.
if (!(c1 instanceof Variable) || (c1 instanceof Variable && !((Variable) c1).isOptional())) {
break matchScope;
} else {
// There is no need to loop over later Constructs, the commands are ambigous.
break;
}
}
}
if (thatCommand.size() > thisCommand.size()) {
// thisCommand is shorter than thatCommand.
// Commands are not ambigous if thatCommand contains a non-variable or a non-optional variable
// after the last Construct in thisCommand.
Construct c2 = thatCommand.get(thisCommand.size());
if (!(c2 instanceof Variable) || (c2 instanceof Variable && !((Variable) c2).isOptional())) {
break matchScope;
}
}
// The signature of thisCommand and thatCommand are ambigous. Throw a compile exception.
String commandThis = "";
for (Construct c : thisCommand) {
commandThis += c.val() + " ";
}
String commandThat = "";
for (Construct c : thatCommand) {
commandThat += c.val() + " ";
}
script.compilerError = true;
this.compilerError = true;
throw new ConfigCompileException("The command " + commandThis.trim() + " is ambiguous because it " + "matches the signature of " + commandThat.trim() + " defined at " + thatCommand.get(0).getTarget(), thisCommand.get(0).getTarget());
}
}
}
Aggregations