use of jetbrick.template.parser.grammer.JetTemplateParser.Define_expression_listContext in project jetbrick-template-1x by subchen.
the class JetTemplateCodeVisitor method visitMacro_directive.
@Override
public Code visitMacro_directive(Macro_directiveContext ctx) {
String text = ctx.getChild(0).getText();
String name = text.substring(7, text.length() - 1).trim();
MacroCode macroCode = scopeCode.createMacroCode();
macroCode.setName(name);
scopeCode = macroCode.getMethodCode();
scopeCode.define(Code.CONTEXT_NAME, TypedKlass.JetContext);
// 处理参数
Define_expression_listContext define_expression_list = ctx.define_expression_list();
if (define_expression_list != null) {
SegmentListCode define_list_code = (SegmentListCode) define_expression_list.accept(this);
macroCode.setDefineListCode(define_list_code);
// 设置参数 Context
for (SegmentCode node : define_list_code.getChildren()) {
DefineExpressionCode c = (DefineExpressionCode) node;
scopeCode.define(c.getName(), c.getTypedKlass());
}
}
// 需要先定义 macro,这样可以支持 macro 的递归调用 (issue 102)
if (macroMap == null) {
macroMap = new HashMap<String, MacroCode>(8);
}
MacroCode old = macroMap.put(name, macroCode);
if (old != null) {
throw reportError("Duplicated macro defination " + name, ctx);
}
tcc.addMacro(macroCode);
// 访问 macro body
// add body content
scopeCode.setBodyCode(ctx.block().accept(this));
scopeCode = scopeCode.pop();
return Code.EMPTY;
}
Aggregations