/** 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);
@is.name = srcName != null ? srcName : name;
TemplateLexer lexer = new TemplateLexer(ErrorManager, @is, templateToken, DelimiterStartChar, DelimiterStopChar);
CommonTokenStream tokens = new CommonTokenStream(lexer);
TemplateParser p = new TemplateParser(tokens, ErrorManager, templateToken);
TemplateParser.templateAndEOF_return 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;
// only save tree/token stream when debugging
if (Group.Debug)
{
impl2.ast = (CommonTree)r.Tree;
impl2.ast.SetUnknownTokenBoundaries();
impl2.tokens = tokens;
}
}
catch (RecognitionException re)
{
ErrorManager.InternalError(null, "bad tree structure", re);
}
return(impl2);
}