diff options
Diffstat (limited to 'tool/src')
27 files changed, 123 insertions, 106 deletions
diff --git a/tool/src/org/antlr/v4/analysis/AnalysisPipeline.java b/tool/src/org/antlr/v4/analysis/AnalysisPipeline.java index 5bd84be..a04ec31 100644 --- a/tool/src/org/antlr/v4/analysis/AnalysisPipeline.java +++ b/tool/src/org/antlr/v4/analysis/AnalysisPipeline.java @@ -100,7 +100,7 @@ public class AnalysisPipeline { } } - /** Return whether lookahead sets are disjoint; no lookahead => not disjoint */ + /** Return whether lookahead sets are disjoint; no lookahead ⇒ not disjoint */ public static boolean disjoint(IntervalSet[] altLook) { boolean collision = false; IntervalSet combined = new IntervalSet(); diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java index 5b6ba05..7a1d233 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java @@ -68,8 +68,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { public LinkedHashMap<Integer, LeftRecursiveRuleAltInfo> binaryAlts = new LinkedHashMap<Integer, LeftRecursiveRuleAltInfo>(); public LinkedHashMap<Integer, LeftRecursiveRuleAltInfo> ternaryAlts = new LinkedHashMap<Integer, LeftRecursiveRuleAltInfo>(); public LinkedHashMap<Integer, LeftRecursiveRuleAltInfo> suffixAlts = new LinkedHashMap<Integer, LeftRecursiveRuleAltInfo>(); - public List<LeftRecursiveRuleAltInfo> prefixAlts = new ArrayList<LeftRecursiveRuleAltInfo>(); - public List<LeftRecursiveRuleAltInfo> otherAlts = new ArrayList<LeftRecursiveRuleAltInfo>(); + public List<LeftRecursiveRuleAltInfo> prefixAndOtherAlts = new ArrayList<LeftRecursiveRuleAltInfo>(); /** Pointer to ID node of ^(= ID element) */ public List<Pair<GrammarAST,String>> leftRecursiveRuleRefLabels = @@ -188,7 +187,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { LeftRecursiveRuleAltInfo a = new LeftRecursiveRuleAltInfo(alt, altText, null, altLabel, false, originalAltTree); a.nextPrec = nextPrec; - prefixAlts.add(a); + prefixAndOtherAlts.add(a); //System.out.println("prefixAlt " + alt + ": " + altText + ", rewrite=" + rewriteText); } @@ -222,7 +221,9 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { String altLabel = altTree.altLabel!=null ? altTree.altLabel.getText() : null; LeftRecursiveRuleAltInfo a = new LeftRecursiveRuleAltInfo(alt, altText, null, altLabel, false, originalAltTree); - otherAlts.add(a); + // We keep other alts with prefix alts since they are all added to the start of the generated rule, and + // we want to retain any prior ordering between them + prefixAndOtherAlts.add(a); // System.out.println("otherAlt " + alt + ": " + altText); } @@ -254,8 +255,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { ruleST.add("opAlts", altST); } - ruleST.add("primaryAlts", prefixAlts); - ruleST.add("primaryAlts", otherAlts); + ruleST.add("primaryAlts", prefixAndOtherAlts); tool.log("left-recursion", ruleST.render()); @@ -330,7 +330,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { return lrlabel; } - /** Strip last 2 tokens if -> label; alter indexes in altAST */ + /** Strip last 2 tokens if → label; alter indexes in altAST */ public void stripAltLabel(GrammarAST altAST) { int start = altAST.getTokenStartIndex(); int stop = altAST.getTokenStopIndex(); @@ -439,8 +439,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { "binaryAlts=" + binaryAlts + ", ternaryAlts=" + ternaryAlts + ", suffixAlts=" + suffixAlts + - ", prefixAlts=" + prefixAlts + - ", otherAlts=" + otherAlts + + ", prefixAndOtherAlts=" +prefixAndOtherAlts+ '}'; } } diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java index ea67493..45cb517 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java @@ -168,8 +168,7 @@ public class LeftRecursiveRuleTransformer { // track recursive alt info for codegen r.recPrimaryAlts = new ArrayList<LeftRecursiveRuleAltInfo>(); - r.recPrimaryAlts.addAll(leftRecursiveRuleWalker.prefixAlts); - r.recPrimaryAlts.addAll(leftRecursiveRuleWalker.otherAlts); + r.recPrimaryAlts.addAll(leftRecursiveRuleWalker.prefixAndOtherAlts); if (r.recPrimaryAlts.isEmpty()) { tool.errMgr.grammarError(ErrorType.NO_NON_LR_ALTS, g.fileName, ((GrammarAST)r.ast.getChild(0)).getToken(), r.name); } @@ -244,9 +243,9 @@ public class LeftRecursiveRuleTransformer { * (ALT ID)) * (* (BLOCK * (OPTIONS ...) - * (ALT {7 >= $_p}? '*' (= b e) {$v = $a.v * $b.v;}) - * (ALT {6 >= $_p}? '+' (= b e) {$v = $a.v + $b.v;}) - * (ALT {3 >= $_p}? '++') (ALT {2 >= $_p}? '--')))))) + * (ALT {7 >= $_p}? '*' (= b e) {$v = $a.v * $b.v;}) + * (ALT {6 >= $_p}? '+' (= b e) {$v = $a.v + $b.v;}) + * (ALT {3 >= $_p}? '++') (ALT {2 >= $_p}? '--')))))) * </pre> */ public void setAltASTPointers(LeftRecursiveRule r, RuleAST t) { diff --git a/tool/src/org/antlr/v4/automata/ATNFactory.java b/tool/src/org/antlr/v4/automata/ATNFactory.java index aff2862..b1f61a8 100644 --- a/tool/src/org/antlr/v4/automata/ATNFactory.java +++ b/tool/src/org/antlr/v4/automata/ATNFactory.java @@ -93,7 +93,7 @@ public interface ATNFactory { /** For a non-lexer, just build a simple token reference atom. * For a lexer, a string is a sequence of char to match. That is, * "fog" is treated as 'f' 'o' 'g' not as a single transition in - * the DFA. Machine== o-'f'->o-'o'->o-'g'->o and has n+1 states + * the DFA. Machine== o-'f'->o-'o'->o-'g'->o and has n+1 states * for n characters. */ @@ -101,16 +101,16 @@ public interface ATNFactory { /** For reference to rule r, build * - * o-e->(r) o + * o-e->(r) o * * where (r) is the start of rule r and the trailing o is not linked * to from rule ref state directly (it's done thru the transition(0) * RuleClosureTransition. * * If the rule r is just a list of tokens, it's block will be just - * a set on an edge o->o->o-set->o->o->o, could inline it rather than doing + * a set on an edge o->o->o-set->o->o->o, could inline it rather than doing * the rule reference, but i'm not doing this yet as I'm not sure - * it would help much in the ATN->DFA construction. + * it would help much in the ATN->DFA construction. * * TODO add to codegen: collapse alt blks that are sets into single matchSet * @param node @@ -118,7 +118,7 @@ public interface ATNFactory { Handle ruleRef(GrammarAST node); - /** From an empty alternative build Grip o-e->o */ + /** From an empty alternative build Grip o-e->o */ Handle epsilon(GrammarAST node); @@ -143,13 +143,13 @@ public interface ATNFactory { /** From A|B|..|Z alternative block build * - * o->o-A->o->o (last ATNState is blockEndATNState pointed to by all alts) + * o->o-A->o->o (last ATNState is blockEndATNState pointed to by all alts) * | ^ - * o->o-B->o--| + * o->o-B->o--| * | | * ... | * | | - * o->o-Z->o--| + * o->o-Z->o--| * * So every alternative gets begin ATNState connected by epsilon * and every alt right side points at a block end ATNState. There is a @@ -160,7 +160,7 @@ public interface ATNFactory { * begin/end. * * Special case: if just a list of tokens/chars/sets, then collapse - * to a single edge'd o-set->o graph. + * to a single edge'd o-set->o graph. * * Set alt number (1..n) in the left-Transition ATNState. */ @@ -171,9 +171,9 @@ public interface ATNFactory { /** From (A)? build either: * - * o--A->o + * o--A->o * | ^ - * o---->| + * o---->| * * or, if A is a block, just add an empty alt to the end of the block */ @@ -184,7 +184,7 @@ public interface ATNFactory { * * |---| (Transition 2 from A.right points at alt 1) * v | (follow of loop is Transition 1) - * o->o-A-o->o + * o->o-A-o->o * * Meaning that the last ATNState in A points back to A's left Transition ATNState * and we add a new begin/end ATNState. A can be single alternative or @@ -200,7 +200,7 @@ public interface ATNFactory { * * |---| * v | - * o->o-A-o--o (Transition 2 from block end points at alt 1; follow is Transition 1) + * o->o-A-o--o (Transition 2 from block end points at alt 1; follow is Transition 1) * | ^ * o---------| (optional branch is 2nd alt of optional block containing A+) * diff --git a/tool/src/org/antlr/v4/automata/LexerATNFactory.java b/tool/src/org/antlr/v4/automata/LexerATNFactory.java index a5e80e4..8d16bd1 100644 --- a/tool/src/org/antlr/v4/automata/LexerATNFactory.java +++ b/tool/src/org/antlr/v4/automata/LexerATNFactory.java @@ -324,7 +324,7 @@ public class LexerATNFactory extends ParserATNFactory { /** For a lexer, a string is a sequence of char to match. That is, * "fog" is treated as 'f' 'o' 'g' not as a single transition in - * the DFA. Machine== o-'f'->o-'o'->o-'g'->o and has n+1 states + * the DFA. Machine== o-'f'->o-'o'->o-'g'->o and has n+1 states * for n characters. */ @Override diff --git a/tool/src/org/antlr/v4/automata/ParserATNFactory.java b/tool/src/org/antlr/v4/automata/ParserATNFactory.java index 3664111..d2114b4 100644 --- a/tool/src/org/antlr/v4/automata/ParserATNFactory.java +++ b/tool/src/org/antlr/v4/automata/ParserATNFactory.java @@ -286,7 +286,7 @@ public class ParserATNFactory implements ATNFactory { * For reference to rule {@code r}, build * * <pre> - * o->(r) o + * o->(r) o * </pre> * * where {@code (r)} is the start of rule {@code r} and the trailing @@ -391,24 +391,24 @@ public class ParserATNFactory implements ATNFactory { * From {@code A|B|..|Z} alternative block build * * <pre> - * o->o-A->o->o (last ATNState is BlockEndState pointed to by all alts) + * o->o-A->o->o (last ATNState is BlockEndState pointed to by all alts) * | ^ - * |->o-B->o--| + * |->o-B->o--| * | | * ... | * | | - * |->o-Z->o--| + * |->o-Z->o--| * </pre> * * So start node points at every alternative with epsilon transition and * every alt right side points at a block end ATNState. - * <p/> + * <p> * Special case: only one alternative: don't make a block with alt * begin/end. - * <p/> + * <p> * Special case: if just a list of tokens/chars/sets, then collapse to a - * single edged o-set->o graph. - * <p/> + * single edged o-set->o graph. + * <p> * TODO: Set alt number (1..n) in the states? */ @@ -506,9 +506,9 @@ public class ParserATNFactory implements ATNFactory { * From {@code (A)?} build either: * * <pre> - * o--A->o + * o--A->o * | ^ - * o---->| + * o---->| * </pre> * * or, if {@code A} is a block, just add an empty alt to the end of the @@ -535,7 +535,7 @@ public class ParserATNFactory implements ATNFactory { * <pre> * |---------| * v | - * [o-blk-o]->o->o + * [o-blk-o]->o->o * </pre> * * We add a decision for loop back node to the existing one at {@code blk} @@ -583,7 +583,7 @@ public class ParserATNFactory implements ATNFactory { * <pre> * |-------------| * v | - * o--[o-blk-o]->o o + * o--[o-blk-o]->o o * | ^ * -----------------| * </pre> diff --git a/tool/src/org/antlr/v4/codegen/ActionTranslator.java b/tool/src/org/antlr/v4/codegen/ActionTranslator.java index f1e5452..53a9a50 100644 --- a/tool/src/org/antlr/v4/codegen/ActionTranslator.java +++ b/tool/src/org/antlr/v4/codegen/ActionTranslator.java @@ -138,7 +138,7 @@ public class ActionTranslator implements ActionSplitterListener { ActionAST node) { String action = tokenWithinAction.getText(); - if ( action.charAt(0)=='{' ) { + if ( action!=null && action.length()>0 && action.charAt(0)=='{' ) { int firstCurly = action.indexOf('{'); int lastCurly = action.lastIndexOf('}'); if ( firstCurly>=0 && lastCurly>=0 ) { @@ -158,7 +158,7 @@ public class ActionTranslator implements ActionSplitterListener { translator.rf = rf; factory.getGrammar().tool.log("action-translator", "translate " + action); String altLabel = node.getAltLabel(); - if ( rf!=null ) { + if ( rf!=null ) { translator.nodeContext = rf.ruleCtx; if ( altLabel!=null ) translator.nodeContext = rf.altLabelCtxs.get(altLabel); } diff --git a/tool/src/org/antlr/v4/codegen/DefaultOutputModelFactory.java b/tool/src/org/antlr/v4/codegen/DefaultOutputModelFactory.java index 901e439..c8a1498 100644 --- a/tool/src/org/antlr/v4/codegen/DefaultOutputModelFactory.java +++ b/tool/src/org/antlr/v4/codegen/DefaultOutputModelFactory.java @@ -30,6 +30,7 @@ package org.antlr.v4.codegen; +import org.antlr.v4.codegen.model.Action; import org.antlr.v4.codegen.model.CodeBlockForOuterMostAlt; import org.antlr.v4.codegen.model.OutputModelObject; import org.antlr.v4.codegen.model.RuleFunction; @@ -38,6 +39,9 @@ import org.antlr.v4.codegen.model.decl.CodeBlock; import org.antlr.v4.codegen.model.decl.Decl; import org.antlr.v4.tool.Alternative; import org.antlr.v4.tool.Grammar; +import org.antlr.v4.tool.Rule; +import org.stringtemplate.v4.ST; +import org.stringtemplate.v4.STGroup; import java.util.ArrayList; import java.util.Arrays; @@ -73,6 +77,22 @@ public abstract class DefaultOutputModelFactory extends BlankOutputModelFactory return controller; } + @Override + public List<SrcOp> rulePostamble(RuleFunction function, Rule r) { + if ( r.namedActions.containsKey("after") || r.namedActions.containsKey("finally") ) { + // See OutputModelController.buildLeftRecursiveRuleFunction + // and Parser.exitRule for other places which set stop. + CodeGenerator gen = getGenerator(); + STGroup codegenTemplates = gen.getTemplates(); + ST setStopTokenAST = codegenTemplates.getInstanceOf("recRuleSetStopToken"); + Action setStopTokenAction = new Action(this, function.ruleCtx, setStopTokenAST); + List<SrcOp> ops = new ArrayList<SrcOp>(1); + ops.add(setStopTokenAction); + return ops; + } + return super.rulePostamble(function, r); + } + // Convenience methods diff --git a/tool/src/org/antlr/v4/codegen/OutputModelWalker.java b/tool/src/org/antlr/v4/codegen/OutputModelWalker.java index 8a03895..486efd1 100644 --- a/tool/src/org/antlr/v4/codegen/OutputModelWalker.java +++ b/tool/src/org/antlr/v4/codegen/OutputModelWalker.java @@ -53,7 +53,7 @@ import java.util.Set; * We identify those nested objects by the list of arguments in the template * definition. For example, here is the definition of the parser template: * - * Parser(parser, scopes, funcs) ::= <<...>> + * Parser(parser, scopes, funcs) ::= <<...>> * * The first template argument is always the output model object from which * this walker will create the template. Any other arguments identify diff --git a/tool/src/org/antlr/v4/codegen/Target.java b/tool/src/org/antlr/v4/codegen/Target.java index 1f2d748..3d4a93a 100644 --- a/tool/src/org/antlr/v4/codegen/Target.java +++ b/tool/src/org/antlr/v4/codegen/Target.java @@ -56,7 +56,7 @@ public abstract class Target { * predicates and such that may refer to chars that need to be escaped * when represented as strings. Also, templates need to be escaped so * that the target language can hold them as a string. - * <p/> + * <p> * I have defined (via the constructor) the set of typical escapes, * but your {@link Target} subclass is free to alter the translated chars * or add more definitions. This is non-static so each target can have diff --git a/tool/src/org/antlr/v4/codegen/model/ParserFile.java b/tool/src/org/antlr/v4/codegen/model/ParserFile.java index 28ef200..808d4f9 100644 --- a/tool/src/org/antlr/v4/codegen/model/ParserFile.java +++ b/tool/src/org/antlr/v4/codegen/model/ParserFile.java @@ -31,6 +31,8 @@ package org.antlr.v4.codegen.model; import org.antlr.v4.codegen.OutputModelFactory; +import org.antlr.v4.codegen.model.chunk.ActionChunk; +import org.antlr.v4.codegen.model.chunk.ActionText; import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.ast.ActionAST; @@ -42,10 +44,11 @@ public class ParserFile extends OutputFile { public String genPackage; // from -package cmd-line @ModelElement public Parser parser; @ModelElement public Map<String, Action> namedActions; + @ModelElement public ActionChunk contextSuperClass; public Boolean genListener = false; public Boolean genVisitor = false; public String grammarName; - + public ParserFile(OutputModelFactory factory, String fileName) { super(factory, fileName); Grammar g = factory.getGrammar(); @@ -59,5 +62,9 @@ public class ParserFile extends OutputFile { genListener = g.tool.gen_listener; genVisitor = g.tool.gen_visitor; grammarName = g.name; + + if (g.getOptionString("contextSuperClass") != null) { + contextSuperClass = new ActionText(null, g.getOptionString("contextSuperClass")); + } } } diff --git a/tool/src/org/antlr/v4/codegen/model/decl/AltLabelStructDecl.java b/tool/src/org/antlr/v4/codegen/model/decl/AltLabelStructDecl.java index 5d49625..f48f45d 100644 --- a/tool/src/org/antlr/v4/codegen/model/decl/AltLabelStructDecl.java +++ b/tool/src/org/antlr/v4/codegen/model/decl/AltLabelStructDecl.java @@ -38,7 +38,7 @@ import org.antlr.v4.tool.Rule; import java.util.ArrayList; -/** A StructDecl to handle a -> label on alt */ +/** A StructDecl to handle a -> label on alt */ public class AltLabelStructDecl extends StructDecl { public int altNum; public AltLabelStructDecl(OutputModelFactory factory, Rule r, diff --git a/tool/src/org/antlr/v4/codegen/target/CSharpTarget.java b/tool/src/org/antlr/v4/codegen/target/CSharpTarget.java index bfebe4b..b4aa584 100644 --- a/tool/src/org/antlr/v4/codegen/target/CSharpTarget.java +++ b/tool/src/org/antlr/v4/codegen/target/CSharpTarget.java @@ -51,7 +51,7 @@ public class CSharpTarget extends Target { @Override public String getVersion() { - return "4.5.2"; // crossing fingers that it's close enough. + return "4.5.3"; } @Override diff --git a/tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java b/tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java index 71926ac..9648376 100644 --- a/tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java +++ b/tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java @@ -74,7 +74,7 @@ public class JavaScriptTarget extends Target { @Override public String getVersion() { - return "4.5.2"; + return "4.5.3"; } public Set<String> getBadWords() { @@ -93,11 +93,11 @@ public class JavaScriptTarget extends Target { /** * {@inheritDoc} - * <p/> + * <p> * For Java, this is the translation {@code 'a\n"'} → {@code "a\n\""}. * Expect single quotes around the incoming literal. Just flip the quotes * and replace double quotes with {@code \"}. - * <p/> + * <p> * Note that we have decided to allow people to use '\"' without penalty, so * we must build the target string in a loop as {@link String#replace} * cannot handle both {@code \"} and {@code "} without a lot of messing diff --git a/tool/src/org/antlr/v4/codegen/target/Python2Target.java b/tool/src/org/antlr/v4/codegen/target/Python2Target.java index efa5d2c..c80949a 100644 --- a/tool/src/org/antlr/v4/codegen/target/Python2Target.java +++ b/tool/src/org/antlr/v4/codegen/target/Python2Target.java @@ -50,7 +50,7 @@ public class Python2Target extends Target { "abs", "all", "any", "apply", "as", "bin", "bool", "buffer", "bytearray", "callable", "chr", "classmethod", "coerce", "compile", "complex", - "delattr", "dict", "dir", "divmod", + "del", "delattr", "dict", "dir", "divmod", "enumerate", "eval", "execfile", "file", "filter", "float", "format", "frozenset", "getattr", "globals", @@ -61,7 +61,7 @@ public class Python2Target extends Target { "memoryview", "object", "oct", "open", "ord", "pow", "print", "property", - "range", "raw_input", "reduce", "reload", "repr", "reversed", "round", + "range", "raw_input", "reduce", "reload", "repr", "return", "reversed", "round", "set", "setattr", "slice", "sorted", "staticmethod", "str", "sum", "super", "tuple", "type", "unichr", "unicode", @@ -117,7 +117,7 @@ public class Python2Target extends Target { @Override public String getVersion() { - return "4.5.2.1"; + return "4.5.3"; } public Set<String> getBadWords() { diff --git a/tool/src/org/antlr/v4/codegen/target/Python3Target.java b/tool/src/org/antlr/v4/codegen/target/Python3Target.java index 68d7a16..f70d2a2 100644 --- a/tool/src/org/antlr/v4/codegen/target/Python3Target.java +++ b/tool/src/org/antlr/v4/codegen/target/Python3Target.java @@ -50,7 +50,7 @@ public class Python3Target extends Target { "abs", "all", "any", "apply", "as", "bin", "bool", "buffer", "bytearray", "callable", "chr", "classmethod", "coerce", "compile", "complex", - "delattr", "dict", "dir", "divmod", + "del", "delattr", "dict", "dir", "divmod", "enumerate", "eval", "execfile", "file", "filter", "float", "format", "frozenset", "getattr", "globals", @@ -61,7 +61,7 @@ public class Python3Target extends Target { "memoryview", "object", "oct", "open", "ord", "pow", "print", "property", - "range", "raw_input", "reduce", "reload", "repr", "reversed", "round", + "range", "raw_input", "reduce", "reload", "repr", "return", "reversed", "round", "set", "setattr", "slice", "sorted", "staticmethod", "str", "sum", "super", "tuple", "type", "unichr", "unicode", @@ -119,7 +119,7 @@ public class Python3Target extends Target { @Override public String getVersion() { - return "4.5.2.1"; + return "4.5.3"; } /** Avoid grammar symbols in this set to prevent conflicts in gen'd code. */ diff --git a/tool/src/org/antlr/v4/misc/Graph.java b/tool/src/org/antlr/v4/misc/Graph.java index 2509c81..a7c63d5 100644 --- a/tool/src/org/antlr/v4/misc/Graph.java +++ b/tool/src/org/antlr/v4/misc/Graph.java @@ -81,7 +81,7 @@ public class Graph<T> { * For sorting, I'm not following convention here since ANTLR * needs the opposite. Here's what I assume for sorting: * - * If there exists an edge u -> v then u depends on v and v + * If there exists an edge u -> v then u depends on v and v * must happen before u. * * So if this gives nonreversed postorder traversal, I get the order @@ -114,4 +114,4 @@ public class Graph<T> { } sorted.add(n.payload); } -}
\ No newline at end of file +} diff --git a/tool/src/org/antlr/v4/misc/Utils.java b/tool/src/org/antlr/v4/misc/Utils.java index c62003c..6d63b7c 100644 --- a/tool/src/org/antlr/v4/misc/Utils.java +++ b/tool/src/org/antlr/v4/misc/Utils.java @@ -54,21 +54,6 @@ public class Utils { static Integer[] ints = new Integer[INTEGER_POOL_MAX_VALUE+1]; - /** Integer objects are immutable so share all Integers with the - * same value up to some max size. Use an array as a perfect hash. - * Return shared object for 0..INTEGER_POOL_MAX_VALUE or a new - * Integer object with x in it. Java's autoboxing only caches up to 127. - public static Integer integer(int x) { - if ( x<0 || x>INTEGER_POOL_MAX_VALUE ) { - return new Integer(x); - } - if ( ints[x]==null ) { - ints[x] = new Integer(x); - } - return ints[x]; - } - */ - public static String stripFileExtension(String name) { if ( name==null ) return null; int lastDot = name.lastIndexOf('.'); diff --git a/tool/src/org/antlr/v4/parse/GrammarToken.java b/tool/src/org/antlr/v4/parse/GrammarToken.java index 4d849bf..3e7e190 100644 --- a/tool/src/org/antlr/v4/parse/GrammarToken.java +++ b/tool/src/org/antlr/v4/parse/GrammarToken.java @@ -35,7 +35,7 @@ import org.antlr.runtime.Token; import org.antlr.v4.tool.Grammar; /** A CommonToken that can also track it's original location, - * derived from options on the element ref like BEGIN<line=34,...>. + * derived from options on the element ref like BEGIN<line=34,...>. */ public class GrammarToken extends CommonToken { public Grammar g; diff --git a/tool/src/org/antlr/v4/parse/ScopeParser.java b/tool/src/org/antlr/v4/parse/ScopeParser.java index a0ce182..743fe98 100644 --- a/tool/src/org/antlr/v4/parse/ScopeParser.java +++ b/tool/src/org/antlr/v4/parse/ScopeParser.java @@ -52,11 +52,15 @@ import java.util.List; public class ScopeParser { /** Given an arg or retval scope definition list like * - * Map<String, String>, int[] j3, char *foo32[3] + * <code> + * Map<String, String>, int[] j3, char *foo32[3] + * </code> * * or * + * <code> * int i=3, j=a[34]+20 + * </code> * * convert to an attribute scope. */ diff --git a/tool/src/org/antlr/v4/tool/AttributeDict.java b/tool/src/org/antlr/v4/tool/AttributeDict.java index 911170d..e8d487f 100644 --- a/tool/src/org/antlr/v4/tool/AttributeDict.java +++ b/tool/src/org/antlr/v4/tool/AttributeDict.java @@ -39,7 +39,7 @@ import java.util.LinkedHashMap; import java.util.Set; /** Track the attributes within retval, arg lists etc... - * <p/> + * <p> * Each rule has potentially 3 scopes: return values, * parameters, and an implicitly-named scope (i.e., a scope defined in a rule). * Implicitly-defined scopes are named after the rule; rules and scopes then diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index 0fedfc4..32bb574 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -34,12 +34,12 @@ import org.antlr.v4.runtime.Lexer; /** * A complex enumeration of all the error messages that the tool can issue. - * <p/> + * <p> * When adding error messages, also add a description of the message to the * Wiki with a location under the Wiki page * <a href="http://www.antlr.org/wiki/display/ANTLR4/Errors+Reported+by+the+ANTLR+Tool">Errors Reported by the ANTLR Tool</a>. * - * @author Jim Idle <jimi@temporal-wave.com>, Terence Parr + * @author Jim Idle <jimi@temporal-wave.com>, Terence Parr * @since 4.0 */ public enum ErrorType { @@ -702,8 +702,8 @@ public enum ErrorType { * <p>The following rule produces this error.</p> * * <pre> - * X : 'foo' -> type(Foo); // ok - * Y : 'foo' -> token(Foo); // error 149 (token is not a supported lexer command) + * X : 'foo' -> type(Foo); // ok + * Y : 'foo' -> token(Foo); // error 149 (token is not a supported lexer command) * </pre> * * @since 4.1 @@ -719,8 +719,8 @@ public enum ErrorType { * <p>The following rule produces this error.</p> * * <pre> - * X : 'foo' -> type(Foo); // ok - * Y : 'foo' -> type; // error 150 (the type command requires an argument) + * X : 'foo' -> type(Foo); // ok + * Y : 'foo' -> type; // error 150 (the type command requires an argument) * </pre> * * @since 4.1 @@ -737,8 +737,8 @@ public enum ErrorType { * <p>The following rule produces this error.</p> * * <pre> - * X : 'foo' -> popMode; // ok - * Y : 'foo' -> popMode(A); // error 151 (the popMode command does not take an argument) + * X : 'foo' -> popMode; // ok + * Y : 'foo' -> popMode(A); // error 151 (the popMode command does not take an argument) * </pre> * * @since 4.1 @@ -825,8 +825,8 @@ public enum ErrorType { * public static final int CUSTOM = HIDDEN + 1; * } * - * X : 'foo' -> channel(HIDDEN); // ok - * Y : 'bar' -> channel(CUSTOM); // warning 155 + * X : 'foo' -> channel(HIDDEN); // ok + * Y : 'bar' -> channel(CUSTOM); // warning 155 * </pre> * * @since 4.2 @@ -891,12 +891,12 @@ public enum ErrorType { * <p>The following rule produces this warning.</p> * * <pre> - * X1 : 'x' -> more // ok + * X1 : 'x' -> more // ok * ; * Y1 : 'x' {more();} // ok * ; * fragment - * X2 : 'x' -> more // warning 158 + * X2 : 'x' -> more // warning 158 * ; * fragment * Y2 : 'x' {more();} // warning 158 diff --git a/tool/src/org/antlr/v4/tool/Grammar.java b/tool/src/org/antlr/v4/tool/Grammar.java index 5632ab4..89e2a26 100644 --- a/tool/src/org/antlr/v4/tool/Grammar.java +++ b/tool/src/org/antlr/v4/tool/Grammar.java @@ -101,6 +101,7 @@ public class Grammar implements AttributeResolver { public static final Set<String> parserOptions = new HashSet<String>(); static { parserOptions.add("superClass"); + parserOptions.add("contextSuperClass"); parserOptions.add("TokenLabelType"); parserOptions.add("tokenVocab"); parserOptions.add("language"); @@ -114,14 +115,14 @@ public class Grammar implements AttributeResolver { public static final Set<String> LexerBlockOptions = new HashSet<String>(); - /** Legal options for rule refs like id<key=value> */ + /** Legal options for rule refs like id<key=value> */ public static final Set<String> ruleRefOptions = new HashSet<String>(); static { ruleRefOptions.add(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME); ruleRefOptions.add(LeftRecursiveRuleTransformer.TOKENINDEX_OPTION_NAME); } - /** Legal options for terminal refs like ID<assoc=right> */ + /** Legal options for terminal refs like ID<assoc=right> */ public static final Set<String> tokenOptions = new HashSet<String>(); static { tokenOptions.add("assoc"); @@ -553,15 +554,6 @@ public class Grammar implements AttributeResolver { public List<Grammar> getImportedGrammars() { return importedGrammars; } - /** Get delegates below direct delegates of g - public List<Grammar> getIndirectDelegates(Grammar g) { - List<Grammar> direct = getDirectDelegates(g); - List<Grammar> delegates = getDelegates(g); - delegates.removeAll(direct); - return delegates; - } -*/ - public LexerGrammar getImplicitLexer() { return implicitLexer; } diff --git a/tool/src/org/antlr/v4/tool/GrammarInterpreterRuleContext.java b/tool/src/org/antlr/v4/tool/GrammarInterpreterRuleContext.java index 8457a6a..936b8dc 100644 --- a/tool/src/org/antlr/v4/tool/GrammarInterpreterRuleContext.java +++ b/tool/src/org/antlr/v4/tool/GrammarInterpreterRuleContext.java @@ -54,4 +54,15 @@ public class GrammarInterpreterRuleContext extends InterpreterRuleContext { public void setOuterAltNum(int outerAltNum) { this.outerAltNum = outerAltNum; } + + @Override + public int getAltNumber() { + // override here and called old functionality; makes it backward compatible vs changing names + return getOuterAltNum(); + } + + @Override + public void setAltNumber(int altNumber) { + setOuterAltNum(altNumber); + } } diff --git a/tool/src/org/antlr/v4/tool/GrammarParserInterpreter.java b/tool/src/org/antlr/v4/tool/GrammarParserInterpreter.java index 9361b40..1e77d57 100644 --- a/tool/src/org/antlr/v4/tool/GrammarParserInterpreter.java +++ b/tool/src/org/antlr/v4/tool/GrammarParserInterpreter.java @@ -151,7 +151,7 @@ public class GrammarParserInterpreter extends ParserInterpreter { * it's simple. Set decisionStatesThatSetOuterAltNumInContext * indicates which decision states should set the outer alternative number. * - * Left recursive rules are much more complicated to deal with: + * <p>Left recursive rules are much more complicated to deal with: * there is typically a decision for the primary alternatives and a * decision to choose between the recursive operator alternatives. * For example, the following left recursive rule has two primary and 2 diff --git a/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java b/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java index 6759e20..9668838 100644 --- a/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java +++ b/tool/src/org/antlr/v4/tool/GrammarTransformPipeline.java @@ -166,11 +166,11 @@ public class GrammarTransformPipeline { /** Merge all the rules, token definitions, and named actions from imported grammars into the root grammar tree. Perform: - (tokens { X (= Y 'y')) + (tokens { Z ) -> (tokens { X (= Y 'y') Z) + (tokens { X (= Y 'y')) + (tokens { Z ) -> (tokens { X (= Y 'y') Z) - (@ members {foo}) + (@ members {bar}) -> (@ members {foobar}) + (@ members {foo}) + (@ members {bar}) -> (@ members {foobar}) - (RULES (RULE x y)) + (RULES (RULE z)) -> (RULES (RULE x y z)) + (RULES (RULE x y)) + (RULES (RULE z)) -> (RULES (RULE x y z)) Rules in root prevent same rule from being appended to RULES node. @@ -322,7 +322,7 @@ public class GrammarTransformPipeline { * We'll have this Grammar share token symbols later; don't generate * tokenVocab or tokens{} section. Copy over named actions. * - * Side-effects: it removes children from GRAMMAR & RULES nodes + * Side-effects: it removes children from GRAMMAR & RULES nodes * in combined AST. Anything cut out is dup'd before * adding to lexer to avoid "who's ur daddy" issues */ diff --git a/tool/src/org/antlr/v4/tool/LeftRecursiveRule.java b/tool/src/org/antlr/v4/tool/LeftRecursiveRule.java index 1d3b990..ad06e34 100644 --- a/tool/src/org/antlr/v4/tool/LeftRecursiveRule.java +++ b/tool/src/org/antlr/v4/tool/LeftRecursiveRule.java @@ -136,7 +136,7 @@ public class LeftRecursiveRule extends Rule { return alts; } - /** Get -> labels from those alts we deleted for left-recursive rules. */ + /** Get -> labels from those alts we deleted for left-recursive rules. */ @Override public Map<String, List<Pair<Integer, AltAST>>> getAltLabels() { Map<String, List<Pair<Integer, AltAST>>> labels = new HashMap<String, List<Pair<Integer, AltAST>>>(); |