package com.github.davidmoten.asn1;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;

import com.github.davidmoten.asn1.Asn1Parser.moduleDefinitions_return;

public class Compiler {

	private final List<File> files;

	public Compiler(List<File> files) {
		this.files = files;
	}

	public void compile() {
		for (File file : files) {
			try {
				CharStream s = new ANTLRFileStream(file.getPath());

				Asn1Lexer lexer = new Asn1Lexer(s);
				CommonTokenStream tokens = new CommonTokenStream(lexer);

				Asn1Parser parser = new Asn1Parser(tokens);
				for (String token : parser.getTokenNames()) {
					System.out.println(token);
				}
				moduleDefinitions_return defs = parser.moduleDefinitions();
			} catch (IOException e) {
				throw new RuntimeException(e);
			} catch (RecognitionException e) {
				throw new RuntimeException(e);
			}
		}
	}
}

@@ -79,16 +79,101 @@
 eption;%0A
+import java.lang.reflect.InvocationTargetException;%0Aimport java.lang.reflect.Method;%0A
 import j
@@ -314,127 +314,8 @@
 eam;
-%0Aimport org.antlr.runtime.RecognitionException;%0A%0Aimport com.github.davidmoten.asn1.Asn1Parser.moduleDefinitions_return;
 %0A%0Apu
@@ -799,65 +799,358 @@
 %09%09%09%09
-moduleDefinitions_return defs = parser.moduleDefini
+process(parser.getClass(), parser);%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09throw new RuntimeException(e);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09private %3CT%3E void process(Class%3C? extends T%3E cls, T object) %7B%0A%09%09for (Method method : cls.getDeclaredMethods()) %7B%0A%09%09%09try %7B%0A%09%09%09%09Object result = method.invoke(object);%0A%09%09%09%7D catch (IllegalAccessException e) %7B%0A%09%09%09%09throw new RuntimeExcep
 tion
-s
 (
+e
 );%0A%09
@@ -1153,33 +1153,46 @@
 );%0A%09%09%09%7D catch (I
-O
+llegalArgument
 Exception e) %7B%0A%09
@@ -1241,19 +1241,24 @@
 ch (
-Recognition
+InvocationTarget
 Exce

add reflection utils