mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 15:26:52 -04:00
allows translated panics from hgs
This commit is contained in:
parent
d25c92c105
commit
53ad33d6de
@ -8,6 +8,7 @@ package de.neemann.digital.hdl.hgs;
|
|||||||
import de.neemann.digital.hdl.hgs.function.Func;
|
import de.neemann.digital.hdl.hgs.function.Func;
|
||||||
import de.neemann.digital.hdl.hgs.function.Function;
|
import de.neemann.digital.hdl.hgs.function.Function;
|
||||||
import de.neemann.digital.hdl.hgs.function.InnerFunction;
|
import de.neemann.digital.hdl.hgs.function.InnerFunction;
|
||||||
|
import de.neemann.digital.lang.Lang;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -276,12 +277,27 @@ public class Context {
|
|||||||
|
|
||||||
private static final class FunctionPanic extends Function {
|
private static final class FunctionPanic extends Function {
|
||||||
private FunctionPanic() {
|
private FunctionPanic() {
|
||||||
super(1);
|
super(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object f(Object... args) throws HGSEvalException {
|
protected Object f(Object... args) throws HGSEvalException {
|
||||||
throw new HGSEvalException(args[0].toString());
|
if (args.length == 0)
|
||||||
|
throw new HGSEvalException("panic");
|
||||||
|
|
||||||
|
String message = args[0].toString();
|
||||||
|
if (message.startsWith("err_")) {
|
||||||
|
if (args.length == 1)
|
||||||
|
message = Lang.get(message);
|
||||||
|
else {
|
||||||
|
String[] ar = new String[args.length - 1];
|
||||||
|
for (int i = 0; i < args.length - 1; i++)
|
||||||
|
ar[i] = args[i + 1].toString();
|
||||||
|
message = Lang.get(message, ar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HGSEvalException(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,6 +495,18 @@ public class ParserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testPanic2() throws IOException, ParserException, HGSEvalException {
|
||||||
|
Statement s = new Parser("<? panic(\"err_varNotDefined_N\",\"hello\"); ?>").parse();
|
||||||
|
|
||||||
|
try {
|
||||||
|
exec(s);
|
||||||
|
fail();
|
||||||
|
} catch (HGSEvalException e) {
|
||||||
|
assertTrue(e.getMessage().contains("hello"));
|
||||||
|
assertFalse(e.getMessage().contains("err_"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testTrim() throws IOException, ParserException, HGSEvalException {
|
public void testTrim() throws IOException, ParserException, HGSEvalException {
|
||||||
assertEquals(" 5", exec(" <?=5;-?> ").toString());
|
assertEquals(" 5", exec(" <?=5;-?> ").toString());
|
||||||
assertEquals("5 ", exec(" <?-=5?> ").toString());
|
assertEquals("5 ", exec(" <?-=5?> ").toString());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user