From e4a9a44671a007cb2904d71283b36da8f5fe2c51 Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Wed, 5 Sep 2012 18:37:28 -0700 Subject: [PATCH] grammar option cleanup. was a mess. -Doption=value works to override grammar options on cmd-line now. --- tool/playground/T.g | 13 ++---- tool/src/org/antlr/v4/Tool.java | 40 +++++++++++++++++++ .../LeftRecursiveRuleTransformer.java | 9 +++-- .../antlr/v4/automata/LexerATNFactory.java | 3 +- .../org/antlr/v4/codegen/CodeGenerator.java | 2 +- .../org/antlr/v4/codegen/model/SemPred.java | 2 +- .../antlr/v4/semantics/SemanticPipeline.java | 2 +- tool/src/org/antlr/v4/tool/ErrorType.java | 2 +- tool/src/org/antlr/v4/tool/Grammar.java | 7 ---- .../v4/tool/ast/GrammarASTWithOptions.java | 10 +++-- .../org/antlr/v4/tool/ast/GrammarRootAST.java | 32 ++++++++++----- 11 files changed, 82 insertions(+), 40 deletions(-) diff --git a/tool/playground/T.g b/tool/playground/T.g index 2e5b298a4..2554840ae 100644 --- a/tool/playground/T.g +++ b/tool/playground/T.g @@ -1,14 +1,7 @@ grammar T; -options -{ - output=AST; - backtrack=true; +options { + superClass=Z; } -Integer : '0' .. '9'; - - -myID : Integer*; - -public json : myID+ -> ^(myID); \ No newline at end of file +s : A ; diff --git a/tool/src/org/antlr/v4/Tool.java b/tool/src/org/antlr/v4/Tool.java index 05f99ee0c..e9b4512d9 100644 --- a/tool/src/org/antlr/v4/Tool.java +++ b/tool/src/org/antlr/v4/Tool.java @@ -73,7 +73,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; public class Tool { @@ -124,6 +126,7 @@ public class Tool { public boolean gen_listener = true; public boolean gen_visitor = false; public boolean abstract_recognizer = false; + public Map grammarOptions = null; public static Option[] optionDefs = { new Option("outputDirectory", "-o", OptionArgType.STRING, "specify output directory where all output is generated"), @@ -140,6 +143,8 @@ public class Tool { new Option("gen_visitor", "-visitor", "generate parse tree visitor"), new Option("gen_visitor", "-no-visitor", "don't generate parse tree visitor (default)"), new Option("abstract_recognizer", "-abstract", "generate abstract recognizer classes"), + new Option("-D