module GrammarSeparationTest;

import antlr.v4.runtime.ANTLRInputStream;
import antlr.v4.runtime.atn.ParserATNSimulator;
import antlr.v4.runtime.CommonToken;
import antlr.v4.runtime.CommonTokenStream;
import antlr.v4.runtime.LexerNoViableAltException;
import antlr.v4.runtime.Token;
import antlr.v4.runtime.tree.ParseTreeWalker;
import dshould : be, equal, not, should;
import dshould.thrown;
import RuleLexer;
import RuleParser;
import RuleWriter;
import RuleParserBaseListener;
import antlr.v4.runtime.Token;
import antlr.v4.runtime.atn.ParserATNSimulator;
import std.conv;
import std.file;
import std.stdio;
import unit_threaded;

@Tags("separation")
@("construct")
unittest {

    auto antlrInput =
        new ANTLRInputStream(File("unittest/separated_grammar/declaration.rule", "r"));
    auto lexer = new RuleLexer(antlrInput);
    auto cts = new CommonTokenStream(lexer);
    cts.fill;

    string s;
    int i;
    foreach (t; cts.getTokens) {
        s = cts.get(i++).to!string;
    }

    auto parser = new RuleParser(cts);
    parser.isTTS = true; // tts mode
    // Specify entry point
    auto rootContext = parser.file_input;
    parser.numberOfSyntaxErrors.should.equal(0);
    auto templateWalker = new ParseTreeWalker;
    auto templatesListener = new RuleParserBaseListener;
    auto writer = new RuleWriter;
    //templatesListener.writer = writer;
    templateWalker.walk(templatesListener, rootContext);
    // //writefln("edT = %s", templatesListener.externalDefinedTemplates);
}