v4: use getInterpreter() instead of directly accessing the _interp field

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9437]
This commit is contained in:
sharwell 2011-11-22 16:33:19 -08:00
parent 72684907bc
commit 1495ba5bd7
6 changed files with 21 additions and 21 deletions

View File

@ -251,7 +251,7 @@ public abstract class BaseRecognizer<Symbol> extends Recognizer<Symbol, ParserAT
}
public IntervalSet getExpectedTokens() {
return _interp.atn.nextTokens(_ctx);
return getInterpreter().atn.nextTokens(_ctx);
}
/** Return List<String> of the rule names in your parser instance

View File

@ -145,7 +145,7 @@ public class DefaultErrorStrategy<Symbol> implements ANTLRErrorStrategy<Symbol>
*/
@Override
public void sync(BaseRecognizer<Symbol> recognizer) {
ATNState s = recognizer._interp.atn.states.get(recognizer._ctx.s);
ATNState s = recognizer.getInterpreter().atn.states.get(recognizer._ctx.s);
// System.err.println("sync @ "+s.stateNumber+"="+s.getClass().getSimpleName());
// If already recovering, don't try to sync
if ( errorRecoveryMode ) return;
@ -296,9 +296,9 @@ public class DefaultErrorStrategy<Symbol> implements ANTLRErrorStrategy<Symbol>
// if current token is consistent with what could come after current
// ATN state, then we know we're missing a token; error recovery
// is free to conjure up and insert the missing token
ATNState currentState = recognizer._interp.atn.states.get(recognizer._ctx.s);
ATNState currentState = recognizer.getInterpreter().atn.states.get(recognizer._ctx.s);
ATNState next = currentState.transition(0).target;
IntervalSet expectingAtLL2 = recognizer._interp.atn.nextTokens(next, recognizer._ctx);
IntervalSet expectingAtLL2 = recognizer.getInterpreter().atn.nextTokens(next, recognizer._ctx);
// System.out.println("LT(2) set="+expectingAtLL2.toString(recognizer.getTokenNames()));
if ( expectingAtLL2.contains(currentSymbolType) ) {
reportMissingToken(recognizer);
@ -521,7 +521,7 @@ public class DefaultErrorStrategy<Symbol> implements ANTLRErrorStrategy<Symbol>
* at run-time upon error to avoid overhead during parsing.
*/
protected IntervalSet getErrorRecoverySet(BaseRecognizer<Symbol> recognizer) {
ATN atn = recognizer._interp.atn;
ATN atn = recognizer.getInterpreter().atn;
RuleContext ctx = recognizer._ctx;
IntervalSet recoverSet = new IntervalSet();
while ( ctx!=null && ctx.invokingState>=0 ) {

View File

@ -48,7 +48,7 @@ public class FailedPredicateException extends RecognitionException {
public FailedPredicateException(BaseRecognizer<?> recognizer, @Nullable String msg) {
super(recognizer, recognizer.getInputStream(), recognizer._ctx);
ATNState s = recognizer._interp.atn.states.get(recognizer._ctx.s);
ATNState s = recognizer.getInterpreter().atn.states.get(recognizer._ctx.s);
PredicateTransition trans = (PredicateTransition)s.transition(0);
ruleIndex = trans.ruleIndex;
predIndex = trans.predIndex;

View File

@ -116,7 +116,7 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
modeStack.clear();
}
_interp.reset();
getInterpreter().reset();
}
/** Return a token from this source; i.e., match a token on the char
@ -131,8 +131,8 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
token = null;
channel = Token.DEFAULT_CHANNEL;
tokenStartCharIndex = input.index();
tokenStartCharPositionInLine = _interp.getCharPositionInLine();
tokenStartLine = _interp.getLine();
tokenStartCharPositionInLine = getInterpreter().getCharPositionInLine();
tokenStartLine = getInterpreter().getLine();
text = null;
do {
type = Token.INVALID_TYPE;
@ -141,7 +141,7 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
// " at index "+input.index());
int ttype;
try {
ttype = _interp.match(input, mode);
ttype = getInterpreter().match(input, mode);
}
catch (LexerNoViableAltException e) {
notifyListeners(e); // report error
@ -259,12 +259,12 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
@Override
public int getLine() {
return _interp.getLine();
return getInterpreter().getLine();
}
@Override
public int getCharPositionInLine() {
return _interp.getCharPositionInLine();
return getInterpreter().getCharPositionInLine();
}
/** What is the index of the current character of lookahead? */
@ -279,7 +279,7 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
if ( text!=null ) {
return text;
}
return _interp.getText(input);
return getInterpreter().getText(input);
// return ((CharStream)input).substring(tokenStartCharIndex,getCharIndex()-1);
}
@ -315,7 +315,7 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
}
public void recover(LexerNoViableAltException e) {
_interp.consume(input); // skip a char and try again
getInterpreter().consume(input); // skip a char and try again
}
public void notifyListeners(LexerNoViableAltException e) {

View File

@ -84,7 +84,7 @@ public class RecognitionException extends RuntimeException {
public IntervalSet getExpectedTokens() {
// TODO: do we really need this type check?
if ( recognizer!=null && recognizer instanceof BaseRecognizer) {
return recognizer._interp.atn.nextTokens(ctx);
return recognizer.getInterpreter().atn.nextTokens(ctx);
}
return null;
}

View File

@ -317,7 +317,7 @@ setState(<choice.stateNumber>);
_errHandler.sync(this);
<if(choice.label)><labelref(choice.label)> = _input.LT(1);<endif>
<preamble; separator="\n">
switch ( _interp.adaptivePredict(_input,<choice.decision>,_ctx) ) {
switch ( getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx) ) {
<alts:{alt |
case <i>:
<alt>
@ -328,7 +328,7 @@ case <i>:
OptionalBlock(choice, alts, error) ::= <<
setState(<choice.stateNumber>);
_errHandler.sync(this);
switch ( _interp.adaptivePredict(_input,<choice.decision>,_ctx) ) {
switch ( getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx) ) {
<alts:{alt |
case <i>:
<alt>
@ -341,7 +341,7 @@ case <i>:
StarBlock(choice, alts, sync) ::= <<
setState(<choice.stateNumber>);
_errHandler.sync(this);
int _alt<choice.uniqueID> = _interp.adaptivePredict(_input,<choice.decision>,_ctx);
int _alt<choice.uniqueID> = getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx);
while ( _alt<choice.uniqueID>!=<choice.exitAlt> && _alt<choice.uniqueID>!=-1 ) {
switch ( _alt<choice.uniqueID> ) {
<alts:{alt|
@ -351,14 +351,14 @@ case <i>:
}
setState(<choice.loopBackStateNumber>);
_errHandler.sync(this);
_alt<choice.uniqueID> = _interp.adaptivePredict(_input,<choice.decision>,_ctx);
_alt<choice.uniqueID> = getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx);
}
>>
PlusBlock(choice, alts, error) ::= <<
setState(<choice.blockStartStateNumber>); <! alt block decision !>
_errHandler.sync(this);
int _alt<choice.uniqueID> = _interp.adaptivePredict(_input,<choice.decision>,_ctx);
int _alt<choice.uniqueID> = getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx);
do {
switch ( _alt<choice.uniqueID> ) {
<alts:{alt|
@ -370,7 +370,7 @@ case <i>:
}
setState(<choice.loopBackStateNumber>); <! loopback/exit decision !>
_errHandler.sync(this);
_alt<choice.uniqueID> = _interp.adaptivePredict(_input,<choice.decision>,_ctx);
_alt<choice.uniqueID> = getInterpreter().adaptivePredict(_input,<choice.decision>,_ctx);
} while ( _alt<choice.uniqueID>!=<choice.exitAlt> && _alt<choice.uniqueID>!=-1 );
>>