class Writer {
private void processFunction(Node node, JsonML currentParent) {
JsonML element;
if (NodeUtil.isFunctionDeclaration(node)) {
element = new JsonML(TagType.FunctionDecl);
} else { // isFunctionExpresion == true
element = new JsonML(TagType.FunctionExpr);
}
currentParent.appendChild(element);
// the first child represents function's name
Node child = node.getFirstChild();
String name = child.getString();
if (!name.equals("")) {
JsonML nameElement = new JsonML(TagType.IdPatt);
nameElement.setAttribute(TagAttr.NAME, name);
element.appendChild(nameElement);
} else {
element.appendChild(new JsonML(TagType.Empty));
}
// the second child is a wrapper for formal parameters
child = child.getNext();
JsonML params = new JsonML(TagType.ParamDecl);
element.appendChild(params);
Iterator<Node> it = child.children().iterator();
while (it.hasNext()) {
JsonML param = new JsonML(TagType.IdPatt);
Node nameNode = it.next();
param.setAttribute(TagAttr.NAME, nameNode.getString());
params.appendChild(param);
}
// the third child represents function's body
child = child.getNext();
// it can contain some directives
processDirectives(child, element);
it = child.children().iterator();
while (it.hasNext()) {
processNode(it.next(), element);
}
}
}