weird. missed a few files. these are to simplify get filename functionality.

This commit is contained in:
parrt 2016-11-05 09:32:04 -07:00
parent 62badff2e8
commit 0799e838bb
2 changed files with 60 additions and 6 deletions

View File

@ -1478,10 +1478,4 @@ initValue(typeName) ::= <<
<javaTypeInitMap.(typeName)>
>>
RecognizerFileName(name, type) ::= "<name; format={lower}>_<type; format={lower}>"
ListenerFileName(name) ::= "<name; format={lower}>_listener"
VisitorFileName(name) ::= "<name; format={lower}>_visitor"
BaseListenerFileName(name) ::= "<name; format={lower}>_base_listener"
BaseVisitorFileName(name) ::= "<name; format={lower}>_base_visitor"
codeFileExtension() ::= ".go"

View File

@ -2,6 +2,7 @@ package org.antlr.v4.codegen.target;
import org.antlr.v4.codegen.CodeGenerator;
import org.antlr.v4.codegen.Target;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.ast.GrammarAST;
import org.stringtemplate.v4.ST;
@ -134,6 +135,65 @@ public class GoTarget extends Target {
return result;
}
public String getRecognizerFileName(boolean header) {
CodeGenerator gen = getCodeGenerator();
Grammar g = gen.g;
assert g!=null;
String name;
switch ( g.getType()) {
case ANTLRParser.PARSER:
name = g.name.endsWith("Parser") ? g.name.substring(0, g.name.length()-6) : g.name;
return name.toLowerCase()+"_parser.go";
case ANTLRParser.LEXER:
name = g.name.endsWith("Lexer") ? g.name.substring(0, g.name.length()-5) : g.name; // trim off "lexer"
return name.toLowerCase()+"_lexer.go";
case ANTLRParser.COMBINED:
return g.name.toLowerCase()+"_parser.go";
default :
return "INVALID_FILE_NAME";
}
}
/** A given grammar T, return the listener name such as
* TListener.java, if we're using the Java target.
*/
public String getListenerFileName(boolean header) {
CodeGenerator gen = getCodeGenerator();
Grammar g = gen.g;
assert g.name != null;
return g.name.toLowerCase()+"_listener.go";
}
/** A given grammar T, return the visitor name such as
* TVisitor.java, if we're using the Java target.
*/
public String getVisitorFileName(boolean header) {
CodeGenerator gen = getCodeGenerator();
Grammar g = gen.g;
assert g.name != null;
return g.name.toLowerCase()+"_visitor.go";
}
/** A given grammar T, return a blank listener implementation
* such as TBaseListener.java, if we're using the Java target.
*/
public String getBaseListenerFileName(boolean header) {
CodeGenerator gen = getCodeGenerator();
Grammar g = gen.g;
assert g.name != null;
return g.name.toLowerCase()+"_base_listener.go";
}
/** A given grammar T, return a blank listener implementation
* such as TBaseListener.java, if we're using the Java target.
*/
public String getBaseVisitorFileName(boolean header) {
CodeGenerator gen = getCodeGenerator();
Grammar g = gen.g;
assert g.name != null;
return g.name.toLowerCase()+"_base_visitor.go";
}
protected static class JavaStringRenderer extends StringRenderer {
@Override