v4: ObjectStream -> SymbolStream

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9381]
This commit is contained in:
sharwell 2011-11-17 19:45:35 -08:00
parent f999b5c3d0
commit ff97c91ef2
7 changed files with 16 additions and 18 deletions

View File

@ -148,7 +148,7 @@ public abstract class BaseRecognizer<TSymbol> extends Recognizer<TSymbol, Parser
}
@Override
public abstract ObjectStream<TSymbol> getInputStream();
public abstract SymbolStream<TSymbol> getInputStream();
/** Match needs to return the current input symbol, which gets put
* into the label for the associated token ref; e.g., x=ID. Token

View File

@ -33,8 +33,6 @@ import com.sun.istack.internal.NotNull;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.tree.AST;
import org.antlr.v4.runtime.tree.ASTAdaptor;
import org.antlr.v4.runtime.tree.Tree;
/** This is the default error handling mechanism for ANTLR parsers
* and tree parsers.
@ -158,7 +156,7 @@ public class DefaultANTLRErrorStrategy<TSymbol> implements ANTLRErrorStrategy<TS
// System.err.println("sync expecting: "+expecting);
// TODO: subclass this class for treeparsers
ObjectStream<TSymbol> tokens = recognizer.getInputStream();
SymbolStream<TSymbol> tokens = recognizer.getInputStream();
int la = tokens.LA(1);
// Return but don't end recovery. only do that upon valid token match
if ( la==Token.EOF || expecting.contains(la) ) return;
@ -187,7 +185,7 @@ public class DefaultANTLRErrorStrategy<TSymbol> implements ANTLRErrorStrategy<TS
NoViableAltException e)
throws RecognitionException
{
ObjectStream<TSymbol> tokens = recognizer.getInputStream();
SymbolStream<TSymbol> tokens = recognizer.getInputStream();
String input;
if (tokens instanceof TokenStream) {
input = ((TokenStream)tokens).toString(e.startToken, e.offendingToken);

View File

@ -55,7 +55,7 @@ public class NoViableAltException extends RecognitionException {
}
public <T> NoViableAltException(BaseRecognizer<T> recognizer,
ObjectStream<T> input,
SymbolStream<T> input,
Token startToken,
Token offendingToken,
T offendingNode,

View File

@ -30,7 +30,7 @@
package org.antlr.v4.runtime;
/** A stream of either tokens or tree nodes */
public interface ObjectStream<T> extends IntStream {
public interface SymbolStream<T> extends IntStream {
/** Get an object at absolute index i; 0..n-1.
* This is only valid if the underlying stream implementation buffers
* all of the incoming objects.

View File

@ -30,7 +30,7 @@
package org.antlr.v4.runtime;
/** A stream of tokens accessing tokens from a TokenSource */
public interface TokenStream extends ObjectStream<Token> {
public interface TokenStream extends SymbolStream<Token> {
/** Get Token at current input pointer + i ahead where i=1 is next Token.
* i<0 indicates tokens in the past. So -1 is previous token and -2 is
* two tokens ago. LT(0) is undefined. For i>=n, return Token.EOFToken.

View File

@ -83,7 +83,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
// System.out.println(dot.getDOT(atn.rules.get(1), parser.getRuleNames()));
}
public int adaptivePredict(ObjectStream<TSymbol> input, int decision, RuleContext outerContext) {
public int adaptivePredict(SymbolStream<TSymbol> input, int decision, RuleContext outerContext) {
predict_calls++;
DFA dfa = decisionToDFA[decision];
if ( dfa==null || dfa.s0==null ) {
@ -108,7 +108,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
}
}
public int predictATN(DFA dfa, ObjectStream<TSymbol> input,
public int predictATN(DFA dfa, SymbolStream<TSymbol> input,
RuleContext outerContext,
boolean useContext)
{
@ -146,7 +146,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
}
// doesn't create DFA when matching
public int matchATN(ObjectStream<TSymbol> input, ATNState startState) {
public int matchATN(SymbolStream<TSymbol> input, ATNState startState) {
DFA dfa = new DFA(startState);
if ( outerContext==null ) outerContext = RuleContext.EMPTY;
RuleContext ctx = RuleContext.EMPTY;
@ -154,7 +154,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
return execATN(input, dfa, input.index(), s0_closure, false);
}
public int execDFA(ObjectStream<TSymbol> input, DFA dfa, DFAState s0, RuleContext outerContext) {
public int execDFA(SymbolStream<TSymbol> input, DFA dfa, DFAState s0, RuleContext outerContext) {
// dump(dfa);
if ( outerContext==null ) outerContext = RuleContext.EMPTY;
this.outerContext = outerContext;
@ -241,7 +241,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
return prevAcceptState.prediction;
}
public String getInputString(ObjectStream<TSymbol> input, int start) {
public String getInputString(SymbolStream<TSymbol> input, int start) {
if ( input instanceof TokenStream ) {
return ((TokenStream)input).toString(start,input.index());
}
@ -251,7 +251,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
return "n/a";
}
public int execATN(ObjectStream<TSymbol> input,
public int execATN(SymbolStream<TSymbol> input,
DFA dfa,
int startIndex,
OrderedHashSet<ATNConfig> s0,
@ -405,7 +405,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
return exitAlt;
}
public int retryWithContext(ObjectStream<TSymbol> input,
public int retryWithContext(SymbolStream<TSymbol> input,
DFA dfa,
int startIndex,
RuleContext originalContext,
@ -823,7 +823,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
return String.valueOf(t);
}
public String getLookaheadName(ObjectStream<TSymbol> input) {
public String getLookaheadName(SymbolStream<TSymbol> input) {
return getTokenName(input.LA(1));
}
@ -849,7 +849,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
}
}
public int throwNoViableAlt(ObjectStream<TSymbol> input, RuleContext outerContext,
public int throwNoViableAlt(SymbolStream<TSymbol> input, RuleContext outerContext,
OrderedHashSet<ATNConfig> configs, int startIndex)
{
if ( parser instanceof TreeParser) {

View File

@ -32,7 +32,7 @@ package org.antlr.v4.runtime.tree;
import org.antlr.v4.runtime.*;
/** A stream of tree nodes, accessing nodes from a tree of some kind */
public interface ASTNodeStream<T> extends ObjectStream<T> {
public interface ASTNodeStream<T> extends SymbolStream<T> {
/** Get a tree node at an absolute index i; 0..n-1.
* If you don't want to buffer up nodes, then this method makes no
* sense for you.