Search in sources :

Example 21 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.

the class EvalHelper method eval.

public static BackendEvalResult eval(final IOtpRpc b, final String string, final OtpErlangObject bindings) {
    final BackendEvalResult result = new BackendEvalResult();
    try {
        OtpErlangObject r1;
        // ErlLogger.debug("eval %s %s", string, bindings);
        if (bindings == null) {
            r1 = b.call("erlide_backend", "eval", "s", string);
        } else {
            r1 = b.call("erlide_backend", "eval", "sx", string, bindings);
        }
        // value may be something else if exception is thrown...
        final OtpErlangTuple t = (OtpErlangTuple) r1;
        final boolean ok = !"error".equals(((OtpErlangAtom) t.elementAt(0)).atomValue());
        if (ok) {
            result.setValue(t.elementAt(1), t.elementAt(2));
        } else {
            result.setError(t.elementAt(1));
        }
    } catch (final Exception e) {
        result.setError("rpc failed");
    }
    return result;
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 22 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.

the class InterpretEvent method execute.

@Override
public void execute(final ErlangDebugTarget debugTarget) {
    final OtpErlangAtom m = (OtpErlangAtom) cmds[1];
    debugTarget.getInterpretedModules().add(m.atomValue());
    debugTarget.fireEvent(new DebugEvent(this, DebugEvent.MODEL_SPECIFIC, ErlangDebugTarget.INTERPRETED_MODULES_CHANGED));
}
Also used : DebugEvent(org.eclipse.debug.core.DebugEvent) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 23 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.

the class ErlParser method addRecordDef.

private IErlRecordDef addRecordDef(final IErlModule module, final OtpErlangObject pos, final OtpErlangObject val, final OtpErlangObject extra) {
    if (val instanceof OtpErlangTuple) {
        final OtpErlangTuple recordTuple = (OtpErlangTuple) val;
        if (recordTuple.elementAt(0) instanceof OtpErlangAtom) {
            final String s = extra instanceof OtpErlangString ? ((OtpErlangString) extra).stringValue() : null;
            final OtpErlangList fields = (OtpErlangList) recordTuple.elementAt(1);
            final ErlRecordDef r = new ErlRecordDef(module, null, s);
            setPos(r, pos);
            if (fields != null) {
                final List<ErlRecordField> children = Lists.newArrayListWithCapacity(fields.arity());
                for (final OtpErlangObject o : fields) {
                    if (o instanceof OtpErlangTuple) {
                        final OtpErlangTuple fieldTuple = (OtpErlangTuple) o;
                        final OtpErlangAtom fieldNameAtom = (OtpErlangAtom) fieldTuple.elementAt(0);
                        final String fieldName = fieldNameAtom.atomValue();
                        final ErlRecordField field = new ErlRecordField(r, fieldName);
                        final OtpErlangTuple posTuple = (OtpErlangTuple) fieldTuple.elementAt(1);
                        if (fieldTuple.arity() > 2) {
                            final OtpErlangObject fieldExtra = fieldTuple.elementAt(2);
                            field.setExtra(Util.stringValue(fieldExtra));
                        }
                        setPos(field, posTuple);
                        children.add(field);
                    } else {
                        ErlLogger.error("bad record def: %s", o);
                    }
                }
                r.setChildren(children);
            } else {
                r.setChildren(new ArrayList<>());
            }
            return r;
        }
    }
    if (val instanceof OtpErlangAtom) {
        final String s = extra instanceof OtpErlangString ? ((OtpErlangString) extra).stringValue() : null;
        final ErlRecordDef r = new ErlRecordDef(module, null, s);
        setPos(r, pos);
        return r;
    }
    return null;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) ErlRecordField(org.erlide.engine.internal.model.erlang.ErlRecordField) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) ErlRecordDef(org.erlide.engine.internal.model.erlang.ErlRecordDef) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 24 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.

the class ErlParser method parse.

public boolean parse(final IErlModule module, final String scannerName, final boolean initialParse, final String path, final String initialText, final boolean updateSearchServer) {
    if (module == null) {
        return false;
    }
    OtpErlangList forms = null;
    OtpErlangList comments = null;
    OtpErlangTuple res = null;
    if (initialParse) {
        final String stateDir = ErlangEngine.getInstance().getStateDir();
        final String pathNotNull = path == null ? "" : path;
        res = ErlideNoparse.initialParse(backend, scannerName, pathNotNull, initialText, stateDir, updateSearchServer);
    } else {
        res = ErlideNoparse.reparse(backend, scannerName, updateSearchServer);
    }
    if (Util.isOk(res)) {
        final OtpErlangTuple t = (OtpErlangTuple) res.elementAt(1);
        forms = (OtpErlangList) t.elementAt(1);
        comments = (OtpErlangList) t.elementAt(2);
    } else {
        ErlLogger.error("error when parsing %s: %s", path, res);
    }
    if (forms == null) {
        module.setChildren(null);
    } else {
        final List<IErlElement> children = createForms(module, forms);
        module.setChildren(children);
    }
    if (comments == null) {
        module.setComments(null);
    } else {
        final List<IErlComment> moduleComments = createComments(module, comments);
        module.setComments(moduleComments);
    }
    attachFunctionComments(module);
    String cached = "reparsed";
    if (res != null && res.arity() > 2) {
        final OtpErlangObject res2 = res.elementAt(2);
        if (res2 instanceof OtpErlangAtom) {
            final OtpErlangAtom atom = (OtpErlangAtom) res2;
            cached = atom.atomValue();
        }
    }
    if (ErlParser.TRACE) {
        ErlLogger.debug("Parsed %d forms and %d comments (%s)", forms != null ? forms.arity() : 0, comments != null ? comments.arity() : 0, cached);
    }
    return forms != null && comments != null;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlComment(org.erlide.engine.model.erlang.IErlComment) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 25 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.

the class ErlideDoc method getOtpDoc.

@Override
public OtpErlangObject getOtpDoc(final IOtpRpc b, final ErlangFunctionCall functionCall) {
    OtpErlangObject res = null;
    final OtpErlangTuple input = new OtpErlangTuple(new OtpErlangObject[] { new OtpErlangAtom("external"), new OtpErlangAtom(functionCall.getModule()), new OtpErlangAtom(functionCall.getName()), new OtpErlangInt(functionCall.getArity()), new OtpErlangString("") });
    try {
        res = b.call(ErlideDoc.ERLIDE_OTP_DOC, "get_doc", "sxs", functionCall.getModule(), input, stateDir);
    } catch (final RpcException e) {
        ErlLogger.warn(e);
    }
    return res;
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangInt(com.ericsson.otp.erlang.OtpErlangInt) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Aggregations

OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)87 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)56 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)48 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)32 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)24 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)17 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)11 RpcException (org.erlide.runtime.rpc.RpcException)11 OtpBindings (org.erlide.util.erlang.OtpBindings)9 IErlElement (org.erlide.engine.model.IErlElement)6 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)4 OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)4 IErlModule (org.erlide.engine.model.root.IErlModule)4 OtpErlangInt (com.ericsson.otp.erlang.OtpErlangInt)3 OtpErlangMap (com.ericsson.otp.erlang.OtpErlangMap)3 Subscribe (com.google.common.eventbus.Subscribe)3 Collection (java.util.Collection)3 OtpErlangException (com.ericsson.otp.erlang.OtpErlangException)2