Fix documentation comments generated for labeled alternatives (fixes #543)

This commit is contained in:
Sam Harwell 2014-06-10 17:30:43 -05:00
parent fdc46c53e6
commit 00f95b4a29
3 changed files with 37 additions and 0 deletions

View File

@ -76,12 +76,22 @@ import org.antlr.v4.runtime.tree.ParseTreeListener;
public interface <file.grammarName>Listener extends ParseTreeListener {
<file.listenerNames:{lname |
/**
<if(file.listenerLabelRuleNames.(lname))>
* Enter a parse tree produced by the {@code <lname>\}
* labeled alternative in {@link <file.parserName>#<file.listenerLabelRuleNames.(lname)>\}.
<else>
* Enter a parse tree produced by {@link <file.parserName>#<lname>\}.
<endif>
* @param ctx the parse tree
*/
void enter<lname; format="cap">(@NotNull <file.parserName>.<lname; format="cap">Context ctx);
/**
<if(file.listenerLabelRuleNames.(lname))>
* Exit a parse tree produced by the {@code <lname>\}
* labeled alternative in {@link <file.parserName>#<file.listenerLabelRuleNames.(lname)>\}.
<else>
* Exit a parse tree produced by {@link <file.parserName>#<lname>\}.
<endif>
* @param ctx the parse tree
*/
void exit<lname; format="cap">(@NotNull <file.parserName>.<lname; format="cap">Context ctx);}; separator="\n">
@ -166,7 +176,12 @@ import org.antlr.v4.runtime.tree.ParseTreeVisitor;
public interface <file.grammarName>Visitor\<T> extends ParseTreeVisitor\<T> {
<file.visitorNames:{lname |
/**
<if(file.visitorLabelRuleNames.(lname))>
* Visit a parse tree produced by the {@code <lname>\}
* labeled alternative in {@link <file.parserName>#<file.visitorLabelRuleNames.(lname)>\}.
<else>
* Visit a parse tree produced by {@link <file.parserName>#<lname>\}.
<endif>
* @param ctx the parse tree
* @return the visitor result
*/

View File

@ -36,6 +36,7 @@ import org.antlr.v4.tool.Rule;
import org.antlr.v4.tool.ast.ActionAST;
import org.antlr.v4.tool.ast.AltAST;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -48,7 +49,16 @@ public class ListenerFile extends OutputFile {
public String genPackage; // from -package cmd-line
public String grammarName;
public String parserName;
/**
* The names of all listener contexts.
*/
public Set<String> listenerNames = new HashSet<String>();
/**
* For listener contexts created for a labeled outer alternative, maps from
* a listener context name to the name of the rule which defines the
* context.
*/
public Map<String, String> listenerLabelRuleNames = new HashMap<String, String>();
@ModelElement public Action header;
@ -62,6 +72,7 @@ public class ListenerFile extends OutputFile {
if ( labels!=null ) {
for (Map.Entry<String, List<Pair<Integer, AltAST>>> pair : labels.entrySet()) {
listenerNames.add(pair.getKey());
listenerLabelRuleNames.put(pair.getKey(), r.name);
}
}
else {

View File

@ -36,6 +36,7 @@ import org.antlr.v4.tool.Rule;
import org.antlr.v4.tool.ast.ActionAST;
import org.antlr.v4.tool.ast.AltAST;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -45,7 +46,16 @@ public class VisitorFile extends OutputFile {
public String genPackage; // from -package cmd-line
public String grammarName;
public String parserName;
/**
* The names of all rule contexts which may need to be visited.
*/
public Set<String> visitorNames = new HashSet<String>();
/**
* For rule contexts created for a labeled outer alternative, maps from
* a listener context name to the name of the rule which defines the
* context.
*/
public Map<String, String> visitorLabelRuleNames = new HashMap<String, String>();
@ModelElement public Action header;
@ -59,6 +69,7 @@ public class VisitorFile extends OutputFile {
if ( labels!=null ) {
for (Map.Entry<String, List<Pair<Integer, AltAST>>> pair : labels.entrySet()) {
visitorNames.add(pair.getKey());
visitorLabelRuleNames.put(pair.getKey(), r.name);
}
}
else {