rm any/all pattern

This commit is contained in:
Terence Parr 2013-11-19 09:19:32 -08:00
parent 8cace4e182
commit f99cc52d39
5 changed files with 6 additions and 144 deletions

View File

@ -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;

View File

@ -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.
* "<...> . <ID>" 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;
}
}

View File

@ -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;
}
}

View File

@ -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 <ID>, 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 "<ID> = <e:expr> ;" into 4 chunks */
/** Split "<ID> = <e:expr> ;" into 4 chunks for tokenizing by tokenize() */
public List<Chunk> 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;

View File

@ -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 "<.>";
}
}