org.snapscript.tree.InstructionBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
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 InstructionReader reader;
private final Context context;
public InstructionBuilder(Context context, String file) {
this.reader = new InstructionReader(file);
this.context = context;
}
public Map create() throws Exception{
Map table = new HashMap();
for(Instruction instruction : reader){
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();
String value = instruction.getType();
Type type = loader.loadType(value);
String name = instruction.getName();
return new Operation(type, name);
}
}