*/
public TemplateAST parse(final Template template) throws ParseException {
Lexer lexer = null;
final Engine myEngine = template.engine;
final Resource resource = template.resource;
final TextStatementFactory textStatFactory = myEngine.getTextStatementFactory();
this.template = template;
this.engine = myEngine;
this.textStatementFactory = textStatFactory;
this.locateVarForce = !myEngine.isLooseVar();
this.nativeFactory = myEngine.getNativeFactory();
this.varmgr = new VariantManager(myEngine);
this.currentLabelIndex = 0;
this.labelsIndexMap.put(null, 0);
try {
//ISSUE: LexerProvider
lexer = new Lexer(resource.openReader());
lexer.setTrimCodeBlockBlankLine(myEngine.isTrimCodeBlockBlankLine());
if (resource instanceof ResourceOffset) {
lexer.setOffset((ResourceOffset) resource);
} else {
lexer.setOffset(0, 0);
}
textStatFactory.startTemplateParser(template);
return (TemplateAST) this.parse(lexer).value;
} catch (ParseException e) {
throw e;
} catch (Exception e) {
throw new ParseException(e);
} finally {
textStatFactory.finishTemplateParser(template);
if (lexer != null) {
try {
lexer.yyclose();
} catch (IOException ignore) {
}