@Override
public IConstructor visitExpressionCallOrTree(CallOrTree x) {
Expression namePart = x.getExpression();
if (!namePart.isQualifiedName()) {
throw new ImplementationError("weird AST");
}
String name = ((org.rascalmpl.semantics.dynamic.QualifiedName.Default) namePart.getQualifiedName()).lastName();
if (name.equals("lit")) {
StringConstant.Lexical arg =
(org.rascalmpl.ast.StringConstant.Lexical) x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
// TODO: escaping etc.
String str = arg.getString();
str = str.substring(1, str.length() - 1);
return vf.constructor(Factory.Symbol_Lit, vf.string(str));
}
if (name.equals("cilit")) {
StringConstant.Lexical arg = (org.rascalmpl.ast.StringConstant.Lexical) x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
// TODO: escaping etc.
String str = arg.getString();
str = str.substring(1, str.length() - 1);
return vf.constructor(Factory.Symbol_CiLit, vf.string(str));
}
if (name.equals("empty")) {
return vf.constructor(Factory.Symbol_Empty);
}
if (name.equals("seq")) {
IList list = vf.list(Factory.Symbol);
Expression.List arg = (List) x.getArguments().get(0);
for (Expression y: arg.getElements()) {
list = list.append(y.accept(this));
}
return vf.constructor(Factory.Symbol_Seq, list);
}
if (name.equals("opt")) {
IConstructor arg = x.getArguments().get(0).accept(this);
return vf.constructor(Factory.Symbol_Opt, arg);
}
if (name.equals("alt")) {
ISet set = vf.set(Factory.Symbol);
Expression.Set arg = (Set) x.getArguments().get(0);
for(Expression y: arg.getElements()){
set = set.insert(y.accept(this));
}
return vf.constructor(Factory.Symbol_Alt, set);
}
if (name.equals("tuple")) {
java.util.List<Expression> args = x.getArguments();
IConstructor head = args.get(0).accept(this);
IList rest = vf.list(Factory.Symbol);
for (Expression arg: ((Expression.List)args.get(1)).getElements()) {
rest = rest.append(arg.accept(this));
}
return vf.constructor(Factory.Symbol_Tuple, head, rest);
}
if (name.equals("sort")) {
StringConstant.Lexical arg = (org.rascalmpl.ast.StringConstant.Lexical)
x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
String str = arg.getString();
str = str.substring(1, str.length() - 1);
return vf.constructor(Factory.Symbol_Sort, vf.string(str));
}
if (name.equals("layouts")) {
StringConstant.Lexical arg = (org.rascalmpl.ast.StringConstant.Lexical)
x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
String str = arg.getString();
str = str.substring(1, str.length() - 1);
return vf.constructor(Factory.Symbol_LayoutX, vf.string(str));
}
if (name.equals("iter")) {
IConstructor arg = x.getArguments().get(0).accept(this);
return vf.constructor(Factory.Symbol_IterPlus, arg);
}
if (name.equals("iter-star")) {
IConstructor arg = x.getArguments().get(0).accept(this);
return vf.constructor(Factory.Symbol_IterStar, arg);
}
if (name.equals("iter-star-seps")) {
IConstructor arg = x.getArguments().get(0).accept(this);
Expression.List args = (Expression.List) x.getArguments().get(1);
IList seps = vf.list(Factory.Args);
for (Expression elem: args.getElements()) {
seps = seps.append(elem.accept(this));
}
return vf.constructor(Factory.Symbol_IterStarSepX, arg, seps);
}
if (name.equals("iter-seps")) {
IConstructor arg = x.getArguments().get(0).accept(this);
Expression.List args = (Expression.List) x.getArguments().get(1);
IList seps = vf.list(Factory.Args);
for (Expression elem: args.getElements()) {
seps = seps.append(elem.accept(this));
}
return vf.constructor(Factory.Symbol_IterSepX, arg, seps);
}
if (name.equals("parameterized-sort")) {
java.util.List<Expression> args = x.getArguments();
StringConstant.Lexical sort = (org.rascalmpl.ast.StringConstant.Lexical)
x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
IList rest = vf.list(Factory.Symbol);
for (Expression arg: ((Expression.List)args.get(1)).getElements()) {
rest = rest.append(arg.accept(this));
}
return vf.constructor(Factory.Symbol_ParameterizedSort, vf.string(sort.getString()), rest);
}
if (name.equals("lit")) {
StringConstant.Lexical arg = (org.rascalmpl.ast.StringConstant.Lexical)
x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
// TODO: escaping etc.
return vf.constructor(Factory.Symbol_Lit, vf.string(arg.getString()));
}
if (name.equals("char-class")) {
java.util.List<Expression> args = x.getArguments();
IList ranges = vf.list(Factory.CharRange);
for (Expression arg: ((Expression.List)args.get(0)).getElements()) {
ranges = ranges.append(arg.accept(this));
}
return vf.constructor(Factory.Symbol_CharClass, ranges);
}
if (name.equals("single")) {
org.rascalmpl.ast.DecimalIntegerLiteral.Lexical arg1 = (org.rascalmpl.ast.DecimalIntegerLiteral.Lexical) x.getArguments().get(0).getLiteral().getIntegerLiteral().getDecimal();
IInteger num = vf.integer(java.lang.Integer.parseInt(arg1.getString()));
return vf.constructor(Factory.CharRange_Single, num);
}
if (name.equals("range")) {
org.rascalmpl.ast.DecimalIntegerLiteral.Lexical arg1 = (org.rascalmpl.ast.DecimalIntegerLiteral.Lexical) x.getArguments().get(0).getLiteral().getIntegerLiteral().getDecimal();
IInteger num1 = vf.integer(java.lang.Integer.parseInt(arg1.getString()));
org.rascalmpl.ast.DecimalIntegerLiteral.Lexical arg2 = (org.rascalmpl.ast.DecimalIntegerLiteral.Lexical) x.getArguments().get(1).getLiteral().getIntegerLiteral().getDecimal();
IInteger num2 = vf.integer(java.lang.Integer.parseInt(arg2.getString()));
return vf.constructor(Factory.CharRange_Range, num1, num2);
}
throw new ImplementationError("Non-IUPTR AST expression: " + name + ", " + x);
}