forked from jasder/antlr
v4: ObjectStream -> SymbolStream
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9381]
This commit is contained in:
parent
f999b5c3d0
commit
ff97c91ef2
|
@ -148,7 +148,7 @@ public abstract class BaseRecognizer<TSymbol> extends Recognizer<TSymbol, Parser
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract ObjectStream<TSymbol> getInputStream();
|
public abstract SymbolStream<TSymbol> getInputStream();
|
||||||
|
|
||||||
/** Match needs to return the current input symbol, which gets put
|
/** Match needs to return the current input symbol, which gets put
|
||||||
* into the label for the associated token ref; e.g., x=ID. Token
|
* into the label for the associated token ref; e.g., x=ID. Token
|
||||||
|
|
|
@ -33,8 +33,6 @@ import com.sun.istack.internal.NotNull;
|
||||||
import org.antlr.v4.runtime.atn.*;
|
import org.antlr.v4.runtime.atn.*;
|
||||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||||
import org.antlr.v4.runtime.tree.AST;
|
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
|
/** This is the default error handling mechanism for ANTLR parsers
|
||||||
* and tree parsers.
|
* and tree parsers.
|
||||||
|
@ -158,7 +156,7 @@ public class DefaultANTLRErrorStrategy<TSymbol> implements ANTLRErrorStrategy<TS
|
||||||
// System.err.println("sync expecting: "+expecting);
|
// System.err.println("sync expecting: "+expecting);
|
||||||
|
|
||||||
// TODO: subclass this class for treeparsers
|
// TODO: subclass this class for treeparsers
|
||||||
ObjectStream<TSymbol> tokens = recognizer.getInputStream();
|
SymbolStream<TSymbol> tokens = recognizer.getInputStream();
|
||||||
int la = tokens.LA(1);
|
int la = tokens.LA(1);
|
||||||
// Return but don't end recovery. only do that upon valid token match
|
// Return but don't end recovery. only do that upon valid token match
|
||||||
if ( la==Token.EOF || expecting.contains(la) ) return;
|
if ( la==Token.EOF || expecting.contains(la) ) return;
|
||||||
|
@ -187,7 +185,7 @@ public class DefaultANTLRErrorStrategy<TSymbol> implements ANTLRErrorStrategy<TS
|
||||||
NoViableAltException e)
|
NoViableAltException e)
|
||||||
throws RecognitionException
|
throws RecognitionException
|
||||||
{
|
{
|
||||||
ObjectStream<TSymbol> tokens = recognizer.getInputStream();
|
SymbolStream<TSymbol> tokens = recognizer.getInputStream();
|
||||||
String input;
|
String input;
|
||||||
if (tokens instanceof TokenStream) {
|
if (tokens instanceof TokenStream) {
|
||||||
input = ((TokenStream)tokens).toString(e.startToken, e.offendingToken);
|
input = ((TokenStream)tokens).toString(e.startToken, e.offendingToken);
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class NoViableAltException extends RecognitionException {
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> NoViableAltException(BaseRecognizer<T> recognizer,
|
public <T> NoViableAltException(BaseRecognizer<T> recognizer,
|
||||||
ObjectStream<T> input,
|
SymbolStream<T> input,
|
||||||
Token startToken,
|
Token startToken,
|
||||||
Token offendingToken,
|
Token offendingToken,
|
||||||
T offendingNode,
|
T offendingNode,
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
package org.antlr.v4.runtime;
|
package org.antlr.v4.runtime;
|
||||||
|
|
||||||
/** A stream of either tokens or tree nodes */
|
/** 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.
|
/** Get an object at absolute index i; 0..n-1.
|
||||||
* This is only valid if the underlying stream implementation buffers
|
* This is only valid if the underlying stream implementation buffers
|
||||||
* all of the incoming objects.
|
* all of the incoming objects.
|
|
@ -30,7 +30,7 @@
|
||||||
package org.antlr.v4.runtime;
|
package org.antlr.v4.runtime;
|
||||||
|
|
||||||
/** A stream of tokens accessing tokens from a TokenSource */
|
/** 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.
|
/** 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
|
* 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.
|
* two tokens ago. LT(0) is undefined. For i>=n, return Token.EOFToken.
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
|
||||||
// System.out.println(dot.getDOT(atn.rules.get(1), parser.getRuleNames()));
|
// 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++;
|
predict_calls++;
|
||||||
DFA dfa = decisionToDFA[decision];
|
DFA dfa = decisionToDFA[decision];
|
||||||
if ( dfa==null || dfa.s0==null ) {
|
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,
|
RuleContext outerContext,
|
||||||
boolean useContext)
|
boolean useContext)
|
||||||
{
|
{
|
||||||
|
@ -146,7 +146,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// doesn't create DFA when matching
|
// 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);
|
DFA dfa = new DFA(startState);
|
||||||
if ( outerContext==null ) outerContext = RuleContext.EMPTY;
|
if ( outerContext==null ) outerContext = RuleContext.EMPTY;
|
||||||
RuleContext ctx = 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);
|
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);
|
// dump(dfa);
|
||||||
if ( outerContext==null ) outerContext = RuleContext.EMPTY;
|
if ( outerContext==null ) outerContext = RuleContext.EMPTY;
|
||||||
this.outerContext = outerContext;
|
this.outerContext = outerContext;
|
||||||
|
@ -241,7 +241,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
|
||||||
return prevAcceptState.prediction;
|
return prevAcceptState.prediction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInputString(ObjectStream<TSymbol> input, int start) {
|
public String getInputString(SymbolStream<TSymbol> input, int start) {
|
||||||
if ( input instanceof TokenStream ) {
|
if ( input instanceof TokenStream ) {
|
||||||
return ((TokenStream)input).toString(start,input.index());
|
return ((TokenStream)input).toString(start,input.index());
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
|
||||||
return "n/a";
|
return "n/a";
|
||||||
}
|
}
|
||||||
|
|
||||||
public int execATN(ObjectStream<TSymbol> input,
|
public int execATN(SymbolStream<TSymbol> input,
|
||||||
DFA dfa,
|
DFA dfa,
|
||||||
int startIndex,
|
int startIndex,
|
||||||
OrderedHashSet<ATNConfig> s0,
|
OrderedHashSet<ATNConfig> s0,
|
||||||
|
@ -405,7 +405,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
|
||||||
return exitAlt;
|
return exitAlt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int retryWithContext(ObjectStream<TSymbol> input,
|
public int retryWithContext(SymbolStream<TSymbol> input,
|
||||||
DFA dfa,
|
DFA dfa,
|
||||||
int startIndex,
|
int startIndex,
|
||||||
RuleContext originalContext,
|
RuleContext originalContext,
|
||||||
|
@ -823,7 +823,7 @@ public class ParserATNSimulator<TSymbol> extends ATNSimulator {
|
||||||
return String.valueOf(t);
|
return String.valueOf(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLookaheadName(ObjectStream<TSymbol> input) {
|
public String getLookaheadName(SymbolStream<TSymbol> input) {
|
||||||
return getTokenName(input.LA(1));
|
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)
|
OrderedHashSet<ATNConfig> configs, int startIndex)
|
||||||
{
|
{
|
||||||
if ( parser instanceof TreeParser) {
|
if ( parser instanceof TreeParser) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ package org.antlr.v4.runtime.tree;
|
||||||
import org.antlr.v4.runtime.*;
|
import org.antlr.v4.runtime.*;
|
||||||
|
|
||||||
/** A stream of tree nodes, accessing nodes from a tree of some kind */
|
/** 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.
|
/** 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
|
* If you don't want to buffer up nodes, then this method makes no
|
||||||
* sense for you.
|
* sense for you.
|
||||||
|
|
Loading…
Reference in New Issue