Search in sources :

Example 1 with ErlFunction

use of org.erlide.engine.internal.model.erlang.ErlFunction in project erlide_eclipse by erlang.

the class ErlParser method create.

/**
 * create an IErlMember from a tuple from noparse
 *
 * @param el
 *            the tuple, either function or attribute
 * @return
 */
private IErlMember create(final IErlModule module, final OtpErlangTuple el) {
    final OtpErlangAtom type = (OtpErlangAtom) el.elementAt(0);
    final String typeS = type.atomValue();
    if ("error".equals(typeS)) {
        final OtpErlangTuple er = (OtpErlangTuple) el.elementAt(1);
        final String msg = helper.formatError(er);
        final ErlParserProblem e = ErlParserProblem.newError(module, msg);
        setPos(e, er.elementAt(0));
        return e;
    } else if ("tree".equals(typeS)) {
        final OtpErlangTuple atr = (OtpErlangTuple) el.elementAt(3);
        final OtpErlangObject pos = ((OtpErlangTuple) el.elementAt(2)).elementAt(1);
        final OtpErlangTuple name = (OtpErlangTuple) atr.elementAt(1);
        final OtpErlangAtom n = (OtpErlangAtom) concreteTerm(name);
        final OtpErlangObject val = atr.elementAt(2);
        final OtpErlangObject extra = el.arity() > 4 ? el.elementAt(4) : null;
        return addAttribute(module, pos, n, val, extra, null);
    } else if ("attribute".equals(typeS)) {
        final OtpErlangObject pos = el.elementAt(1);
        final OtpErlangAtom name = (OtpErlangAtom) el.elementAt(2);
        final OtpErlangObject val = el.elementAt(3);
        final OtpErlangObject extra = el.arity() > 4 ? el.elementAt(4) : null;
        final OtpErlangObject arity = el.arity() > 5 ? el.elementAt(5) : null;
        return addAttribute(module, pos, name, val, extra, arity);
    } else if ("function".equals(typeS)) {
        final ErlFunction f = makeErlFunction(module, el);
        final OtpErlangList clauses = (OtpErlangList) el.elementAt(6);
        final List<ErlFunctionClause> cls = Lists.newArrayListWithCapacity(clauses.arity());
        for (int i = 0; i < clauses.arity(); i++) {
            final OtpErlangTuple clause = (OtpErlangTuple) clauses.elementAt(i);
            final ErlFunctionClause cl = makeErlFunctionClause(f, i, clause);
            cls.add(cl);
        }
        f.setChildren(cls);
        return f;
    } else {
        ErlLogger.debug("unknown: " + typeS);
    }
    return null;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ErlFunction(org.erlide.engine.internal.model.erlang.ErlFunction) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) ErlFunctionClause(org.erlide.engine.internal.model.erlang.ErlFunctionClause)

Example 2 with ErlFunction

use of org.erlide.engine.internal.model.erlang.ErlFunction in project erlide_eclipse by erlang.

the class ErlParser method makeErlFunction.

/**
 * @param module
 *            module
 * @param el
 *            -record(function, {pos, name, arity, args, head, clauses, name_pos,
 *            comment, exported}).
 * @return ErlFunction
 */
private ErlFunction makeErlFunction(final IErlModule module, final OtpErlangTuple el) {
    final OtpErlangTuple pos = (OtpErlangTuple) el.elementAt(1);
    final OtpErlangAtom name = (OtpErlangAtom) el.elementAt(2);
    final OtpErlangLong arity = (OtpErlangLong) el.elementAt(3);
    final OtpErlangList parameters = (OtpErlangList) el.elementAt(4);
    final OtpErlangObject head = el.elementAt(5);
    final OtpErlangTuple namePos = (OtpErlangTuple) el.elementAt(7);
    ErlFunction f = null;
    final OtpErlangAtom exportedA = (OtpErlangAtom) el.elementAt(8);
    final boolean exported = Boolean.parseBoolean(exportedA.atomValue());
    try {
        f = new ErlFunction(module, name.atomValue(), arity.intValue(), Util.stringValue(head), exported, parameters);
    } catch (final OtpErlangRangeException e) {
        return f;
    }
    setPos(f, pos);
    try {
        setNamePos(f, namePos);
    } catch (final OtpErlangRangeException e) {
        return f;
    }
    return f;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ErlFunction(org.erlide.engine.internal.model.erlang.ErlFunction) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Aggregations

OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)2 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)2 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 ErlFunction (org.erlide.engine.internal.model.erlang.ErlFunction)2 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)2 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 ErlFunctionClause (org.erlide.engine.internal.model.erlang.ErlFunctionClause)1