package com.sleekbyte.tailor;

import com.sleekbyte.tailor.listeners.MainListener;
import com.sleekbyte.tailor.swift.SwiftLexer;
import com.sleekbyte.tailor.swift.SwiftParser;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import java.io.FileInputStream;
import java.io.IOException;

public class Tailor {

    public static void main(String[] args) {

        Options options = new Options();
        CommandLineParser cmdParser = new DefaultParser();
        try {

            CommandLine cmd = cmdParser.parse(options, args);
            FileInputStream inputStream = new FileInputStream(cmd.getArgs()[0]);
            SwiftLexer lexer = new SwiftLexer(new ANTLRInputStream(inputStream));
            CommonTokenStream stream = new CommonTokenStream(lexer);
            SwiftParser swiftParser = new SwiftParser(stream);
            SwiftParser.TopLevelContext tree = swiftParser.topLevel();
            MainListener listener = new MainListener();
            ParseTreeWalker walker = new ParseTreeWalker();

            walker.walk(listener, tree);

        } catch (ParseException | IOException e) {
            System.err.println("Parsing failed. Reason: " + e.getMessage());
        }

    }

}

@@ -72,24 +72,68 @@
 inListener;%0A
+import com.sleekbyte.tailor.output.Printer;%0A
 import com.s
@@ -390,200 +390,32 @@
 cli.
-CommandLine;%0Aimport org.apache.commons.cli.CommandLineParser;%0Aimport org.apache.commons.cli.DefaultParser;%0Aimport org.apache.commons.cli.Options;%0Aimport org.apache.commons.cli.ParseException;%0A
+*;%0A%0Aimport java.io.File;
 %0Aimp
@@ -718,16 +718,73 @@
  args);%0A
+            File inputFile = new File(cmd.getArgs()%5B0%5D);%0A
         
@@ -837,32 +837,25 @@
 tStream(
-cmd.getArgs()%5B0%5D
+inputFile
 );%0A     
@@ -1130,24 +1130,78 @@
 topLevel();%0A
+            Printer printer = new Printer(inputFile);%0A
             
@@ -1241,16 +1241,23 @@
 istener(
+printer
 );%0A     

Initialize printer in main