diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/Chunk.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/Chunk.java new file mode 100644 index 000000000..c3fb00930 --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/Chunk.java @@ -0,0 +1,6 @@ +package org.antlr.v4.runtime.tree.pattern; + +class Chunk { + public Chunk() { + } +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/Match.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/Match.java new file mode 100644 index 000000000..7e390fe11 --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/Match.java @@ -0,0 +1,11 @@ +package org.antlr.v4.runtime.tree.pattern; + +import org.antlr.v4.runtime.misc.Pair; +import org.antlr.v4.runtime.tree.ParseTree; + +import java.util.List; + +public class Match { + protected ParseTree subtree; + protected List> labels; +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/MatchIterator.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/MatchIterator.java new file mode 100644 index 000000000..2c89f72d7 --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/MatchIterator.java @@ -0,0 +1,19 @@ +package org.antlr.v4.runtime.tree.pattern; + +import java.util.Iterator; + +public class MatchIterator implements Iterator { + @Override + public boolean hasNext() { + return false; + } + + @Override + public Match next() { + return null; + } + + @Override + public void remove() { + } +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreePatternErrorStrategy.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternErrorStrategy.java similarity index 98% rename from runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreePatternErrorStrategy.java rename to runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternErrorStrategy.java index 97778246e..b83fae43b 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreePatternErrorStrategy.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternErrorStrategy.java @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.antlr.v4.runtime.tree; +package org.antlr.v4.runtime.tree.pattern; import org.antlr.v4.runtime.DefaultErrorStrategy; import org.antlr.v4.runtime.Parser; diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreePatternLexer.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternLexer.java similarity index 97% rename from runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreePatternLexer.java rename to runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternLexer.java index c5e00722f..32810d3c0 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreePatternLexer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternLexer.java @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.antlr.v4.runtime.tree; +package org.antlr.v4.runtime.tree.pattern; import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.Token; diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreePatternMatcher.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternMatcher.java similarity index 84% rename from runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreePatternMatcher.java rename to runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternMatcher.java index 950f3639c..a778e8c6e 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/ParseTreePatternMatcher.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternMatcher.java @@ -28,23 +28,23 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.antlr.v4.runtime.tree; +package org.antlr.v4.runtime.tree.pattern; import org.antlr.v4.runtime.ANTLRInputStream; import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.Parser; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.TokenStream; -import org.antlr.v4.runtime.misc.Pair; +import org.antlr.v4.runtime.tree.ParseTree; +import org.antlr.v4.runtime.tree.ParseTreeWalker; +import org.antlr.v4.runtime.tree.RuleNode; import java.io.IOException; import java.io.StringReader; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; public class ParseTreePatternMatcher { @@ -54,78 +54,6 @@ public class ParseTreePatternMatcher { protected String start = "<", stop=">"; protected String escape = "\\"; // e.g., \< and \> must escape BOTH! - protected class Chunk { - } - protected class TextChunk extends Chunk { - public String text; - public TextChunk(String text) { - this.text = text; - } - - @Override - public String toString() { - return "'"+text+"'"; - } - } - protected class TagChunk extends Chunk { // or - public String tag; - public String label; - - public TagChunk(String tag) { - this.tag = tag; - } - - public TagChunk(String label, String tag) { - this.label = label; - this.tag = tag; - } - @Override - public String toString() { - if ( label!=null ) return label+":"+tag; - return tag; - } - } - - public static class Pattern { - protected String pattern; - - public Pattern(String pattern) { - this.pattern = pattern; - } - - public boolean matches(ParseTree t) { - return false; - } - } - - public static final Pattern WildcardPattern = - new Pattern("...") { - public boolean matches(ParseTree t) { - return true; - } - }; - - public static class Match { - protected ParseTree subtree; - protected List> labels; - } - - public static class MatchIterator implements Iterator { - @Override - public boolean hasNext() { - return false; - } - - @Override - public Match next() { - return null; - } - - @Override - public void remove() { - } - } - public ParseTreePatternMatcher() { } public ParseTreePatternMatcher(Class lexerClass, @@ -159,7 +87,7 @@ public class ParseTreePatternMatcher { String[] tokenNames = parser.getTokenNames(); String[] ruleNames = parser.getRuleNames(); // make maps for quick look up - + // split pattern into chunks: sea (raw input) and islands (, ) List chunks = split(pattern); @@ -306,7 +234,7 @@ public class ParseTreePatternMatcher { if ( pattern.matches(t) ) { subtrees.add(t); } - if ( t instanceof RuleNode ) { + if ( t instanceof RuleNode) { RuleNode r = (RuleNode)t; int n = r.getChildCount(); for (int i = 0; i or + public String tag; + public String label; + + public TagChunk(String tag) { + this.tag = tag; + } + + public TagChunk(String label, String tag) { + this.label = label; + this.tag = tag; + } + @Override + public String toString() { + if ( label!=null ) return label+":"+tag; + return tag; + } +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/TextChunk.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/TextChunk.java new file mode 100644 index 000000000..ad4dbb145 --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/TextChunk.java @@ -0,0 +1,13 @@ +package org.antlr.v4.runtime.tree.pattern; + +class TextChunk extends Chunk { + public String text; + public TextChunk(String text) { + this.text = text; + } + + @Override + public String toString() { + return "'"+text+"'"; + } +}