package compiler;

import grammar.ReceiptLexer;
import grammar.ReceiptParser;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;

/**
 *
 * @author Lucas
 */
public class Compiler {

    String in;
    String out;
    
    Compiler() {
        this("src/input/test.txt", "src/json/test.json");
    }

    Compiler(String in, String out) {
        try {
            if (in.isEmpty() || out.isEmpty()) {
                throw new IllegalArgumentException("Parameters in and/or out cannot be an empty String");
            }

            this.in = in;
            this.out = out;
        } catch (NullPointerException e) {
            throw new IllegalArgumentException(e.getMessage());
        }
    }

    /**
     * @param args the command line arguments
     * @throws java.lang.Exception
     */
    public static void main(String[] args) throws Exception {
        
        Compiler compiler;

        if (args.length == 2) {
            compiler = new Compiler(args[0], args[1]);
        } else {
            compiler = new Compiler();
        }

        compiler.start();
    }

    private void start() throws IOException {
        ANTLRInputStream inputStream = new ANTLRInputStream(new FileInputStream(in));
        
        ReceiptLexer   lexer = new ReceiptLexer(inputStream);
        ReceiptParser parser = new ReceiptParser(new CommonTokenStream(lexer));
        
        parser.receipt();
    }
}

@@ -14,16 +14,48 @@
 ler;%0D%0A%0D%0A
+import filehandler.JsonWriter;%0D%0A
 import g
@@ -181,46 +181,40 @@
 rt j
-ava.util.concurrent.ExecutionException
+son.infrastructure.JsonStructure
 ;%0D%0Ai
@@ -306,16 +306,47 @@
 Stream;%0D
+%0Aimport translator.Translator;%0D
 %0A%0D%0A/**%0D%0A
@@ -399,24 +399,32 @@
 er %7B%0D%0A%0D%0A    
+private 
 String in;%0D%0A
@@ -427,16 +427,24 @@
 n;%0D%0A    
+private 
 String o
@@ -512,20 +512,22 @@
 %22, %22src/
-json
+output
 /test.js
@@ -1119,26 +1119,16 @@
 tion %7B%0D%0A
-        %0D%0A
         
@@ -1384,32 +1384,135 @@
  IOException %7B%0D%0A
+        System.out.println(%22Compilation proccess has started. File being compiled: %22 + in);%0D%0A        %0D%0A
         ANTLRInp
@@ -1758,23 +1758,268 @@
     
-parser.receipt(
+JsonStructure tree = parser.receipt().e;%0D%0A        System.out.println(%22Parsing completed.%22);%0D%0A        %0D%0A        String result = new Translator(tree).run().export();%0D%0A        %0D%0A        new JsonWriter(out, result).export();%0D%0A        System.out.println(%22Finished!%22
 );%0D%0A

Update compiler