Skip to content

Commit

Permalink
generate package for the listener and visitor files too
Browse files Browse the repository at this point in the history
  • Loading branch information
parrt committed Sep 23, 2012
1 parent 5f8645c commit 71276f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import java.util.ArrayList;
>>

ListenerFile(file, header) ::= <<
<if(file.genPackage)>
package <file.genPackage>;
<else>
<header>
<endif>
import org.antlr.v4.runtime.tree.*;
import org.antlr.v4.runtime.Token;

Expand All @@ -44,7 +48,11 @@ void exit<lname; format="cap">(<file.parserName>.<lname; format="cap">Context ct
>>

BaseListenerFile(file, header) ::= <<
<if(file.genPackage)>
package <file.genPackage>;
<else>
<header>
<endif>

import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
Expand All @@ -64,7 +72,11 @@ public class <file.grammarName>BaseListener implements <file.grammarName>Listene
>>

VisitorFile(file, header) ::= <<
<if(file.genPackage)>
package <file.genPackage>;
<else>
<header>
<endif>
import org.antlr.v4.runtime.tree.*;
import org.antlr.v4.runtime.Token;

Expand All @@ -75,7 +87,11 @@ T visit<lname; format="cap">(<file.parserName>.<lname; format="cap">Context ctx)
>>

BaseVisitorFile(file, header) ::= <<
<if(file.genPackage)>
package <file.genPackage>;
<else>
<header>
<endif>
import org.antlr.v4.runtime.tree.*;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.ParserRuleContext;
Expand Down
2 changes: 2 additions & 0 deletions tool/src/org/antlr/v4/codegen/model/ListenerFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* These are the rules specific events triggered by a parse tree visitor.
*/
public class ListenerFile extends OutputFile {
public String genPackage; // from -package cmd-line
public String grammarName;
public String parserName;
public Set<String> listenerNames = new HashSet<String>();
Expand All @@ -68,5 +69,6 @@ public ListenerFile(OutputModelFactory factory, String fileName) {
}
ActionAST ast = g.namedActions.get("header");
if ( ast!=null ) header = new Action(factory, ast);
genPackage = factory.getGrammar().tool.genPackage;
}
}
2 changes: 2 additions & 0 deletions tool/src/org/antlr/v4/codegen/model/VisitorFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
import java.util.Set;

public class VisitorFile extends OutputFile {
public String genPackage; // from -package cmd-line
public String grammarName;
public String parserName;
public Set<String> visitorNames = new HashSet<String>();
Expand All @@ -65,5 +66,6 @@ public VisitorFile(OutputModelFactory factory, String fileName) {
}
ActionAST ast = g.namedActions.get("header");
if ( ast!=null ) header = new Action(factory, ast);
genPackage = factory.getGrammar().tool.genPackage;
}
}

0 comments on commit 71276f7

Please sign in to comment.