Merge pull request #1131 from gagern/setStopToken

Set stop token in postamble
This commit is contained in:
Terence Parr 2016-03-30 16:43:07 +00:00
commit b05d86c150
1 changed files with 17 additions and 0 deletions

View File

@ -30,6 +30,7 @@
package org.antlr.v4.codegen;
import org.antlr.v4.codegen.model.Action;
import org.antlr.v4.codegen.model.CodeBlockForOuterMostAlt;
import org.antlr.v4.codegen.model.OutputModelObject;
import org.antlr.v4.codegen.model.RuleFunction;
@ -38,6 +39,9 @@ import org.antlr.v4.codegen.model.decl.CodeBlock;
import org.antlr.v4.codegen.model.decl.Decl;
import org.antlr.v4.tool.Alternative;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.Rule;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroup;
import java.util.ArrayList;
import java.util.Arrays;
@ -73,6 +77,19 @@ public abstract class DefaultOutputModelFactory extends BlankOutputModelFactory
return controller;
}
@Override
public List<SrcOp> rulePostamble(RuleFunction function, Rule r) {
// See OutputModelController.buildLeftRecursiveRuleFunction
// and Parser.exitRule for other places which set stop.
CodeGenerator gen = getGenerator();
STGroup codegenTemplates = gen.getTemplates();
ST setStopTokenAST = codegenTemplates.getInstanceOf("recRuleSetStopToken");
Action setStopTokenAction = new Action(this, function.ruleCtx, setStopTokenAST);
List<SrcOp> ops = new ArrayList<SrcOp>(1);
ops.add(setStopTokenAction);
return ops;
}
// Convenience methods