From f99cc52d391b6fe01245bdd0bfe8c6ec13e8d0b9 Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Tue, 19 Nov 2013 09:19:32 -0800 Subject: [PATCH] rm any/all pattern --- .../{tree/pattern => }/ListTokenSource.java | 2 +- .../tree/pattern/AnythingTagToken.java | 63 ------------------- .../ParseTreePatternErrorStrategy.java | 3 +- .../tree/pattern/ParseTreePatternMatcher.java | 20 ++---- .../tree/pattern/WildcardTagToken.java | 62 ------------------ 5 files changed, 6 insertions(+), 144 deletions(-) rename runtime/Java/src/org/antlr/v4/runtime/{tree/pattern => }/ListTokenSource.java (96%) delete mode 100644 runtime/Java/src/org/antlr/v4/runtime/tree/pattern/AnythingTagToken.java delete mode 100644 runtime/Java/src/org/antlr/v4/runtime/tree/pattern/WildcardTagToken.java diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ListTokenSource.java b/runtime/Java/src/org/antlr/v4/runtime/ListTokenSource.java similarity index 96% rename from runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ListTokenSource.java rename to runtime/Java/src/org/antlr/v4/runtime/ListTokenSource.java index 86dc7a0eb..fb12ce31d 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ListTokenSource.java +++ b/runtime/Java/src/org/antlr/v4/runtime/ListTokenSource.java @@ -1,4 +1,4 @@ -package org.antlr.v4.runtime.tree.pattern; +package org.antlr.v4.runtime; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CommonToken; diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/AnythingTagToken.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/AnythingTagToken.java deleted file mode 100644 index 1dc96ffa8..000000000 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/AnythingTagToken.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.antlr.v4.runtime.tree.pattern; - -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.TokenSource; - -/** <...> tag matches anything until what follows or end of string. - * "<...> . " matches anything until an ID. - * "x = <...>" - * - * matches .+ not .* - */ -public class AnythingTagToken implements Token { - @Override - public int getChannel() { - return 0; - } - - @Override - public String getText() { - return "..."; - } - - @Override - public int getType() { - return Token.INVALID_TYPE; - } - - @Override - public int getLine() { - return 0; - } - - @Override - public int getCharPositionInLine() { - return 0; - } - - @Override - public int getTokenIndex() { - return 0; - } - - @Override - public int getStartIndex() { - return 0; - } - - @Override - public int getStopIndex() { - return 0; - } - - @Override - public TokenSource getTokenSource() { - return null; - } - - @Override - public CharStream getInputStream() { - return null; - } -} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternErrorStrategy.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternErrorStrategy.java index efd416af9..31dc30269 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternErrorStrategy.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternErrorStrategy.java @@ -80,7 +80,6 @@ public class ParseTreePatternErrorStrategy extends DefaultErrorStrategy { } protected boolean isPatternTag(Token t) { - return t instanceof RuleTagToken || - t instanceof WildcardTagToken; + return t instanceof RuleTagToken; } } diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternMatcher.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternMatcher.java index 771c9a2b5..a160dd3e3 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternMatcher.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/ParseTreePatternMatcher.java @@ -34,6 +34,7 @@ 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.ListTokenSource; import org.antlr.v4.runtime.Parser; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.Token; @@ -53,10 +54,6 @@ import java.util.List; import java.util.Map; public class ParseTreePatternMatcher { - - public static final String ANYTHING = "..."; - public static final String WILDCARD = "."; - public static class CannotCreateLexerOrParser extends RuntimeException { public CannotCreateLexerOrParser(Throwable e) { super(e); @@ -135,9 +132,6 @@ public class ParseTreePatternMatcher { if ( tree==null || patternTree==null ) { return new ParseTreeMatchFailed(tree, null, pattern); } - if ( patternTree instanceof WildcardTagToken ) { - return new ParseTreeMatch(tree, pattern); // <.> matches any single node/subtree - } // x and , x and y, or x and x; or could be mismatched types if ( tree instanceof TerminalNode && patternTree instanceof TerminalNode ) { TerminalNode t1 = (TerminalNode)tree; @@ -250,13 +244,7 @@ public class ParseTreePatternMatcher { if ( chunk instanceof TagChunk ) { TagChunk tagChunk = (TagChunk)chunk; // add special rule token or conjure up new token from name -// if ( tagChunk.tag.equals(ANYTHING) ) { -// tokens.add(new AnythingTagToken()); -// } - if ( tagChunk.tag.equals(WILDCARD) ) { - tokens.add(new WildcardTagToken()); - } - else if ( Character.isUpperCase(tagChunk.tag.charAt(0)) ) { + if ( Character.isUpperCase(tagChunk.tag.charAt(0)) ) { tokens.add(new TokenTagToken(tagChunk.tag, tokenNameToType.get(tagChunk.tag))); } else { @@ -293,7 +281,7 @@ public class ParseTreePatternMatcher { return m; } - /** Split " = ;" into 4 chunks */ + /** Split " = ;" into 4 chunks for tokenizing by tokenize() */ public List split(String pattern) { int p = 0; int n = pattern.length(); @@ -368,7 +356,7 @@ public class ParseTreePatternMatcher { } } - // strip out the escape sequences + // strip out the escape sequences from text chunks but not tags for (Chunk c : chunks) { if ( c instanceof TextChunk ) { TextChunk tc = (TextChunk)c; diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/WildcardTagToken.java b/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/WildcardTagToken.java deleted file mode 100644 index 454939f59..000000000 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/pattern/WildcardTagToken.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.antlr.v4.runtime.tree.pattern; - -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.TokenSource; - -public class WildcardTagToken implements Token { - @Override - public int getChannel() { - return 0; - } - - @Override - public String getText() { - return "<.>"; - } - - @Override - public int getType() { - return Token.INVALID_TYPE; - } - - @Override - public int getLine() { - return 0; - } - - @Override - public int getCharPositionInLine() { - return 0; - } - - @Override - public int getTokenIndex() { - return 0; - } - - @Override - public int getStartIndex() { - return 0; - } - - @Override - public int getStopIndex() { - return 0; - } - - @Override - public TokenSource getTokenSource() { - return null; - } - - @Override - public CharStream getInputStream() { - return null; - } - - @Override - public String toString() { - return "<.>"; - } -}