}
return w.done();
}
else if (type.isSet()) {
Type elementType = splicing ? type : type.getElementType();
ISetWriter w = values.setWriter();
for (IValue arg: TreeAdapter.getListASTArgs(tree)) {
w.insert(implode(store, elementType, (IConstructor) arg, false, ctx));
}
return w.done();
}
else {
throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Cannot match list with " + type));
}
}
//Changes end here
if (TreeAdapter.isOpt(tree) && type.isBool()) {
IList args = TreeAdapter.getArgs(tree);
if (args.isEmpty()) {
return values.bool(false);
}
return values.bool(true);
}
if (TreeAdapter.isOpt(tree)) {
if (!type.isList() && !isUntypedNodeType(type)) {
throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Optional should match with a list and not " + type));
}
Type elementType = isUntypedNodeType(type) ? type : type.getElementType();
IListWriter w = values.listWriter();
for (IValue arg: TreeAdapter.getASTArgs(tree)) {
IValue implodedArg = implode(store, elementType, (IConstructor) arg, true, ctx);
if (implodedArg instanceof IList) {
// splicing
for (IValue nextArg: (IList)implodedArg) {
w.append(nextArg);
}
}
else {
w.append(implodedArg);
}
// opts should have one argument (if any at all)
break;
}
return w.done();
}
if (TreeAdapter.isAmb(tree)) {
if (!type.isSet()) {
throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Ambiguous node should match with set and not " + type));
}
Type elementType = type.getElementType();
ISetWriter w = values.setWriter();
for (IValue arg: TreeAdapter.getAlternatives(tree)) {
w.insert(implode(store, elementType, (IConstructor) arg, false, ctx));
}
return w.done();
}
if (ProductionAdapter.hasAttribute(TreeAdapter.getProduction(tree), Factory.Attribute_Bracket)) {
return implode(store, type, (IConstructor) TreeAdapter.getASTArgs(tree).get(0), false, ctx);
}