
org.snapscript.tree.InstructionBuilder Maven / Gradle / Ivy
package org.snapscript.tree;
import java.util.HashMap;
import java.util.Map;
import org.snapscript.core.Context;
import org.snapscript.core.type.Type;
import org.snapscript.core.type.TypeLoader;
public class InstructionBuilder {
private final Instruction[] instructions;
private final Context context;
public InstructionBuilder(Context context) {
this.instructions = Instruction.values();
this.context = context;
}
public Map create() throws Exception{
Map table = new HashMap();
for(Instruction instruction : instructions){
Operation operation = create(instruction);
String grammar = instruction.getName();
table.put(grammar, operation);
}
return table;
}
private Operation create(Instruction instruction) throws Exception{
TypeLoader loader = context.getLoader();
Class value = instruction.getType();
Type type = loader.loadType(value);
String name = instruction.getName();
return new Operation(type, name);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy