Skip to content

Commit

Permalink
Fix test discrepancy; moved trying to runFrom to use parseExceptionCa…
Browse files Browse the repository at this point in the history
…llback; moved pollEvents to end of loop; SVVal test fix.
  • Loading branch information
SerrpentDagger committed Aug 31, 2023
1 parent 3350716 commit 358278b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 47 deletions.
85 changes: 43 additions & 42 deletions src/commands/Scajl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2289,60 +2289,61 @@ public synchronized void forceKill()
}
public void run(VarSet... varSets)
{
try
{
keyIn = new Scanner(System.in);
runFrom(GLOBAL, varSets);
}
catch (ScajlException e)
{
this.parseExceptionCallback.accept(e, e.getMessage());
}
catch (Throwable e)
{
e.printStackTrace();
this.exceptionCallback.accept(e);
}
keyIn = new Scanner(System.in);
runFrom(GLOBAL, varSets);
}
private int labelsDeep = 0;
public void runFrom(Label label, VarSet... varSets)
{
pushStack(label);
for (VarSet var : varSets)
putVar(var.var, var.set);
if (keyIn == null)
keyIn = new Scanner(System.in);

Bool breakIf = new Bool(false);
while(parseLine < lines.length && !stack.isEmpty() && !forceKill.get())
try
{
if (pollEvents != null)
pollEvents.run();
String line = lines[parseLine];
if (!line.isEmpty())
pushStack(label);
for (VarSet var : varSets)
putVar(var.var, var.set);
if (keyIn == null)
keyIn = new Scanner(System.in);

Bool breakIf = new Bool(false);
while(parseLine < lines.length && !stack.isEmpty() && !forceKill.get())
{
if (line.startsWith(LABEL) || line.startsWith(SCOPED_LABEL))
labelsDeep++;
else if (labelsDeep == 0)
String line = lines[parseLine];
if (!line.isEmpty())
{
if (line.equals(HELP_CHAR_STR))
PRINT_COMMANDS.func.cmd(this, (Object[]) null);
else if (startsWith(line, SCOPE_S) && LEGAL_ANON_SCOPE_MATCHER.matcher(line).matches())
scope.push(scope.getLast().getLabelTree().getFor(anonScope.get(parseLine)));
else if (endsWith(line, SCOPE_E) && LEGAL_ANON_SCOPE_MATCHER.matcher(line).matches())
scope.pop();
else
if (line.startsWith(LABEL) || line.startsWith(SCOPED_LABEL))
labelsDeep++;
else if (labelsDeep == 0)
{
CommandResult res = runExecutable(line, breakIf, null);
if (res.shouldBreak)
break;
if (line.equals(HELP_CHAR_STR))
PRINT_COMMANDS.func.cmd(this, (Object[]) null);
else if (startsWith(line, SCOPE_S) && LEGAL_ANON_SCOPE_MATCHER.matcher(line).matches())
scope.push(scope.getLast().getLabelTree().getFor(anonScope.get(parseLine)));
else if (endsWith(line, SCOPE_E) && LEGAL_ANON_SCOPE_MATCHER.matcher(line).matches())
scope.pop();
else
{
CommandResult res = runExecutable(line, breakIf, null);
if (res.shouldBreak)
break;
}
}
else if (endsLabel(line))
labelsDeep--;
}
else if (endsLabel(line))
labelsDeep--;
parseLine++;
if (pollEvents != null)
pollEvents.run();
}
parseLine++;
}
catch (ScajlException e)
{
this.parseExceptionCallback.accept(e, e.getMessage());
}
catch (Throwable e)
{
e.printStackTrace();
this.exceptionCallback.accept(e);
}

}
protected CommandResult runExecutable(String executableLine, SVMember selfCtx)
{
Expand Down
6 changes: 1 addition & 5 deletions src/commands/ScajlVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ public String raw()
public boolean test(ScajlVariable other, Scajl ctx)
{
if (modless.equals("null"))
if (other instanceof SVVal)
return other.equals(NULL) || CmdArg.BOOLEAN.parse(other, ctx) != null || CmdArg.DOUBLE.parse(other, ctx) != null;
else
return true;
return true;
boolean t = other instanceof SVVal && other != NULL;
if (!t)
return false;
Expand Down Expand Up @@ -1422,7 +1419,6 @@ public static void putVar(String name, ScajlVariable var, Scajl ctx, SVMember se

public static boolean test(Variable var, ScajlVariable pat, Scajl ctx)
{
//return var.name != null && (!isVar(var.name, ctx) || !pat.test(var.var, ctx));
return var.name != null && isVar(var.name, ctx) && pat.test(var.var, ctx);
}

Expand Down

0 comments on commit 358278b

Please sign in to comment.