From 913bb717bdf926e2d3cf17f75dc07186052ad41c Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Sat, 22 Sep 2012 17:36:14 -0700 Subject: [PATCH] added -package option. --- tool/playground/A.g4 | 2 +- .../org/antlr/v4/tool/templates/codegen/Java/Java.stg | 8 ++++++++ tool/src/org/antlr/v4/Tool.java | 2 ++ tool/src/org/antlr/v4/codegen/model/LexerFile.java | 2 ++ tool/src/org/antlr/v4/codegen/model/ParserFile.java | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tool/playground/A.g4 b/tool/playground/A.g4 index 0f41e90ed..9b6b8ff9f 100644 --- a/tool/playground/A.g4 +++ b/tool/playground/A.g4 @@ -1,6 +1,6 @@ grammar A; -s : INT { System.out.println($ctx.getStart());} ; +s : INT { System.out.println($start.getText());} ; INT : [0-9]+ ; WS : [ \t\n]+ -> skip ; diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg index 8710dd2a5..2518e7813 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg @@ -14,7 +14,11 @@ javaTypeInitMap ::= [ ParserFile(file, parser, namedActions) ::= << // $ANTLR ANTLRVersion> generatedTimestamp> + +package ; + + import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; import org.antlr.v4.runtime.*; @@ -676,7 +680,11 @@ _prevctx.stop = _input.LT(-1); LexerFile(lexerFile, lexer, namedActions) ::= << // $ANTLR ANTLRVersion> generatedTimestamp> + +package ; + + import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.Token; diff --git a/tool/src/org/antlr/v4/Tool.java b/tool/src/org/antlr/v4/Tool.java index 0754e2c19..4bd5ca605 100644 --- a/tool/src/org/antlr/v4/Tool.java +++ b/tool/src/org/antlr/v4/Tool.java @@ -126,6 +126,7 @@ public class Tool { public boolean verbose_dfa = false; public boolean gen_listener = true; public boolean gen_visitor = false; + public String genPackage = null; public Map grammarOptions = null; public static Option[] optionDefs = { @@ -144,6 +145,7 @@ public class Tool { new Option("gen_listener", "-no-listener", "don't generate parse tree listener"), new Option("gen_visitor", "-visitor", "generate parse tree visitor"), new Option("gen_visitor", "-no-visitor", "don't generate parse tree visitor (default)"), + new Option("genPackage", "-package", OptionArgType.STRING, "specify a package/namespace for the generated code"), new Option("", "-D