use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.
the class PatternMatchTest method testMatch_1.
@Test
public void testMatch_1() throws Exception {
final OtpBindings r = OtpErlang.match("[W, V]", "[\"a\", {[1, 2]}]");
Assert.assertEquals(r.get("W"), new OtpErlangString("a"));
Assert.assertEquals(r.get("V"), OtpErlang.parse("{[1, 2]}"));
}
use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.
the class PatternMatchTest method testMatch_t.
@Test
public void testMatch_t() throws Exception {
final OtpBindings r = OtpErlang.match("[W:a, V:i]", "[a, 1]");
Assert.assertEquals(r.getAs("W", String.class), "a");
Assert.assertEquals(r.getAs("V", Integer.class), Integer.valueOf(1));
}
use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.
the class DebuggerEventFactory method parseMeta.
private static MetaEvent parseMeta(final OtpErlangPid pid, final OtpErlangObject event) {
try {
OtpBindings b = OtpErlang.match("{break_at, Mod:a, Line:i, Crt}", event);
if (b != null) {
return new BreakAtEvent(pid, b.getAtom("Mod"), b.getInt("Line"), b.get("Crt"));
}
b = OtpErlang.match("{exit_at, Pos, Reason, Le, OrigPid:p}", event);
if (b != null) {
return new ExitAtEvent(pid, b.get("Pos"), b.get("Reason"), b.get("Le"), b.getPid("OrigPid"));
}
b = OtpErlang.match("{exit_at, Pos, Reason, Le, OrigPid:p, Stack:l, Binds:l}", event);
if (b != null) {
return new ExitAtEvent(pid, b.get("Pos"), b.get("Reason"), b.get("Le"), b.getPid("OrigPid"), (OtpErlangList) b.get("Stack"), (OtpErlangList) b.get("Binds"));
}
b = OtpErlang.match("{wait_at, Mod:a, Line:i, Crt}", event);
if (b != null) {
return new WaitAtEvent(pid, b.getAtom("Mod"), b.getInt("Line"), b.get("Crt"));
}
} catch (final Exception e) {
}
// this is a default event that does nothing
return new MetaEvent(pid, event);
}
use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.
the class DebuggerEventFactory method parse.
public static DebuggerEvent parse(final OtpErlangObject message) {
// TODO More events from dbg_mon...
try {
OtpBindings b = OtpErlang.match("{started, Pid:p}", message);
if (b != null) {
return DebuggerEventFactory.buildStartedEvent(b);
}
b = OtpErlang.match("{terminated, Pid:p}", message);
if (b != null) {
return DebuggerEventFactory.buildTerminatedEvent(b);
}
b = OtpErlang.match("{int, Cmd}", message);
if (b != null) {
return DebuggerEventFactory.buildIntEvent(b);
}
b = OtpErlang.match("{attached, Pid:p}", message);
if (b != null) {
return DebuggerEventFactory.buildAttachedEvent(b);
}
b = OtpErlang.match("{Other:a, Cmd}", message);
if (b != null) {
return DebuggerEventFactory.buildUnknownEvent(message);
}
b = OtpErlang.match("{Meta:p, Event}", message);
if (b != null) {
return DebuggerEventFactory.buildMetaEvent(b);
}
} catch (final OtpParserException e) {
ErlLogger.error(e);
} catch (final OtpErlangException e) {
ErlLogger.error(e);
}
return new UnknownEvent(message);
}
use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.
the class IOServer method processRequest.
private OtpErlangObject processRequest(final OtpErlangPid from, final OtpErlangObject arequest) {
if (callback == null) {
return error;
}
OtpBindings b;
try {
if (arequest instanceof OtpErlangTuple) {
final OtpErlangTuple request = (OtpErlangTuple) arequest;
final String tag = ((OtpErlangAtom) request.elementAt(0)).atomValue();
if ("put_chars".equals(tag)) {
b = OtpErlang.match("{put_chars, Chars}", request);
if (b != null) {
return callback.putChars(from, IOEncoding.latin1, b.get("Chars"));
}
b = OtpErlang.match("{put_chars, Enc:a, Chars}", request);
if (b != null) {
final String enc = b.getAtom("Enc");
return callback.putChars(from, IOEncoding.valueOf(enc), b.get("Chars"));
}
b = OtpErlang.match("{put_chars, M:a, F:a, A}", request);
if (b != null) {
final String m = b.getAtom("M");
final String f = b.getAtom("F");
final Collection<OtpErlangObject> a = b.getList("A");
return callback.putChars(from, IOEncoding.latin1, m, f, a);
}
b = OtpErlang.match("{put_chars, Enc:a, M:a, F:a, A}", request);
if (b != null) {
final String enc = b.getAtom("Enc");
final String m = b.getAtom("M");
final String f = b.getAtom("F");
final Collection<OtpErlangObject> a = b.getList("A");
return callback.putChars(from, IOEncoding.valueOf(enc), m, f, a);
}
return error;
} else if ("get_until".equals(tag)) {
b = OtpErlang.match("{get_until, Prompt}", request);
if (b != null) {
return callback.getUntil(IOEncoding.latin1, b.get("Prompt"));
}
b = OtpErlang.match("{get_until, Prompt, N:i}", request);
if (b != null) {
final long n = b.getLong("N");
return callback.getUntil(IOEncoding.latin1, b.get("Prompt"), n);
}
b = OtpErlang.match("{get_until, Enc:a, Prompt}", request);
if (b != null) {
final String enc = b.getAtom("Enc");
return callback.getUntil(IOEncoding.valueOf(enc), b.get("Prompt"));
}
b = OtpErlang.match("{get_until, Enc:a, Prompt, N:i}", request);
if (b != null) {
final String enc = b.getAtom("Enc");
final long n = b.getLong("N");
return callback.getUntil(IOEncoding.valueOf(enc), b.get("Prompt"), n);
}
b = OtpErlang.match("{get_until, Prompt, M:a, F:a, A}", request);
if (b != null) {
final String m = b.getAtom("M");
final String f = b.getAtom("F");
final Collection<OtpErlangObject> a = b.getList("A");
return callback.getUntil(IOEncoding.latin1, b.get("Prompt"), m, f, a);
}
b = OtpErlang.match("{get_until, Enc: a, Prompt, M:a, F:a, A}", request);
if (b != null) {
final String enc = b.getAtom("Enc");
final String m = b.getAtom("M");
final String f = b.getAtom("F");
final Collection<OtpErlangObject> a = b.getList("A");
return callback.getUntil(IOEncoding.valueOf(enc), b.get("Prompt"), m, f, a);
}
} else if ("requests".equals(tag)) {
b = OtpErlang.match("{requests, Reqs:lx}", request);
if (b != null) {
final Collection<OtpErlangObject> reqs = b.getList("Reqs");
OtpErlangObject val = null;
for (final OtpErlangObject r : reqs) {
val = processRequest(from, r);
if (val.equals(error)) {
return error;
}
}
return val == null ? error : val;
}
} else if ("setopts".equals(tag)) {
b = OtpErlang.match("{setopts, Opts:lx}", request);
if (b != null) {
final Collection<OtpErlangObject> opts = b.getList("Opts");
return callback.setOpts(opts);
}
} else if ("get_geometry".equals(tag)) {
return OtpErlang.mkTuple(new OtpErlangAtom("error"), new OtpErlangAtom("enotsup"));
} else {
return error;
}
} else if (arequest instanceof OtpErlangAtom) {
final OtpErlangAtom tag = (OtpErlangAtom) arequest;
if ("getopts".equals(tag.atomValue())) {
return callback.getOpts();
}
return error;
} else {
return error;
}
} catch (final OtpParserException e) {
ErlLogger.error(e);
} catch (final OtpErlangException e) {
ErlLogger.error(e);
}
return error;
}
Aggregations