forked from jasder/antlr
weird. missed a few files. these are to simplify get filename functionality.
This commit is contained in:
parent
62badff2e8
commit
0799e838bb
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue