package org.metaborg.meta.interpreter.framework;

import org.spoofax.interpreter.core.Tools;
import org.spoofax.interpreter.terms.IStrategoAppl;
import org.spoofax.interpreter.terms.IStrategoTerm;
import org.spoofax.interpreter.terms.ITermFactory;

public class TermUtils {

	public static boolean boolFromTerm(IStrategoTerm term) {
		if (Tools.isTermAppl(term)) {
			IStrategoAppl tAppl = (IStrategoAppl) term;
			if (Tools.hasConstructor(tAppl, "$__DS_False__$", 0)) {
				return false;
			} else if (Tools.hasConstructor(tAppl, "$__DS_True__$", 0)) {
				return true;
			}
		}
		throw new RuntimeException("Malformed boolean: " + term);
	}

	public static IStrategoTerm termFromBool(boolean bV, ITermFactory factory) {
		return factory.makeAppl(factory.makeConstructor(bV ? "$__DS_True__$"
				: "$__DS_False__$", 0));
	}
}

@@ -437,25 +437,25 @@
 tor(tAppl, %22
-$
+_
 __DS_False__
@@ -450,25 +450,25 @@
 __DS_False__
-$
+_
 %22, 0)) %7B%0A%09%09%09
@@ -525,17 +525,17 @@
 tAppl, %22
-$
+_
 __DS_Tru
@@ -537,17 +537,17 @@
 S_True__
-$
+_
 %22, 0)) %7B
@@ -771,17 +771,17 @@
 r(bV ? %22
-$
+_
 __DS_Tru
@@ -783,17 +783,17 @@
 S_True__
-$
+_
 %22%0A%09%09%09%09: 
@@ -793,17 +793,17 @@
 %0A%09%09%09%09: %22
-$
+_
 __DS_Fal
@@ -810,9 +810,9 @@
 se__
-$
+_
 %22, 0

Fix incorrect ATerms being emitted for booleans