Updated sharpen property annotations

This commit is contained in:
Sam Harwell 2013-02-16 15:23:03 -06:00
parent d676aa8c4c
commit 366da4e5d5
17 changed files with 274 additions and 205 deletions

View File

@ -477,7 +477,7 @@ namespace Antlr4.Runtime.Atn
{
if (dfa_debug && t >= 0)
{
System.Console.Out.WriteLine("no edge for " + parser.GetTokenNames()[t]);
System.Console.Out.WriteLine("no edge for " + parser.TokenNames[t]);
}
int alt;
SimulatorState initialState = new SimulatorState(outerContext, s, state.useContext
@ -1475,7 +1475,7 @@ namespace Antlr4.Runtime.Atn
{
if (parser != null && index >= 0)
{
return parser.GetRuleNames()[index];
return parser.RuleNames[index];
}
return "<rule " + index + ">";
}
@ -1829,15 +1829,15 @@ namespace Antlr4.Runtime.Atn
{
return "EOF";
}
if (parser != null && parser.GetTokenNames() != null)
if (parser != null && parser.TokenNames != null)
{
string[] tokensNames = parser.GetTokenNames();
string[] tokensNames = parser.TokenNames;
if (t >= tokensNames.Length)
{
System.Console.Error.WriteLine(t + " ttype out of range: " + Arrays.ToString(tokensNames
));
System.Console.Error.WriteLine(((CommonTokenStream)((ITokenStream)parser.GetInputStream
())).GetTokens());
System.Console.Error.WriteLine(((CommonTokenStream)((ITokenStream)parser.InputStream
)).GetTokens());
}
else
{
@ -2086,8 +2086,8 @@ namespace Antlr4.Runtime.Atn
{
Interval interval = Interval.Of(startIndex, stopIndex);
System.Console.Out.WriteLine("reportAttemptingFullContext decision=" + dfa.decision
+ ":" + initialState.s0.configs + ", input=" + ((ITokenStream)parser.GetInputStream
()).GetText(interval));
+ ":" + initialState.s0.configs + ", input=" + ((ITokenStream)parser.InputStream
).GetText(interval));
}
if (parser != null)
{
@ -2103,8 +2103,8 @@ namespace Antlr4.Runtime.Atn
{
Interval interval = Interval.Of(startIndex, stopIndex);
System.Console.Out.WriteLine("reportContextSensitivity decision=" + dfa.decision
+ ":" + acceptState.s0.configs + ", input=" + ((ITokenStream)parser.GetInputStream
()).GetText(interval));
+ ":" + acceptState.s0.configs + ", input=" + ((ITokenStream)parser.InputStream
).GetText(interval));
}
if (parser != null)
{
@ -2137,7 +2137,7 @@ namespace Antlr4.Runtime.Atn
// }
Interval interval = Interval.Of(startIndex, stopIndex);
System.Console.Out.WriteLine("reportAmbiguity " + ambigAlts + ":" + configs + ", input="
+ ((ITokenStream)parser.GetInputStream()).GetText(interval));
+ ((ITokenStream)parser.InputStream).GetText(interval));
}
if (parser != null)
{

View File

@ -484,9 +484,9 @@ namespace Antlr4.Runtime.Atn
// first char is '[', if more than that this isn't the first rule
localBuffer.Append(' ');
}
ATN atn = recognizer.GetATN();
ATN atn = recognizer.Atn;
ATNState s = atn.states[stateNumber];
string ruleName = recognizer.GetRuleNames()[s.ruleIndex];
string ruleName = recognizer.RuleNames[s.ruleIndex];
localBuffer.Append(ruleName);
}
else

View File

@ -56,8 +56,8 @@ namespace Antlr4.Runtime
/// </summary>
public override void Recover(Parser recognizer, RecognitionException e)
{
for (ParserRuleContext context = recognizer.GetContext(); context != null; context
= ((ParserRuleContext)context.Parent))
for (ParserRuleContext context = recognizer.Context; context != null; context = (
(ParserRuleContext)context.Parent))
{
context.exception = e;
}
@ -76,8 +76,8 @@ namespace Antlr4.Runtime
public override IToken RecoverInline(Parser recognizer)
{
InputMismatchException e = new InputMismatchException(recognizer);
for (ParserRuleContext context = recognizer.GetContext(); context != null; context
= ((ParserRuleContext)context.Parent))
for (ParserRuleContext context = recognizer.Context; context != null; context = (
(ParserRuleContext)context.Parent))
{
context.exception = e;
}

View File

@ -145,8 +145,8 @@ namespace Antlr4.Runtime
// ", lastErrorIndex="+
// lastErrorIndex+
// ", states="+lastErrorStates);
if (lastErrorIndex == ((ITokenStream)recognizer.GetInputStream()).Index && lastErrorStates
!= null && lastErrorStates.Contains(recognizer.GetState()))
if (lastErrorIndex == ((ITokenStream)recognizer.InputStream).Index && lastErrorStates
!= null && lastErrorStates.Contains(recognizer.State))
{
// uh oh, another error at same token index and previously-visited
// state in ATN; must be a case where LT(1) is in the recovery
@ -157,12 +157,12 @@ namespace Antlr4.Runtime
// System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]);
recognizer.Consume();
}
lastErrorIndex = ((ITokenStream)recognizer.GetInputStream()).Index;
lastErrorIndex = ((ITokenStream)recognizer.InputStream).Index;
if (lastErrorStates == null)
{
lastErrorStates = new IntervalSet();
}
lastErrorStates.Add(recognizer.GetState());
lastErrorStates.Add(recognizer.State);
IntervalSet followSet = GetErrorRecoverySet(recognizer);
ConsumeUntil(recognizer, followSet);
}
@ -186,17 +186,17 @@ namespace Antlr4.Runtime
/// </remarks>
public virtual void Sync(Parser recognizer)
{
ATNState s = recognizer.GetInterpreter().atn.states[recognizer.GetState()];
ATNState s = recognizer.Interpreter.atn.states[recognizer.State];
// System.err.println("sync @ "+s.stateNumber+"="+s.getClass().getSimpleName());
// If already recovering, don't try to sync
if (errorRecoveryMode)
{
return;
}
ITokenStream tokens = ((ITokenStream)recognizer.GetInputStream());
ITokenStream tokens = ((ITokenStream)recognizer.InputStream);
int la = tokens.La(1);
// try cheaper subset first; might get lucky. seems to shave a wee bit off
if (recognizer.GetATN().NextTokens(s).Contains(la) || la == IToken.Eof)
if (recognizer.Atn.NextTokens(s).Contains(la) || la == IToken.Eof)
{
return;
}
@ -245,7 +245,7 @@ namespace Antlr4.Runtime
public virtual void ReportNoViableAlternative(Parser recognizer, NoViableAltException
e)
{
ITokenStream tokens = ((ITokenStream)recognizer.GetInputStream());
ITokenStream tokens = ((ITokenStream)recognizer.InputStream);
string input;
if (tokens != null)
{
@ -271,7 +271,7 @@ namespace Antlr4.Runtime
e)
{
string msg = "mismatched input " + GetTokenErrorDisplay(e.GetOffendingToken()) +
" expecting " + e.GetExpectedTokens().ToString(recognizer.GetTokenNames());
" expecting " + e.GetExpectedTokens().ToString(recognizer.TokenNames);
NotifyErrorListeners(recognizer, msg, e);
}
@ -279,7 +279,7 @@ namespace Antlr4.Runtime
public virtual void ReportFailedPredicate(Parser recognizer, FailedPredicateException
e)
{
string ruleName = recognizer.GetRuleNames()[recognizer._ctx.GetRuleIndex()];
string ruleName = recognizer.RuleNames[recognizer._ctx.GetRuleIndex()];
string msg = "rule " + ruleName + " " + e.Message;
NotifyErrorListeners(recognizer, msg, e);
}
@ -292,11 +292,11 @@ namespace Antlr4.Runtime
}
recognizer._syntaxErrors++;
BeginErrorCondition(recognizer);
IToken t = recognizer.GetCurrentToken();
IToken t = recognizer.CurrentToken;
string tokenName = GetTokenErrorDisplay(t);
IntervalSet expecting = GetExpectedTokens(recognizer);
string msg = "extraneous input " + tokenName + " expecting " + expecting.ToString
(recognizer.GetTokenNames());
(recognizer.TokenNames);
recognizer.NotifyErrorListeners(t, msg, null);
}
@ -308,10 +308,10 @@ namespace Antlr4.Runtime
}
recognizer._syntaxErrors++;
BeginErrorCondition(recognizer);
IToken t = recognizer.GetCurrentToken();
IToken t = recognizer.CurrentToken;
IntervalSet expecting = GetExpectedTokens(recognizer);
string msg = "missing " + expecting.ToString(recognizer.GetTokenNames()) + " at "
+ GetTokenErrorDisplay(t);
string msg = "missing " + expecting.ToString(recognizer.TokenNames) + " at " + GetTokenErrorDisplay
(t);
recognizer.NotifyErrorListeners(t, msg, null);
}
@ -363,14 +363,13 @@ namespace Antlr4.Runtime
// if next token is what we are looking for then "delete" this token
public virtual bool SingleTokenInsertion(Parser recognizer)
{
int currentSymbolType = ((ITokenStream)recognizer.GetInputStream()).La(1);
int currentSymbolType = ((ITokenStream)recognizer.InputStream).La(1);
// 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.GetInterpreter().atn.states[recognizer.GetState
()];
ATNState currentState = recognizer.Interpreter.atn.states[recognizer.State];
ATNState next = currentState.Transition(0).target;
ATN atn = recognizer.GetInterpreter().atn;
ATN atn = recognizer.Interpreter.atn;
IntervalSet expectingAtLL2 = atn.NextTokens(next, PredictionContext.FromRuleContext
(atn, recognizer._ctx));
// System.out.println("LT(2) set="+expectingAtLL2.toString(recognizer.getTokenNames()));
@ -384,7 +383,7 @@ namespace Antlr4.Runtime
public virtual IToken SingleTokenDeletion(Parser recognizer)
{
int nextTokenType = ((ITokenStream)recognizer.GetInputStream()).La(2);
int nextTokenType = ((ITokenStream)recognizer.InputStream).La(2);
IntervalSet expecting = GetExpectedTokens(recognizer);
if (expecting.Contains(nextTokenType))
{
@ -392,7 +391,7 @@ namespace Antlr4.Runtime
recognizer.Consume();
// simply delete extra token
// we want to return the token we're actually matching
IToken matchedSymbol = recognizer.GetCurrentToken();
IToken matchedSymbol = recognizer.CurrentToken;
EndErrorCondition(recognizer);
// we know current token is correct
return matchedSymbol;
@ -422,7 +421,7 @@ namespace Antlr4.Runtime
/// </remarks>
protected internal virtual IToken GetMissingSymbol(Parser recognizer)
{
IToken currentSymbol = recognizer.GetCurrentToken();
IToken currentSymbol = recognizer.CurrentToken;
IntervalSet expecting = GetExpectedTokens(recognizer);
int expectedTokenType = expecting.GetMinElement();
// get any element
@ -433,15 +432,15 @@ namespace Antlr4.Runtime
}
else
{
tokenText = "<missing " + recognizer.GetTokenNames()[expectedTokenType] + ">";
tokenText = "<missing " + recognizer.TokenNames[expectedTokenType] + ">";
}
IToken current = currentSymbol;
IToken lookback = ((ITokenStream)recognizer.GetInputStream()).Lt(-1);
IToken lookback = ((ITokenStream)recognizer.InputStream).Lt(-1);
if (current.Type == IToken.Eof && lookback != null)
{
current = lookback;
}
return ConstructToken(((ITokenStream)recognizer.GetInputStream()).TokenSource, expectedTokenType
return ConstructToken(((ITokenStream)recognizer.InputStream).TokenSource, expectedTokenType
, tokenText, current);
}
@ -515,7 +514,7 @@ namespace Antlr4.Runtime
protected internal virtual IntervalSet GetErrorRecoverySet(Parser recognizer)
{
ATN atn = recognizer.GetInterpreter().atn;
ATN atn = recognizer.Interpreter.atn;
RuleContext ctx = recognizer._ctx;
IntervalSet recoverSet = new IntervalSet();
while (ctx != null && ctx.invokingState >= 0)
@ -536,13 +535,13 @@ namespace Antlr4.Runtime
public virtual void ConsumeUntil(Parser recognizer, IntervalSet set)
{
// System.err.println("consumeUntil("+set.toString(recognizer.getTokenNames())+")");
int ttype = ((ITokenStream)recognizer.GetInputStream()).La(1);
int ttype = ((ITokenStream)recognizer.InputStream).La(1);
while (ttype != IToken.Eof && !set.Contains(ttype))
{
//System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]);
// recognizer.getInputStream().consume();
recognizer.Consume();
ttype = ((ITokenStream)recognizer.GetInputStream()).La(1);
ttype = ((ITokenStream)recognizer.InputStream).La(1);
}
}
}

View File

@ -59,8 +59,8 @@ namespace Antlr4.Runtime.Dfa
}
public DFASerializer(DFA dfa, Recognizer<object, object> parser) : this(dfa, parser
!= null ? parser.GetTokenNames() : null, parser != null ? parser.GetRuleNames
() : null, parser != null ? parser.GetATN() : null)
!= null ? parser.TokenNames : null, parser != null ? parser.RuleNames : null
, parser != null ? parser.Atn : null)
{
}

View File

@ -43,8 +43,8 @@ namespace Antlr4.Runtime
{
string format = "reportAmbiguity d=%s: ambigAlts=%s, input='%s'";
recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer
, dfa.decision), ambigAlts, ((ITokenStream)recognizer.GetInputStream()).GetText
(Interval.Of(startIndex, stopIndex))));
, dfa.decision), ambigAlts, ((ITokenStream)recognizer.InputStream).GetText(Interval
.Of(startIndex, stopIndex))));
}
public override void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int
@ -52,8 +52,8 @@ namespace Antlr4.Runtime
{
string format = "reportAttemptingFullContext d=%s, input='%s'";
recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer
, dfa.decision), ((ITokenStream)recognizer.GetInputStream()).GetText(Interval
.Of(startIndex, stopIndex))));
, dfa.decision), ((ITokenStream)recognizer.InputStream).GetText(Interval.Of(startIndex
, stopIndex))));
}
public override void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex
@ -61,8 +61,8 @@ namespace Antlr4.Runtime
{
string format = "reportContextSensitivity d=%s, input='%s'";
recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer
, dfa.decision), ((ITokenStream)recognizer.GetInputStream()).GetText(Interval
.Of(startIndex, stopIndex))));
, dfa.decision), ((ITokenStream)recognizer.InputStream).GetText(Interval.Of(startIndex
, stopIndex))));
}
protected internal virtual string GetDecisionDescription(Parser recognizer, int decision

View File

@ -63,9 +63,9 @@ namespace Antlr4.Runtime
public FailedPredicateException(Parser recognizer, string predicate, string message
) : base(FormatMessage(predicate, message), recognizer, ((ITokenStream)recognizer
.GetInputStream()), recognizer._ctx)
.InputStream), recognizer._ctx)
{
ATNState s = recognizer.GetInterpreter().atn.states[recognizer.GetState()];
ATNState s = recognizer.Interpreter.atn.states[recognizer.State];
AbstractPredicateTransition trans = (AbstractPredicateTransition)s.Transition(0);
if (trans is PredicateTransition)
{
@ -78,7 +78,7 @@ namespace Antlr4.Runtime
this.predicateIndex = 0;
}
this.predicate = predicate;
this.SetOffendingToken(recognizer.GetCurrentToken());
this.SetOffendingToken(recognizer.CurrentToken);
}
public virtual int GetRuleIndex()

View File

@ -46,9 +46,9 @@ namespace Antlr4.Runtime
private const long serialVersionUID = 1532568338707443067L;
public InputMismatchException(Parser recognizer) : base(recognizer, ((ITokenStream
)recognizer.GetInputStream()), recognizer._ctx)
)recognizer.InputStream), recognizer._ctx)
{
this.SetOffendingToken(recognizer.GetCurrentToken());
this.SetOffendingToken(recognizer.CurrentToken);
}
}
}

View File

@ -147,7 +147,7 @@ namespace Antlr4.Runtime
_hitEOF = false;
_mode = Antlr4.Runtime.Lexer.DefaultMode;
_modeStack.Clear();
GetInterpreter().Reset();
Interpreter.Reset();
}
/// <summary>
@ -180,8 +180,8 @@ namespace Antlr4.Runtime
_token = null;
_channel = IToken.DefaultChannel;
_tokenStartCharIndex = _input.Index;
_tokenStartCharPositionInLine = GetInterpreter().GetCharPositionInLine();
_tokenStartLine = GetInterpreter().GetLine();
_tokenStartCharPositionInLine = Interpreter.GetCharPositionInLine();
_tokenStartLine = Interpreter.GetLine();
_text = null;
do
{
@ -192,7 +192,7 @@ namespace Antlr4.Runtime
int ttype;
try
{
ttype = GetInterpreter().Match(_input, _mode);
ttype = Interpreter.Match(_input, _mode);
}
catch (LexerNoViableAltException e)
{
@ -305,9 +305,12 @@ outer_break: ;
}
}
public override IIntStream GetInputStream()
public override IIntStream InputStream
{
return _input;
get
{
return _input;
}
}
/// <summary>
@ -365,7 +368,7 @@ outer_break: ;
{
get
{
return GetInterpreter().GetLine();
return Interpreter.GetLine();
}
}
@ -373,18 +376,18 @@ outer_break: ;
{
get
{
return GetInterpreter().GetCharPositionInLine();
return Interpreter.GetCharPositionInLine();
}
}
public virtual void SetLine(int line)
{
GetInterpreter().SetLine(line);
Interpreter.SetLine(line);
}
public virtual void SetCharPositionInLine(int charPositionInLine)
{
GetInterpreter().SetCharPositionInLine(charPositionInLine);
Interpreter.SetCharPositionInLine(charPositionInLine);
}
/// <summary>What is the index of the current character of lookahead?</summary>
@ -407,7 +410,7 @@ outer_break: ;
{
return _text;
}
return GetInterpreter().GetText(_input);
return Interpreter.GetText(_input);
}
/// <summary>
@ -469,9 +472,12 @@ outer_break: ;
/// error reporting. The generated parsers implement a method
/// that overrides this to point to their String[] tokenNames.
/// </remarks>
public override string[] GetTokenNames()
public override string[] TokenNames
{
return null;
get
{
return null;
}
}
/// <summary>Return a list of all Token objects in input char stream.</summary>
@ -496,7 +502,7 @@ outer_break: ;
if (_input.La(1) != IIntStream.Eof)
{
// skip a char and try again
GetInterpreter().Consume(_input);
Interpreter.Consume(_input);
}
}

View File

@ -283,19 +283,19 @@ namespace Antlr4.Runtime.Misc
if (diagnostics)
{
parser.AddErrorListener(new DiagnosticErrorListener());
parser.GetInterpreter().SetPredictionMode(PredictionMode.LlExactAmbigDetection);
parser.Interpreter.SetPredictionMode(PredictionMode.LlExactAmbigDetection);
}
if (printTree || gui || psFile != null)
{
parser.SetBuildParseTree(true);
parser.BuildParseTree = true;
}
if (Sll)
{
// overrides diagnostics
parser.GetInterpreter().SetPredictionMode(PredictionMode.Sll);
parser.Interpreter.SetPredictionMode(PredictionMode.Sll);
}
parser.SetInputStream(tokens);
parser.SetTrace(trace);
parser.Trace = trace;
try
{
MethodInfo startRule = parserClass.GetMethod(startRuleName, (Type[])null);

View File

@ -68,8 +68,8 @@ namespace Antlr4.Runtime
private readonly IToken startToken;
public NoViableAltException(Parser recognizer) : this(recognizer, ((ITokenStream)
recognizer.GetInputStream()), recognizer.GetCurrentToken(), recognizer.GetCurrentToken
(), null, recognizer._ctx)
recognizer.InputStream), recognizer.CurrentToken, recognizer.CurrentToken, null
, recognizer._ctx)
{
}

View File

@ -48,13 +48,13 @@ namespace Antlr4.Runtime
{
public virtual void EnterEveryRule(ParserRuleContext ctx)
{
System.Console.Out.WriteLine("enter " + this._enclosing.GetRuleNames()[ctx.GetRuleIndex
System.Console.Out.WriteLine("enter " + this._enclosing.RuleNames[ctx.GetRuleIndex
()] + ", LT(1)=" + this._enclosing._input.Lt(1).Text);
}
public virtual void ExitEveryRule(ParserRuleContext ctx)
{
System.Console.Out.WriteLine("exit " + this._enclosing.GetRuleNames()[ctx.GetRuleIndex
System.Console.Out.WriteLine("exit " + this._enclosing.RuleNames[ctx.GetRuleIndex
()] + ", LT(1)=" + this._enclosing._input.Lt(1).Text);
}
@ -66,8 +66,8 @@ namespace Antlr4.Runtime
{
ParserRuleContext parent = (ParserRuleContext)((IRuleNode)node.Parent).RuleContext;
IToken token = node.Symbol;
System.Console.Out.WriteLine("consume " + token + " rule " + this._enclosing.GetRuleNames
()[parent.GetRuleIndex()] + " alt=" + parent.altNum);
System.Console.Out.WriteLine("consume " + token + " rule " + this._enclosing.RuleNames
[parent.GetRuleIndex()] + " alt=" + parent.altNum);
}
internal TraceListener(Parser _enclosing)
@ -155,9 +155,9 @@ namespace Antlr4.Runtime
/// <summary>reset the parser's state</summary>
public virtual void Reset()
{
if (((ITokenStream)GetInputStream()) != null)
if (((ITokenStream)InputStream) != null)
{
((ITokenStream)GetInputStream()).Seek(0);
((ITokenStream)InputStream).Seek(0);
}
_errHandler.EndErrorCondition(this);
_ctx = null;
@ -165,7 +165,7 @@ namespace Antlr4.Runtime
_tracer = null;
_precedenceStack.Clear();
_precedenceStack.Push(0);
ATNSimulator interpreter = GetInterpreter();
ATNSimulator interpreter = Interpreter;
if (interpreter != null)
{
interpreter.Reset();
@ -181,7 +181,7 @@ namespace Antlr4.Runtime
/// <exception cref="Antlr4.Runtime.RecognitionException"></exception>
public virtual IToken Match(int ttype)
{
IToken t = GetCurrentToken();
IToken t = CurrentToken;
if (t.Type == ttype)
{
_errHandler.EndErrorCondition(this);
@ -203,7 +203,7 @@ namespace Antlr4.Runtime
/// <exception cref="Antlr4.Runtime.RecognitionException"></exception>
public virtual IToken MatchWildcard()
{
IToken t = GetCurrentToken();
IToken t = CurrentToken;
if (t.Type > 0)
{
_errHandler.EndErrorCondition(this);
@ -244,14 +244,17 @@ namespace Antlr4.Runtime
/// somebody's children list. Contexts are then not candidates
/// for garbage collection.
/// </remarks>
public virtual void SetBuildParseTree(bool buildParseTrees)
public virtual bool BuildParseTree
{
this._buildParseTrees = buildParseTrees;
}
public virtual bool GetBuildParseTree()
{
return _buildParseTrees;
get
{
return _buildParseTrees;
}
set
{
bool buildParseTrees = value;
this._buildParseTrees = buildParseTrees;
}
}
/// <summary>Trim the internal lists of the parse tree during parsing to conserve memory.
@ -262,29 +265,13 @@ namespace Antlr4.Runtime
/// <code>false</code>
/// by default for a newly constructed parser.
/// </remarks>
/// <param name="trimParseTrees">
/// <value>
///
/// <code>true</code>
/// to trim the capacity of the
/// <see cref="ParserRuleContext.children">ParserRuleContext.children</see>
/// list to its size after a rule is parsed.
/// </param>
public virtual void SetTrimParseTree(bool trimParseTrees)
{
if (trimParseTrees)
{
if (GetTrimParseTree())
{
return;
}
AddParseListener(Parser.TrimToSizeListener.Instance);
}
else
{
RemoveParseListener(Parser.TrimToSizeListener.Instance);
}
}
/// </value>
/// <returns>
///
/// <code>true</code>
@ -295,25 +282,47 @@ namespace Antlr4.Runtime
/// <see cref="TrimToSizeListener">TrimToSizeListener</see>
/// during the parse process.
/// </returns>
public virtual bool GetTrimParseTree()
public virtual bool TrimParseTree
{
if (_parseListeners == null)
get
{
return false;
if (_parseListeners == null)
{
return false;
}
return _parseListeners.Contains(Parser.TrimToSizeListener.Instance);
}
set
{
bool trimParseTrees = value;
if (trimParseTrees)
{
if (TrimParseTree)
{
return;
}
AddParseListener(Parser.TrimToSizeListener.Instance);
}
else
{
RemoveParseListener(Parser.TrimToSizeListener.Instance);
}
}
return _parseListeners.Contains(Parser.TrimToSizeListener.Instance);
}
// public void setTraceATNStates(boolean traceATNStates) {
// this.traceATNStates = traceATNStates;
// }
//
// public boolean getTraceATNStates() {
// return traceATNStates;
// }
public virtual IList<IParseTreeListener> GetParseListeners()
public virtual IList<IParseTreeListener> ParseListeners
{
return _parseListeners;
get
{
// public void setTraceATNStates(boolean traceATNStates) {
// this.traceATNStates = traceATNStates;
// }
//
// public boolean getTraceATNStates() {
// return traceATNStates;
// }
return _parseListeners;
}
}
/// <summary>
@ -411,24 +420,33 @@ namespace Antlr4.Runtime
/// an error and next valid token match
/// See also reportError()
/// </remarks>
public virtual int GetNumberOfSyntaxErrors()
public virtual int NumberOfSyntaxErrors
{
return _syntaxErrors;
get
{
return _syntaxErrors;
}
}
public virtual IAntlrErrorStrategy GetErrorHandler()
public virtual IAntlrErrorStrategy ErrorHandler
{
return _errHandler;
get
{
return _errHandler;
}
set
{
IAntlrErrorStrategy handler = value;
this._errHandler = handler;
}
}
public virtual void SetErrorHandler(IAntlrErrorStrategy handler)
public override IIntStream InputStream
{
this._errHandler = handler;
}
public override IIntStream GetInputStream()
{
return _input;
get
{
return _input;
}
}
/// <summary>Set the token stream and reset the parser</summary>
@ -447,14 +465,17 @@ namespace Antlr4.Runtime
/// Match needs to return the current input symbol, which gets put
/// into the label for the associated token ref; e.g., x=ID.
/// </remarks>
public virtual IToken GetCurrentToken()
public virtual IToken CurrentToken
{
return _input.Lt(1);
get
{
return _input.Lt(1);
}
}
public virtual void NotifyErrorListeners(string msg)
{
NotifyErrorListeners(GetCurrentToken(), msg, null);
NotifyErrorListeners(CurrentToken, msg, null);
}
public virtual void NotifyErrorListeners(IToken offendingToken, string msg, RecognitionException
@ -485,10 +506,10 @@ namespace Antlr4.Runtime
/// </remarks>
public virtual IToken Consume()
{
IToken o = GetCurrentToken();
IToken o = CurrentToken;
if (o.Type != Eof)
{
((ITokenStream)GetInputStream()).Consume();
((ITokenStream)InputStream).Consume();
}
bool hasListener = _parseListeners != null && !_parseListeners.IsEmpty();
if (_buildParseTrees || hasListener)
@ -540,7 +561,7 @@ namespace Antlr4.Runtime
public virtual void EnterRule(ParserRuleContext localctx, int state, int ruleIndex
)
{
SetState(state);
State = state;
_ctx = localctx;
_ctx.start = _input.Lt(1);
if (_buildParseTrees)
@ -556,7 +577,7 @@ namespace Antlr4.Runtime
public virtual void EnterLeftFactoredRule(ParserRuleContext localctx, int state,
int ruleIndex)
{
SetState(state);
State = state;
if (_buildParseTrees)
{
ParserRuleContext factoredContext = (ParserRuleContext)_ctx.GetChild(_ctx.ChildCount
@ -585,7 +606,7 @@ namespace Antlr4.Runtime
{
TriggerExitRuleEvent();
}
SetState(_ctx.invokingState);
State = _ctx.invokingState;
_ctx = (ParserRuleContext)_ctx.parent;
}
@ -681,9 +702,12 @@ namespace Antlr4.Runtime
return null;
}
public virtual ParserRuleContext GetContext()
public virtual ParserRuleContext Context
{
return _ctx;
get
{
return _ctx;
}
}
public override bool Precpred(RuleContext localctx, int precedence)
@ -705,9 +729,9 @@ namespace Antlr4.Runtime
public virtual bool IsExpectedToken(int symbol)
{
// return getInterpreter().atn.nextTokens(_ctx);
ATN atn = GetInterpreter().atn;
ATN atn = Interpreter.atn;
ParserRuleContext ctx = _ctx;
ATNState s = atn.states[GetState()];
ATNState s = atn.states[State];
IntervalSet following = atn.NextTokens(s);
if (following.Contains(symbol))
{
@ -747,9 +771,9 @@ namespace Antlr4.Runtime
/// </remarks>
public virtual IntervalSet GetExpectedTokens()
{
ATN atn = GetInterpreter().atn;
ATN atn = Interpreter.atn;
ParserRuleContext ctx = _ctx;
ATNState s = atn.states[GetState()];
ATNState s = atn.states[State];
IntervalSet following = atn.NextTokens(s);
// System.out.println("following "+s+"="+following);
if (!following.Contains(IToken.Epsilon))
@ -778,23 +802,26 @@ namespace Antlr4.Runtime
public virtual IntervalSet GetExpectedTokensWithinCurrentRule()
{
ATN atn = GetInterpreter().atn;
ATNState s = atn.states[GetState()];
ATN atn = Interpreter.atn;
ATNState s = atn.states[State];
return atn.NextTokens(s);
}
// /** Compute the set of valid tokens reachable from the current
// * position in the parse.
// */
// public IntervalSet nextTokens(@NotNull RuleContext ctx) {
// ATN atn = getInterpreter().atn;
// ATNState s = atn.states.get(ctx.s);
// if ( s == null ) return null;
// return atn.nextTokens(s, ctx);
// }
public virtual ParserRuleContext GetRuleContext()
public virtual ParserRuleContext RuleContext
{
return _ctx;
get
{
// /** Compute the set of valid tokens reachable from the current
// * position in the parse.
// */
// public IntervalSet nextTokens(@NotNull RuleContext ctx) {
// ATN atn = getInterpreter().atn;
// ATNState s = atn.states.get(ctx.s);
// if ( s == null ) return null;
// return atn.nextTokens(s, ctx);
// }
return _ctx;
}
}
/// <summary>
@ -815,7 +842,7 @@ namespace Antlr4.Runtime
public virtual IList<string> GetRuleInvocationStack(RuleContext p)
{
string[] ruleNames = GetRuleNames();
string[] ruleNames = RuleNames;
IList<string> stack = new List<string>();
while (p != null)
{
@ -841,7 +868,7 @@ namespace Antlr4.Runtime
for (int d = 0; d < _interp.atn.decisionToDFA.Length; d++)
{
DFA dfa = _interp.atn.decisionToDFA[d];
s.AddItem(dfa.ToString(GetTokenNames(), GetRuleNames()));
s.AddItem(dfa.ToString(TokenNames, RuleNames));
}
return s;
}
@ -860,15 +887,18 @@ namespace Antlr4.Runtime
System.Console.Out.WriteLine();
}
System.Console.Out.WriteLine("Decision " + dfa.decision + ":");
System.Console.Out.Write(dfa.ToString(GetTokenNames(), GetRuleNames()));
System.Console.Out.Write(dfa.ToString(TokenNames, RuleNames));
seenOne = true;
}
}
}
public virtual string GetSourceName()
public virtual string SourceName
{
return _input.SourceName;
get
{
return _input.SourceName;
}
}
/// <summary>A convenience method for use most often with template rewrites.</summary>
@ -898,24 +928,39 @@ namespace Antlr4.Runtime
/// During a parse is sometimes useful to listen in on the rule entry and exit
/// events as well as token matches. This is for quick and dirty debugging.
/// </remarks>
public virtual void SetTrace(bool trace)
public virtual bool Trace
{
if (!trace)
get
{
RemoveParseListener(_tracer);
_tracer = null;
foreach (object o in ParseListeners)
{
if (o is Parser.TraceListener)
{
return true;
}
}
return false;
}
else
set
{
if (_tracer != null)
bool trace = value;
if (!trace)
{
RemoveParseListener(_tracer);
_tracer = null;
}
else
{
_tracer = new Parser.TraceListener(this);
if (_tracer != null)
{
RemoveParseListener(_tracer);
}
else
{
_tracer = new Parser.TraceListener(this);
}
AddParseListener(_tracer);
}
AddParseListener(_tracer);
}
}
}

View File

@ -80,7 +80,7 @@ namespace Antlr4.Runtime
this.ctx = ctx;
if (recognizer != null)
{
this.offendingState = recognizer.GetState();
this.offendingState = recognizer.State;
}
}
@ -92,7 +92,7 @@ namespace Antlr4.Runtime
this.ctx = ctx;
if (recognizer != null)
{
this.offendingState = recognizer.GetState();
this.offendingState = recognizer.State;
}
}

View File

@ -67,30 +67,45 @@ namespace Antlr4.Runtime
/// error reporting. The generated parsers implement a method
/// that overrides this to point to their String[] tokenNames.
/// </remarks>
public abstract string[] GetTokenNames();
public abstract string[] TokenNames
{
get;
}
public abstract string[] GetRuleNames();
public abstract string[] RuleNames
{
get;
}
/// <summary>For debugging and other purposes, might want the grammar name.</summary>
/// <remarks>
/// For debugging and other purposes, might want the grammar name.
/// Have ANTLR generate an implementation for this method.
/// </remarks>
public abstract string GetGrammarFileName();
public virtual ATN GetATN()
public abstract string GrammarFileName
{
return _interp.atn;
get;
}
public virtual ATNInterpreter GetInterpreter()
public virtual ATN Atn
{
return _interp;
get
{
return _interp.atn;
}
}
public virtual void SetInterpreter(ATNInterpreter interpreter)
public virtual ATNInterpreter Interpreter
{
_interp = interpreter;
get
{
return _interp;
}
set
{
ATNInterpreter interpreter = value;
_interp = interpreter;
}
}
/// <summary>What is the error header, normally line/character position information?</summary>
@ -190,11 +205,6 @@ namespace Antlr4.Runtime
{
}
public int GetState()
{
return _stateNumber;
}
/// <summary>
/// Indicate that the recognizer has changed internal state that is
/// consistent with the ATN state passed in.
@ -207,13 +217,24 @@ namespace Antlr4.Runtime
/// invoking rules. Combine this and we have complete ATN
/// configuration information.
/// </remarks>
public void SetState(int atnState)
public int State
{
// System.err.println("setState "+atnState);
_stateNumber = atnState;
get
{
return _stateNumber;
}
set
{
int atnState = value;
// System.err.println("setState "+atnState);
_stateNumber = atnState;
}
}
public abstract IIntStream InputStream
{
get;
}
// if ( traceATNStates ) _ctx.trace(atnState);
public abstract IIntStream GetInputStream();
}
}

View File

@ -198,8 +198,7 @@ namespace Antlr4.Runtime
/// <exception cref="Javax.Print.PrintException"></exception>
public virtual void Save(Parser parser, string fileName)
{
IList<string> ruleNames = parser != null ? Arrays.AsList(parser.GetRuleNames()) :
null;
IList<string> ruleNames = parser != null ? Arrays.AsList(parser.RuleNames) : null;
Save(ruleNames, fileName);
}
@ -209,8 +208,7 @@ namespace Antlr4.Runtime
public virtual void Save(Parser parser, string fileName, string fontName, int fontSize
)
{
IList<string> ruleNames = parser != null ? Arrays.AsList(parser.GetRuleNames()) :
null;
IList<string> ruleNames = parser != null ? Arrays.AsList(parser.RuleNames) : null;
Save(ruleNames, fileName, fontName, fontSize);
}
@ -282,7 +280,7 @@ namespace Antlr4.Runtime
public virtual string ToString<_T0>(Recognizer<_T0> recog, Antlr4.Runtime.RuleContext
stop)
{
string[] ruleNames = recog != null ? recog.GetRuleNames() : null;
string[] ruleNames = recog != null ? recog.RuleNames : null;
IList<string> ruleNamesList = ruleNames != null ? Arrays.AsList(ruleNames) : null;
return ToString(ruleNamesList, stop);
}

View File

@ -65,7 +65,7 @@ namespace Antlr4.Runtime.Tree
/// </remarks>
public static string ToStringTree(ITree t, Parser recog)
{
string[] ruleNames = recog != null ? recog.GetRuleNames() : null;
string[] ruleNames = recog != null ? recog.RuleNames : null;
IList<string> ruleNamesList = ruleNames != null ? Arrays.AsList(ruleNames) : null;
return ToStringTree(t, ruleNamesList);
}
@ -105,7 +105,7 @@ namespace Antlr4.Runtime.Tree
public static string GetNodeText(ITree t, Parser recog)
{
string[] ruleNames = recog != null ? recog.GetRuleNames() : null;
string[] ruleNames = recog != null ? recog.RuleNames : null;
IList<string> ruleNamesList = ruleNames != null ? Arrays.AsList(ruleNames) : null;
return GetNodeText(t, ruleNamesList);
}

@ -1 +1 @@
Subproject commit 5cda16588918c8873c62abdeb9ce88e600e5d045
Subproject commit 6743730f698969a938bec3ec2c42c4728a97256c