.forEach(term -> {
term.setCode("()");
term.setReturnType("Unit");
});
Environment ntEnv = res.getGrammars().stream().map(res::getGrammar)
.flatMap(grm -> grm.getElementsOfType(CopperElementType.NON_TERMINAL).stream().map(grm::getGrammarElement))
.map(this::parseType).map(pair->(Pair<String, Type>)pair)
.collect(() -> new Reference<Environment>(Environment.getEmptyEnvironment()),
(env, elem) -> env.set(env.get().extend(new NameBindingImpl(elem.first(), elem.second()))),
(a, b) -> a.set(a.get().extend(b.get()))).get();
final Environment savedNtEnv = ntEnv;
ntEnv = res.getGrammars().stream().map(res::getGrammar)
.flatMap(grm -> grm.getElementsOfType(CopperElementType.TERMINAL).stream().map(grm::getGrammarElement))
.map(this::parseType).map(pair -> (Pair<String, Type>) pair)
.collect(() -> new Reference<Environment>(savedNtEnv),
(env, elem) -> env.set(env.get().extend(new NameBindingImpl(elem.first(), elem.second()))),
(a, b) -> a.set(a.get().extend(b.get()))).get();
HashMap<String, Pair<Type,SpliceBindExn>> toGen = new HashMap<>();
HashMap<String, TypedAST> toGenDefs = new HashMap<>();
Reference<Integer> methNum = new Reference<>(0);
String wyvClassName = res.getClassName();
String javaClassName = wyvClassName + "$java";
final Environment savedNtEnv2 = ntEnv;
res.getGrammars().stream().map(res::getGrammar)
.flatMap(grm->grm.getElementsOfType(CopperElementType.PRODUCTION).stream().map(grm::getGrammarElement).<Production>map(el->(Production)el))
.<Pair<Production, List<NameBinding>>>map(prod->new Pair<Production, List<NameBinding>>(prod, CopperTSL.<Type,String,Optional<NameBinding>>
zip(prod.getRhs().stream().map(cer->savedNtEnv2.lookup(cer.getName().toString()).getType()), prod.getRhsVarNames().stream(),
(type, name) -> (name == null)?Optional.empty():Optional.of(new NameBindingImpl(name, type)))
.<NameBinding>flatMap(o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty())
.collect(Collectors.<NameBinding>toList()))
).forEach(updateCode(toGen,ntEnv,methNum, res.getClassName()));