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;
}
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;
}
Aggregations