package org.metaborg.meta.lang.dynsem.interpreter.nodes.matching;

import org.metaborg.meta.lang.dynsem.interpreter.utils.SourceSectionUtil;
import org.spoofax.interpreter.core.Tools;
import org.spoofax.interpreter.terms.IStrategoAppl;
import org.spoofax.terms.util.NotImplementedException;

import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.source.SourceSection;

public abstract class LiteralMatchPattern extends MatchPattern {

	public LiteralMatchPattern(SourceSection source) {
		super(source);
	}

	public static LiteralMatchPattern create(IStrategoAppl t, FrameDescriptor fd) {
		SourceSection source = SourceSectionUtil.fromStrategoTerm(t);
		if(Tools.hasConstructor(t, "True",0)){
			return new TrueLiteralTermMatchPattern(source);
		}
		if(Tools.hasConstructor(t, "False",0)){
			return new FalseLiteralTermMatchPattern(source);
		}
		if(Tools.hasConstructor(t, "Int", 1)){
			return new IntLiteralTermMatchPattern(Tools.intAt(t, 0).intValue(), source);
		}
		if(Tools.hasConstructor(t, "String", 1)){
			return new StringLiteralTermMatchPattern(Tools.stringAt(t, 0).stringValue(), source);
		}
		
		throw new NotImplementedException("Unsupported literal: " + t);
	}
}

package org.metaborg.meta.lang.dynsem.interpreter.nodes.matching;

import org.metaborg.meta.lang.dynsem.interpreter.utils.SourceSectionUtil;
import org.spoofax.interpreter.core.Tools;
import org.spoofax.interpreter.terms.IStrategoAppl;
import org.spoofax.terms.util.NotImplementedException;

import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.source.SourceSection;

public abstract class LiteralMatchPattern extends MatchPattern {

	public LiteralMatchPattern(SourceSection source) {
		super(source);
	}

	public static LiteralMatchPattern create(IStrategoAppl t, FrameDescriptor fd) {
		SourceSection source = SourceSectionUtil.fromStrategoTerm(t);
		if (Tools.hasConstructor(t, "True", 0)) {
			return new TrueLiteralTermMatchPattern(source);
		}
		if (Tools.hasConstructor(t, "False", 0)) {
			return new FalseLiteralTermMatchPattern(source);
		}
		if (Tools.hasConstructor(t, "Int", 1)) {
			return new IntLiteralTermMatchPattern(Integer.parseInt(Tools.stringAt(t, 0).stringValue()), source);
		}
		if (Tools.hasConstructor(t, "String", 1)) {
			return new StringLiteralTermMatchPattern(Tools.stringAt(t, 0).stringValue(), source);
		}

		throw new NotImplementedException("Unsupported literal: " + t);
	}
}

Fix literal pattern matching creation to correctly convert integer literals in the specification which are encoded as strings.