use of org.erlide.engine.internal.model.erlang.ErlFunctionClause in project erlide_eclipse by erlang.
the class ErlParser method makeErlFunctionClause.
/**
* @param f
* function
* @param i
* clause number
* @param clause
* -record(clause, {pos, name, args, head, code, name_pos}).
* @return ErlFunctionClause
*/
private ErlFunctionClause makeErlFunctionClause(final ErlFunction f, final int i, final OtpErlangTuple clause) {
final OtpErlangTuple cpos = (OtpErlangTuple) clause.elementAt(1);
final OtpErlangList parameters = (OtpErlangList) clause.elementAt(3);
final OtpErlangObject head = clause.elementAt(4);
final OtpErlangTuple cnamePos = (OtpErlangTuple) clause.elementAt(5);
final ErlFunctionClause cl = new ErlFunctionClause(f, "#" + i, Util.stringValue(head), parameters);
try {
setNamePos(cl, cnamePos);
} catch (final OtpErlangRangeException e) {
ErlLogger.warn(e);
}
setPos(cl, cpos);
return cl;
}
use of org.erlide.engine.internal.model.erlang.ErlFunctionClause 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;
}
Aggregations