/** Compile full template with respect to a list of formal args. */
        public virtual CompiledTemplate Compile(string srcName, string name, List<FormalArgument> args, string template, IToken templateToken)
        {
            ANTLRStringStream @is = new ANTLRStringStream(template, srcName);
            @is.name = srcName != null ? srcName : name;
            TemplateLexer lexer = null;
            if (templateToken != null && templateToken.Type == GroupParser.BIGSTRING_NO_NL)
            {
                lexer = new TemplateLexerNoNewlines(ErrorManager, @is, templateToken, DelimiterStartChar, DelimiterStopChar);
            }
            else
            {
                lexer = new TemplateLexer(ErrorManager, @is, templateToken, DelimiterStartChar, DelimiterStopChar);
            }

            CommonTokenStream tokens = new CommonTokenStream(lexer);
            TemplateParser p = new TemplateParser(tokens, ErrorManager, templateToken);
            IAstRuleReturnScope<CommonTree> r = null;
            try
            {
                r = p.templateAndEOF();
            }
            catch (RecognitionException re)
            {
                ReportMessageAndThrowTemplateException(tokens, templateToken, p, re);
                return null;
            }

            if (p.NumberOfSyntaxErrors > 0 || r.Tree == null)
            {
                CompiledTemplate impl = new CompiledTemplate();
                impl.DefineFormalArguments(args);
                return impl;
            }

            //System.out.println(((CommonTree)r.getTree()).toStringTree());
            CommonTreeNodeStream nodes = new CommonTreeNodeStream(r.Tree);
            nodes.TokenStream = tokens;
            CodeGenerator gen = new CodeGenerator(nodes, this, name, template, templateToken);

            CompiledTemplate impl2 = null;
            try
            {
                impl2 = gen.template(name, args);
                impl2.NativeGroup = Group;
                impl2.Template = template;
                impl2.Ast = r.Tree;
                impl2.Ast.SetUnknownTokenBoundaries();
                impl2.Tokens = tokens;
            }
            catch (RecognitionException re)
            {
                ErrorManager.InternalError(null, "bad tree structure", re);
            }

            return impl2;
        }
        /** Compile full template with respect to a list of formal args. */
        public virtual CompiledTemplate Compile(string srcName, string name, List <FormalArgument> args, string template, IToken templateToken)
        {
            ANTLRStringStream @is = new ANTLRStringStream(template, srcName);

            @is.name = srcName != null ? srcName : name;
            TemplateLexer lexer;

            if (templateToken != null && templateToken.Type == GroupParser.BIGSTRING_NO_NL)
            {
                lexer = new TemplateLexerNoNewlines(ErrorManager, @is, templateToken, DelimiterStartChar, DelimiterStopChar);
            }
            else
            {
                lexer = new TemplateLexer(ErrorManager, @is, templateToken, DelimiterStartChar, DelimiterStopChar);
            }

            CommonTokenStream tokens = new CommonTokenStream(lexer);
            TemplateParser    p      = new TemplateParser(tokens, ErrorManager, templateToken);
            IAstRuleReturnScope <CommonTree> r;

            try
            {
                r = p.templateAndEOF();
            }
            catch (RecognitionException re)
            {
                ReportMessageAndThrowTemplateException(tokens, templateToken, p, re);
                return(null);
            }

            if (p.NumberOfSyntaxErrors > 0 || r.Tree == null)
            {
                CompiledTemplate impl = new CompiledTemplate();
                impl.DefineFormalArguments(args);
                return(impl);
            }

            //System.out.println(((CommonTree)r.getTree()).toStringTree());
            CommonTreeNodeStream nodes = new CommonTreeNodeStream(r.Tree);

            nodes.TokenStream = tokens;
            CodeGenerator gen = new CodeGenerator(nodes, this, name, template, templateToken);

            CompiledTemplate impl2 = null;

            try
            {
                impl2             = gen.template(name, args);
                impl2.NativeGroup = Group;
                impl2.Template    = template;
                impl2.Ast         = r.Tree;
                impl2.Ast.SetUnknownTokenBoundaries();
                impl2.Tokens = tokens;
            }
            catch (RecognitionException re)
            {
                ErrorManager.InternalError(null, "bad tree structure", re);
            }

            return(impl2);
        }