Updated type mappings for interfaces

This commit is contained in:
Sam Harwell 2013-02-15 15:44:38 -06:00
parent 457d6e0aa4
commit fdec53d82d
48 changed files with 300 additions and 292 deletions

View File

@ -232,8 +232,7 @@ namespace Antlr4.Runtime.Atn
/// <code>true</code>
/// , ambiguous alternatives are reported when they are
/// encountered within
/// <see cref="ExecATN(Antlr4.Runtime.Dfa.DFA, Antlr4.Runtime.TokenStream, int, SimulatorState)
/// ">ExecATN(Antlr4.Runtime.Dfa.DFA, Antlr4.Runtime.TokenStream, int, SimulatorState)
/// <see cref="ExecATN(Antlr4.Runtime.Dfa.DFA, ITokenStream, int, SimulatorState)">ExecATN(Antlr4.Runtime.Dfa.DFA, ITokenStream, int, SimulatorState)
/// </see>
/// . When
/// <code>false</code>
@ -288,13 +287,13 @@ namespace Antlr4.Runtime.Atn
{
}
public virtual int AdaptivePredict(TokenStream input, int decision, ParserRuleContext
public virtual int AdaptivePredict(ITokenStream input, int decision, ParserRuleContext
outerContext)
{
return AdaptivePredict(input, decision, outerContext, false);
}
public virtual int AdaptivePredict(TokenStream input, int decision, ParserRuleContext
public virtual int AdaptivePredict(ITokenStream input, int decision, ParserRuleContext
outerContext, bool useContext)
{
DFA dfa = atn.decisionToDFA[decision];
@ -357,7 +356,7 @@ namespace Antlr4.Runtime.Atn
}
}
public virtual SimulatorState GetStartState(DFA dfa, TokenStream input, ParserRuleContext
public virtual SimulatorState GetStartState(DFA dfa, ITokenStream input, ParserRuleContext
outerContext, bool useContext)
{
if (!useContext)
@ -391,7 +390,7 @@ namespace Antlr4.Runtime.Atn
return new SimulatorState(outerContext, s0, useContext, remainingContext);
}
public virtual int PredictATN(DFA dfa, TokenStream input, ParserRuleContext outerContext
public virtual int PredictATN(DFA dfa, ITokenStream input, ParserRuleContext outerContext
, bool useContext)
{
if (outerContext == null)
@ -425,7 +424,7 @@ namespace Antlr4.Runtime.Atn
return alt;
}
public virtual int ExecDFA(DFA dfa, TokenStream input, int startIndex, SimulatorState
public virtual int ExecDFA(DFA dfa, ITokenStream input, int startIndex, SimulatorState
state)
{
ParserRuleContext outerContext = state.outerContext;
@ -648,7 +647,7 @@ namespace Antlr4.Runtime.Atn
/// conflict + preds
/// TODO: greedy + those
/// </remarks>
public virtual int ExecATN(DFA dfa, TokenStream input, int startIndex, SimulatorState
public virtual int ExecATN(DFA dfa, ITokenStream input, int startIndex, SimulatorState
initialState)
{
ParserRuleContext outerContext = initialState.outerContext;
@ -795,7 +794,7 @@ namespace Antlr4.Runtime.Atn
}
}
protected internal virtual int HandleNoViableAlt(TokenStream input, int startIndex
protected internal virtual int HandleNoViableAlt(ITokenStream input, int startIndex
, SimulatorState previous)
{
if (previous.s0 != null)
@ -1835,7 +1834,7 @@ namespace Antlr4.Runtime.Atn
{
System.Console.Error.WriteLine(t + " ttype out of range: " + Arrays.ToString(tokensNames
));
System.Console.Error.WriteLine(((CommonTokenStream)((TokenStream)parser.GetInputStream
System.Console.Error.WriteLine(((CommonTokenStream)((ITokenStream)parser.GetInputStream
())).GetTokens());
}
else
@ -1846,7 +1845,7 @@ namespace Antlr4.Runtime.Atn
return t.ToString();
}
public virtual string GetLookaheadName(TokenStream input)
public virtual string GetLookaheadName(ITokenStream input)
{
return GetTokenName(input.La(1));
}
@ -1880,7 +1879,7 @@ namespace Antlr4.Runtime.Atn
}
[NotNull]
public virtual NoViableAltException NoViableAlt(TokenStream input, ParserRuleContext
public virtual NoViableAltException NoViableAlt(ITokenStream input, ParserRuleContext
outerContext, ATNConfigSet configs, int startIndex)
{
return new NoViableAltException(parser, input, input.Get(startIndex), input.Lt(1)
@ -2085,12 +2084,12 @@ namespace Antlr4.Runtime.Atn
{
Interval interval = Interval.Of(startIndex, stopIndex);
System.Console.Out.WriteLine("reportAttemptingFullContext decision=" + dfa.decision
+ ":" + initialState.s0.configs + ", input=" + ((TokenStream)parser.GetInputStream
+ ":" + initialState.s0.configs + ", input=" + ((ITokenStream)parser.GetInputStream
()).GetText(interval));
}
if (parser != null)
{
((ParserErrorListener)parser.GetErrorListenerDispatch()).ReportAttemptingFullContext
((IParserErrorListener)parser.GetErrorListenerDispatch()).ReportAttemptingFullContext
(parser, dfa, startIndex, stopIndex, initialState);
}
}
@ -2102,12 +2101,12 @@ namespace Antlr4.Runtime.Atn
{
Interval interval = Interval.Of(startIndex, stopIndex);
System.Console.Out.WriteLine("reportContextSensitivity decision=" + dfa.decision
+ ":" + acceptState.s0.configs + ", input=" + ((TokenStream)parser.GetInputStream
+ ":" + acceptState.s0.configs + ", input=" + ((ITokenStream)parser.GetInputStream
()).GetText(interval));
}
if (parser != null)
{
((ParserErrorListener)parser.GetErrorListenerDispatch()).ReportContextSensitivity
((IParserErrorListener)parser.GetErrorListenerDispatch()).ReportContextSensitivity
(parser, dfa, startIndex, stopIndex, acceptState);
}
}
@ -2136,11 +2135,11 @@ namespace Antlr4.Runtime.Atn
// }
Interval interval = Interval.Of(startIndex, stopIndex);
System.Console.Out.WriteLine("reportAmbiguity " + ambigAlts + ":" + configs + ", input="
+ ((TokenStream)parser.GetInputStream()).GetText(interval));
+ ((ITokenStream)parser.GetInputStream()).GetText(interval));
}
if (parser != null)
{
((ParserErrorListener)parser.GetErrorListenerDispatch()).ReportAmbiguity(parser,
((IParserErrorListener)parser.GetErrorListenerDispatch()).ReportAmbiguity(parser,
dfa, startIndex, stopIndex, ambigAlts, configs);
}
}

View File

@ -35,7 +35,7 @@ using Sharpen;
namespace Antlr4.Runtime
{
/// <author>Sam Harwell</author>
public class BaseErrorListener : ParserErrorListener
public class BaseErrorListener : IParserErrorListener
{
public virtual void SyntaxError<T>(Recognizer<T, object> recognizer, T offendingSymbol
, int line, int charPositionInLine, string msg, RecognitionException e) where T:

View File

@ -64,10 +64,10 @@ namespace Antlr4.Runtime
/// because I don't want
/// to confuse small moving window of tokens it uses for the full buffer.
/// </remarks>
public class BufferedTokenStream : TokenStream
public class BufferedTokenStream : ITokenStream
{
[NotNull]
protected internal TokenSource tokenSource;
protected internal ITokenSource tokenSource;
/// <summary>
/// Record every single token pulled from the source so we can reproduce
@ -113,7 +113,7 @@ namespace Antlr4.Runtime
/// <seealso cref="Fetch(int)">Fetch(int)</seealso>
protected internal bool fetchedEOF;
public BufferedTokenStream(TokenSource tokenSource)
public BufferedTokenStream(ITokenSource tokenSource)
{
if (tokenSource == null)
{
@ -122,7 +122,7 @@ namespace Antlr4.Runtime
this.tokenSource = tokenSource;
}
public virtual TokenSource GetTokenSource()
public virtual ITokenSource GetTokenSource()
{
return tokenSource;
}
@ -215,9 +215,9 @@ namespace Antlr4.Runtime
for (int i = 0; i < n; i++)
{
Token t = tokenSource.NextToken();
if (t is WritableToken)
if (t is IWritableToken)
{
((WritableToken)t).SetTokenIndex(tokens.Count);
((IWritableToken)t).SetTokenIndex(tokens.Count);
}
tokens.AddItem(t);
if (t.GetType() == Token.Eof)
@ -344,7 +344,7 @@ namespace Antlr4.Runtime
/// <summary>Reset this token stream by setting its token source.</summary>
/// <remarks>Reset this token stream by setting its token source.</remarks>
public virtual void SetTokenSource(TokenSource tokenSource)
public virtual void SetTokenSource(ITokenSource tokenSource)
{
this.tokenSource = tokenSource;
tokens.Clear();

View File

@ -35,7 +35,7 @@ using Sharpen;
namespace Antlr4.Runtime
{
[System.Serializable]
public class CommonToken : WritableToken
public class CommonToken : IWritableToken
{
private const long serialVersionUID = -6708843461296520577L;
@ -47,7 +47,7 @@ namespace Antlr4.Runtime
protected internal int channel = DefaultChannel;
protected internal Tuple<TokenSource, CharStream> source;
protected internal Tuple<ITokenSource, CharStream> source;
/// <summary>We need to be able to change the text once in a while.</summary>
/// <remarks>
@ -74,7 +74,7 @@ namespace Antlr4.Runtime
this.type = type;
}
public CommonToken(Tuple<TokenSource, CharStream> source, int type, int channel,
public CommonToken(Tuple<ITokenSource, CharStream> source, int type, int channel,
int start, int stop)
{
this.source = source;
@ -220,7 +220,7 @@ namespace Antlr4.Runtime
this.index = index;
}
public virtual TokenSource GetTokenSource()
public virtual ITokenSource GetTokenSource()
{
return source.GetItem1();
}

View File

@ -34,9 +34,9 @@ using Sharpen;
namespace Antlr4.Runtime
{
public class CommonTokenFactory : TokenFactory
public class CommonTokenFactory : ITokenFactory
{
public static readonly TokenFactory Default = new Antlr4.Runtime.CommonTokenFactory
public static readonly ITokenFactory Default = new Antlr4.Runtime.CommonTokenFactory
();
/// <summary>Copy text for token out of input char stream.</summary>
@ -65,7 +65,7 @@ namespace Antlr4.Runtime
}
public virtual CommonToken Create<_T0>(Tuple<_T0> source, int type, string text,
int channel, int start, int stop, int line, int charPositionInLine) where _T0:TokenSource
int channel, int start, int stop, int line, int charPositionInLine) where _T0:ITokenSource
{
CommonToken t = new CommonToken(source, type, channel, start, stop);
t.SetLine(line);

View File

@ -66,11 +66,11 @@ namespace Antlr4.Runtime
/// </remarks>
protected internal int channel = Token.DefaultChannel;
public CommonTokenStream(TokenSource tokenSource) : base(tokenSource)
public CommonTokenStream(ITokenSource tokenSource) : base(tokenSource)
{
}
public CommonTokenStream(TokenSource tokenSource, int channel) : this(tokenSource
public CommonTokenStream(ITokenSource tokenSource, int channel) : this(tokenSource
)
{
this.channel = channel;

View File

@ -33,7 +33,7 @@ using Sharpen;
namespace Antlr4.Runtime
{
/// <author>Sam Harwell</author>
public class ConsoleErrorListener : ANTLRErrorListener<object>
public class ConsoleErrorListener : IAntlrErrorListener<object>
{
public static readonly ConsoleErrorListener Instance = new ConsoleErrorListener();

View File

@ -43,7 +43,7 @@ namespace Antlr4.Runtime
/// This is the default error handling mechanism for ANTLR parsers
/// and tree parsers.
/// </remarks>
public class DefaultErrorStrategy : ANTLRErrorStrategy
public class DefaultErrorStrategy : IAntlrErrorStrategy
{
/// <summary>
/// This is true after we see an error and before having successfully
@ -145,7 +145,7 @@ namespace Antlr4.Runtime
// ", lastErrorIndex="+
// lastErrorIndex+
// ", states="+lastErrorStates);
if (lastErrorIndex == ((TokenStream)recognizer.GetInputStream()).Index() && lastErrorStates
if (lastErrorIndex == ((ITokenStream)recognizer.GetInputStream()).Index() && lastErrorStates
!= null && lastErrorStates.Contains(recognizer.GetState()))
{
// uh oh, another error at same token index and previously-visited
@ -157,7 +157,7 @@ namespace Antlr4.Runtime
// System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]);
recognizer.Consume();
}
lastErrorIndex = ((TokenStream)recognizer.GetInputStream()).Index();
lastErrorIndex = ((ITokenStream)recognizer.GetInputStream()).Index();
if (lastErrorStates == null)
{
lastErrorStates = new IntervalSet();
@ -193,7 +193,7 @@ namespace Antlr4.Runtime
{
return;
}
TokenStream tokens = ((TokenStream)recognizer.GetInputStream());
ITokenStream tokens = ((ITokenStream)recognizer.GetInputStream());
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 == Token.Eof)
@ -245,7 +245,7 @@ namespace Antlr4.Runtime
public virtual void ReportNoViableAlternative(Parser recognizer, NoViableAltException
e)
{
TokenStream tokens = ((TokenStream)recognizer.GetInputStream());
ITokenStream tokens = ((ITokenStream)recognizer.GetInputStream());
string input;
if (tokens != null)
{
@ -363,7 +363,7 @@ namespace Antlr4.Runtime
// if next token is what we are looking for then "delete" this token
public virtual bool SingleTokenInsertion(Parser recognizer)
{
int currentSymbolType = ((TokenStream)recognizer.GetInputStream()).La(1);
int currentSymbolType = ((ITokenStream)recognizer.GetInputStream()).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
@ -384,7 +384,7 @@ namespace Antlr4.Runtime
public virtual Token SingleTokenDeletion(Parser recognizer)
{
int nextTokenType = ((TokenStream)recognizer.GetInputStream()).La(2);
int nextTokenType = ((ITokenStream)recognizer.GetInputStream()).La(2);
IntervalSet expecting = GetExpectedTokens(recognizer);
if (expecting.Contains(nextTokenType))
{
@ -436,19 +436,19 @@ namespace Antlr4.Runtime
tokenText = "<missing " + recognizer.GetTokenNames()[expectedTokenType] + ">";
}
Token current = currentSymbol;
Token lookback = ((TokenStream)recognizer.GetInputStream()).Lt(-1);
Token lookback = ((ITokenStream)recognizer.GetInputStream()).Lt(-1);
if (current.GetType() == Token.Eof && lookback != null)
{
current = lookback;
}
return ConstructToken(((TokenStream)recognizer.GetInputStream()).GetTokenSource()
, expectedTokenType, tokenText, current);
return ConstructToken(((ITokenStream)recognizer.GetInputStream()).GetTokenSource(
), expectedTokenType, tokenText, current);
}
protected internal virtual Token ConstructToken(TokenSource tokenSource, int expectedTokenType
protected internal virtual Token ConstructToken(ITokenSource tokenSource, int expectedTokenType
, string tokenText, Token current)
{
TokenFactory factory = tokenSource.GetTokenFactory();
ITokenFactory factory = tokenSource.GetTokenFactory();
return factory.Create(Tuple.Create(tokenSource, current.GetTokenSource().GetInputStream
()), expectedTokenType, tokenText, Token.DefaultChannel, -1, -1, current.GetLine
(), current.GetCharPositionInLine());
@ -536,13 +536,13 @@ namespace Antlr4.Runtime
public virtual void ConsumeUntil(Parser recognizer, IntervalSet set)
{
// System.err.println("consumeUntil("+set.toString(recognizer.getTokenNames())+")");
int ttype = ((TokenStream)recognizer.GetInputStream()).La(1);
int ttype = ((ITokenStream)recognizer.GetInputStream()).La(1);
while (ttype != Token.Eof && !set.Contains(ttype))
{
//System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]);
// recognizer.getInputStream().consume();
recognizer.Consume();
ttype = ((TokenStream)recognizer.GetInputStream()).La(1);
ttype = ((ITokenStream)recognizer.GetInputStream()).La(1);
}
}
}

View File

@ -35,7 +35,7 @@ using Sharpen;
namespace Antlr4.Runtime.Dfa
{
/// <author>Sam Harwell</author>
public abstract class AbstractEdgeMap<T> : EdgeMap<T>
public abstract class AbstractEdgeMap<T> : IEdgeMap<T>
{
protected internal readonly int minIndex;
@ -51,8 +51,8 @@ namespace Antlr4.Runtime.Dfa
public abstract Antlr4.Runtime.Dfa.AbstractEdgeMap<T> Put(int key, T value);
public virtual Antlr4.Runtime.Dfa.AbstractEdgeMap<T> PutAll<_T0>(EdgeMap<_T0> m) where
_T0:T
public virtual Antlr4.Runtime.Dfa.AbstractEdgeMap<T> PutAll<_T0>(IEdgeMap<_T0> m)
where _T0:T
{
Antlr4.Runtime.Dfa.AbstractEdgeMap<T> result = this;
foreach (KeyValuePair<int, T> entry in m.EntrySet())

View File

@ -96,7 +96,7 @@ namespace Antlr4.Runtime.Dfa
return ((Antlr4.Runtime.Dfa.ArrayEdgeMap<T>)Put(key, null));
}
public override AbstractEdgeMap<T> PutAll<_T0>(EdgeMap<_T0> m)
public override AbstractEdgeMap<T> PutAll<_T0>(IEdgeMap<_T0> m)
{
if (m.IsEmpty())
{

View File

@ -68,8 +68,8 @@ namespace Antlr4.Runtime.Dfa
/// <summary>
/// Set of configs for a DFA state with at least one conflict? Mainly used as "return value"
/// from
/// <see cref="Antlr4.Runtime.Atn.ParserATNSimulator.PredictATN(DFA, Antlr4.Runtime.TokenStream, Antlr4.Runtime.ParserRuleContext, bool)
/// ">Antlr4.Runtime.Atn.ParserATNSimulator.PredictATN(DFA, Antlr4.Runtime.TokenStream, Antlr4.Runtime.ParserRuleContext, bool)
/// <see cref="Antlr4.Runtime.Atn.ParserATNSimulator.PredictATN(DFA, ITokenStream, Antlr4.Runtime.ParserRuleContext, bool)
/// ">Antlr4.Runtime.Atn.ParserATNSimulator.PredictATN(DFA, ITokenStream, Antlr4.Runtime.ParserRuleContext, bool)
/// </see>
/// for retry.
/// </summary>

View File

@ -28,7 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.Collections.Generic;
using Antlr4.Runtime.Dfa;
using Antlr4.Runtime.Misc;
using Sharpen;
@ -47,16 +46,16 @@ namespace Antlr4.Runtime.Dfa
T Get(int key);
[NotNull]
EdgeMap<T> Put(int key, T value);
IEdgeMap<T> Put(int key, T value);
[NotNull]
EdgeMap<T> Remove(int key);
IEdgeMap<T> Remove(int key);
[NotNull]
EdgeMap<T> PutAll<_T0>(EdgeMap<_T0> m) where _T0:T;
IEdgeMap<T> PutAll<_T0>(IEdgeMap<_T0> m) where _T0:T;
[NotNull]
EdgeMap<T> Clear();
IEdgeMap<T> Clear();
[NotNull]
IDictionary<int, T> ToMap();

View File

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

View File

@ -62,7 +62,7 @@ namespace Antlr4.Runtime
}
public FailedPredicateException(Parser recognizer, string predicate, string message
) : base(FormatMessage(predicate, message), recognizer, ((TokenStream)recognizer
) : base(FormatMessage(predicate, message), recognizer, ((ITokenStream)recognizer
.GetInputStream()), recognizer._ctx)
{
ATNState s = recognizer.GetInterpreter().atn.states[recognizer.GetState()];

View File

@ -45,7 +45,7 @@ namespace Antlr4.Runtime
{
private const long serialVersionUID = 1532568338707443067L;
public InputMismatchException(Parser recognizer) : base(recognizer, ((TokenStream
public InputMismatchException(Parser recognizer) : base(recognizer, ((ITokenStream
)recognizer.GetInputStream()), recognizer._ctx)
{
this.SetOffendingToken(recognizer.GetCurrentToken());

View File

@ -44,7 +44,7 @@ namespace Antlr4.Runtime
/// uses simplified match() and error recovery mechanisms in the interest
/// of speed.
/// </remarks>
public abstract class Lexer : Recognizer<int, LexerATNSimulator>, TokenSource
public abstract class Lexer : Recognizer<int, LexerATNSimulator>, ITokenSource
{
public const int DefaultMode = 0;
@ -62,10 +62,10 @@ namespace Antlr4.Runtime
public CharStream _input;
protected internal Tuple<TokenSource, CharStream> _tokenFactorySourcePair;
protected internal Tuple<ITokenSource, CharStream> _tokenFactorySourcePair;
/// <summary>How to create token objects</summary>
protected internal TokenFactory _factory = CommonTokenFactory.Default;
protected internal ITokenFactory _factory = CommonTokenFactory.Default;
/// <summary>The goal of all lexer rules/methods is to create a token object.</summary>
/// <remarks>
@ -274,12 +274,12 @@ outer_break: ;
return _mode;
}
public virtual TokenFactory GetTokenFactory()
public virtual ITokenFactory GetTokenFactory()
{
return _factory;
}
public virtual void SetTokenFactory(TokenFactory factory)
public virtual void SetTokenFactory(ITokenFactory factory)
{
this._factory = factory;
}
@ -492,7 +492,7 @@ outer_break: ;
{
string text = _input.GetText(Interval.Of(_tokenStartCharIndex, _input.Index()));
string msg = "token recognition error at: '" + GetErrorDisplay(text) + "'";
ANTLRErrorListener<int> listener = GetErrorListenerDispatch();
IAntlrErrorListener<int> listener = GetErrorListenerDispatch();
listener.SyntaxError(this, null, _tokenStartLine, _tokenStartCharPositionInLine,
msg, e);
}

View File

@ -28,7 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.Collections.Generic;
using Antlr4.Runtime.Misc;
using Sharpen;
namespace Antlr4.Runtime.Misc
@ -46,7 +45,7 @@ namespace Antlr4.Runtime.Misc
/// Add all elements from incoming set to this set. Can limit
/// to set of its own type. Return "this" so we can chain calls.
/// </remarks>
IntSet AddAll(IntSet set);
IIntSet AddAll(IIntSet set);
/// <summary>
/// Return the intersection of this set with the argument, creating
@ -56,13 +55,13 @@ namespace Antlr4.Runtime.Misc
/// Return the intersection of this set with the argument, creating
/// a new set.
/// </remarks>
IntSet And(IntSet a);
IIntSet And(IIntSet a);
IntSet Complement(IntSet elements);
IIntSet Complement(IIntSet elements);
IntSet Or(IntSet a);
IIntSet Or(IIntSet a);
IntSet Subtract(IntSet a);
IIntSet Subtract(IIntSet a);
/// <summary>
/// Return the size of this set (not the underlying implementation's

View File

@ -53,7 +53,7 @@ namespace Antlr4.Runtime.Misc
/// elements are encoded with an index pair where both intervals are the same.
/// The ranges are ordered and disjoint so that 2..6 appears before 101..103.
/// </remarks>
public class IntervalSet : IntSet
public class IntervalSet : IIntSet
{
public static readonly Antlr4.Runtime.Misc.IntervalSet CompleteCharSet = Antlr4.Runtime.Misc.IntervalSet
.Of(0, Lexer.MaxCharValue);
@ -219,7 +219,7 @@ namespace Antlr4.Runtime.Misc
return r;
}
public virtual Antlr4.Runtime.Misc.IntervalSet AddAll(IntSet set)
public virtual Antlr4.Runtime.Misc.IntervalSet AddAll(IIntSet set)
{
if (set == null)
{
@ -259,7 +259,7 @@ namespace Antlr4.Runtime.Misc
/// this. The computation is (vocabulary - this).
/// 'this' is assumed to be either a subset or equal to vocabulary.
/// </remarks>
public virtual Antlr4.Runtime.Misc.IntervalSet Complement(IntSet vocabulary)
public virtual Antlr4.Runtime.Misc.IntervalSet Complement(IIntSet vocabulary)
{
if (vocabulary == null)
{
@ -318,7 +318,7 @@ namespace Antlr4.Runtime.Misc
/// other is assumed to be a subset of this;
/// anything that is in other but not in this will be ignored.
/// </remarks>
public virtual Antlr4.Runtime.Misc.IntervalSet Subtract(IntSet other)
public virtual Antlr4.Runtime.Misc.IntervalSet Subtract(IIntSet other)
{
// assume the whole unicode range here for the complement
// because it doesn't matter. Anything beyond the max of this' set
@ -330,7 +330,7 @@ namespace Antlr4.Runtime.Misc
));
}
public virtual Antlr4.Runtime.Misc.IntervalSet Or(IntSet a)
public virtual Antlr4.Runtime.Misc.IntervalSet Or(IIntSet a)
{
Antlr4.Runtime.Misc.IntervalSet o = new Antlr4.Runtime.Misc.IntervalSet();
o.AddAll(this);
@ -345,7 +345,7 @@ namespace Antlr4.Runtime.Misc
/// just walk them together. This is roughly O(min(n,m)) for interval
/// list lengths n and m.
/// </remarks>
public virtual Antlr4.Runtime.Misc.IntervalSet And(IntSet other)
public virtual Antlr4.Runtime.Misc.IntervalSet And(IIntSet other)
{
if (other == null)
{

View File

@ -214,8 +214,8 @@ namespace Antlr4.Runtime.Misc
{
System.Console.Error.WriteLine("Can't load " + parserName);
}
Constructor<Parser> parserCtor = parserClass.GetConstructor(typeof(TokenStream));
parser = parserCtor.NewInstance((TokenStream)null);
Constructor<Parser> parserCtor = parserClass.GetConstructor(typeof(ITokenStream));
parser = parserCtor.NewInstance((ITokenStream)null);
}
if (inputFiles.IsEmpty())
{

View File

@ -67,13 +67,13 @@ namespace Antlr4.Runtime
[NotNull]
private readonly Token startToken;
public NoViableAltException(Parser recognizer) : this(recognizer, ((TokenStream)recognizer
.GetInputStream()), recognizer.GetCurrentToken(), recognizer.GetCurrentToken(),
null, recognizer._ctx)
public NoViableAltException(Parser recognizer) : this(recognizer, ((ITokenStream)
recognizer.GetInputStream()), recognizer.GetCurrentToken(), recognizer.GetCurrentToken
(), null, recognizer._ctx)
{
}
public NoViableAltException(Recognizer<Token, object> recognizer, TokenStream input
public NoViableAltException(Recognizer<Token, object> recognizer, ITokenStream input
, Token startToken, Token offendingToken, ATNConfigSet deadEndConfigs, ParserRuleContext
ctx) : base(recognizer, input, ctx)
{

View File

@ -33,7 +33,6 @@ using Antlr4.Runtime;
using Antlr4.Runtime.Atn;
using Antlr4.Runtime.Dfa;
using Antlr4.Runtime.Misc;
using Antlr4.Runtime.Tree;
using Sharpen;
namespace Antlr4.Runtime
@ -44,7 +43,7 @@ namespace Antlr4.Runtime
/// </remarks>
public abstract class Parser : Recognizer<Token, ParserATNSimulator>
{
public class TraceListener : ParseTreeListener
public class TraceListener : IParseTreeListener
{
public virtual void EnterEveryRule(ParserRuleContext ctx)
{
@ -58,11 +57,11 @@ namespace Antlr4.Runtime
()] + ", LT(1)=" + this._enclosing._input.Lt(1).GetText());
}
public virtual void VisitErrorNode(ErrorNode node)
public virtual void VisitErrorNode(IErrorNode node)
{
}
public virtual void VisitTerminal(TerminalNode node)
public virtual void VisitTerminal(ITerminalNode node)
{
ParserRuleContext parent = (ParserRuleContext)node.GetParent().GetRuleContext();
Token token = node.GetSymbol();
@ -78,16 +77,16 @@ namespace Antlr4.Runtime
private readonly Parser _enclosing;
}
public class TrimToSizeListener : ParseTreeListener
public class TrimToSizeListener : IParseTreeListener
{
public static readonly Parser.TrimToSizeListener Instance = new Parser.TrimToSizeListener
();
public virtual void VisitTerminal(TerminalNode node)
public virtual void VisitTerminal(ITerminalNode node)
{
}
public virtual void VisitErrorNode(ErrorNode node)
public virtual void VisitErrorNode(IErrorNode node)
{
}
@ -104,9 +103,9 @@ namespace Antlr4.Runtime
}
}
protected internal ANTLRErrorStrategy _errHandler = new DefaultErrorStrategy();
protected internal IAntlrErrorStrategy _errHandler = new DefaultErrorStrategy();
protected internal TokenStream _input;
protected internal ITokenStream _input;
protected internal readonly IntegerStack _precedenceStack;
@ -137,13 +136,13 @@ namespace Antlr4.Runtime
/// </remarks>
/// <seealso cref="Antlr4.Runtime.Tree.ParseTreeWalker">Antlr4.Runtime.Tree.ParseTreeWalker
/// </seealso>
protected internal IList<ParseTreeListener> _parseListeners;
protected internal IList<IParseTreeListener> _parseListeners;
/// <summary>Did the recognizer encounter a syntax error? Track how many.</summary>
/// <remarks>Did the recognizer encounter a syntax error? Track how many.</remarks>
protected internal int _syntaxErrors = 0;
public Parser(TokenStream input)
public Parser(ITokenStream input)
{
{
_precedenceStack = new IntegerStack();
@ -155,9 +154,9 @@ namespace Antlr4.Runtime
/// <summary>reset the parser's state</summary>
public virtual void Reset()
{
if (((TokenStream)GetInputStream()) != null)
if (((ITokenStream)GetInputStream()) != null)
{
((TokenStream)GetInputStream()).Seek(0);
((ITokenStream)GetInputStream()).Seek(0);
}
_errHandler.EndErrorCondition(this);
_ctx = null;
@ -311,7 +310,7 @@ namespace Antlr4.Runtime
// public boolean getTraceATNStates() {
// return traceATNStates;
// }
public virtual IList<ParseTreeListener> GetParseListeners()
public virtual IList<IParseTreeListener> GetParseListeners()
{
return _parseListeners;
}
@ -329,7 +328,7 @@ namespace Antlr4.Runtime
/// ParseTreeListener to a ParseTreeWalker instead of giving it to
/// the parser!!!!
/// </remarks>
public virtual void AddParseListener(ParseTreeListener listener)
public virtual void AddParseListener(IParseTreeListener listener)
{
if (listener == null)
{
@ -337,12 +336,12 @@ namespace Antlr4.Runtime
}
if (_parseListeners == null)
{
_parseListeners = new AList<ParseTreeListener>();
_parseListeners = new AList<IParseTreeListener>();
}
this._parseListeners.AddItem(listener);
}
public virtual void RemoveParseListener(ParseTreeListener l)
public virtual void RemoveParseListener(IParseTreeListener l)
{
if (l == null)
{
@ -375,7 +374,7 @@ namespace Antlr4.Runtime
/// </remarks>
public virtual void TriggerEnterRuleEvent()
{
foreach (ParseTreeListener l in _parseListeners)
foreach (IParseTreeListener l in _parseListeners)
{
l.EnterEveryRule(_ctx);
_ctx.EnterRule(l);
@ -397,7 +396,7 @@ namespace Antlr4.Runtime
// reverse order walk of listeners
for (int i = _parseListeners.Count - 1; i >= 0; i--)
{
ParseTreeListener l = _parseListeners[i];
IParseTreeListener l = _parseListeners[i];
_ctx.ExitRule(l);
l.ExitEveryRule(_ctx);
}
@ -416,12 +415,12 @@ namespace Antlr4.Runtime
return _syntaxErrors;
}
public virtual ANTLRErrorStrategy GetErrorHandler()
public virtual IAntlrErrorStrategy GetErrorHandler()
{
return _errHandler;
}
public virtual void SetErrorHandler(ANTLRErrorStrategy handler)
public virtual void SetErrorHandler(IAntlrErrorStrategy handler)
{
this._errHandler = handler;
}
@ -432,7 +431,7 @@ namespace Antlr4.Runtime
}
/// <summary>Set the token stream and reset the parser</summary>
public virtual void SetInputStream(TokenStream input)
public virtual void SetInputStream(ITokenStream input)
{
this._input = null;
Reset();
@ -467,7 +466,7 @@ namespace Antlr4.Runtime
line = offendingToken.GetLine();
charPositionInLine = offendingToken.GetCharPositionInLine();
}
ANTLRErrorListener<Token> listener = ((ParserErrorListener)GetErrorListenerDispatch
IAntlrErrorListener<Token> listener = ((IParserErrorListener)GetErrorListenerDispatch
());
listener.SyntaxError(this, offendingToken, line, charPositionInLine, msg, e);
}
@ -488,17 +487,17 @@ namespace Antlr4.Runtime
Token o = GetCurrentToken();
if (o.GetType() != Eof)
{
((TokenStream)GetInputStream()).Consume();
((ITokenStream)GetInputStream()).Consume();
}
bool hasListener = _parseListeners != null && !_parseListeners.IsEmpty();
if (_buildParseTrees || hasListener)
{
if (_errHandler.InErrorRecoveryMode(this))
{
ErrorNode node = _ctx.AddErrorNode(o);
IErrorNode node = _ctx.AddErrorNode(o);
if (_parseListeners != null)
{
foreach (ParseTreeListener listener in _parseListeners)
foreach (IParseTreeListener listener in _parseListeners)
{
listener.VisitErrorNode(node);
}
@ -506,10 +505,10 @@ namespace Antlr4.Runtime
}
else
{
TerminalNode node = _ctx.AddChild(o);
ITerminalNode node = _ctx.AddChild(o);
if (_parseListeners != null)
{
foreach (ParseTreeListener listener in _parseListeners)
foreach (IParseTreeListener listener in _parseListeners)
{
listener.VisitTerminal(node);
}
@ -691,7 +690,7 @@ namespace Antlr4.Runtime
return precedence >= _precedenceStack.Peek();
}
public override ANTLRErrorListener<Token> GetErrorListenerDispatch()
public override IAntlrErrorListener<Token> GetErrorListenerDispatch()
{
return new ProxyParserErrorListener(GetErrorListeners());
}

View File

@ -35,7 +35,7 @@ using Sharpen;
namespace Antlr4.Runtime
{
/// <summary>How to emit recognition errors</summary>
public interface ParserErrorListener : ANTLRErrorListener<Token>
public interface ParserErrorListener : IAntlrErrorListener<Token>
{
/// <summary>
/// Called when the parser detects a true ambiguity: an input sequence can be matched

View File

@ -74,7 +74,7 @@ namespace Antlr4.Runtime
/// operation because we don't the need to track the details about
/// how we parse this rule.
/// </remarks>
public IList<ParseTree> children;
public IList<IParseTree> children;
/// <summary>
/// For debugging/tracing purposes, we want to track all of the nodes in
@ -159,20 +159,20 @@ namespace Antlr4.Runtime
}
// Double dispatch methods for listeners
public virtual void EnterRule(ParseTreeListener listener)
public virtual void EnterRule(IParseTreeListener listener)
{
}
public virtual void ExitRule(ParseTreeListener listener)
public virtual void ExitRule(IParseTreeListener listener)
{
}
/// <summary>Does not set parent link; other add methods do that</summary>
public virtual void AddChild(TerminalNode t)
public virtual void AddChild(ITerminalNode t)
{
if (children == null)
{
children = new AList<ParseTree>();
children = new AList<IParseTree>();
}
children.AddItem(t);
}
@ -181,7 +181,7 @@ namespace Antlr4.Runtime
{
if (children == null)
{
children = new AList<ParseTree>();
children = new AList<IParseTree>();
}
children.AddItem(ruleInvocation);
}
@ -207,7 +207,7 @@ namespace Antlr4.Runtime
// if ( states==null ) states = new ArrayList<Integer>();
// states.add(s);
// }
public virtual TerminalNode AddChild(Token matchedToken)
public virtual ITerminalNode AddChild(Token matchedToken)
{
TerminalNodeImpl t = new TerminalNodeImpl(matchedToken);
AddChild(t);
@ -215,7 +215,7 @@ namespace Antlr4.Runtime
return t;
}
public virtual ErrorNode AddErrorNode(Token badToken)
public virtual IErrorNode AddErrorNode(Token badToken)
{
ErrorNodeImpl t = new ErrorNodeImpl(badToken);
AddChild(t);
@ -228,12 +228,12 @@ namespace Antlr4.Runtime
return (Antlr4.Runtime.ParserRuleContext)base.GetParent();
}
public override ParseTree GetChild(int i)
public override IParseTree GetChild(int i)
{
return children != null && i >= 0 && i < children.Count ? children[i] : null;
}
public virtual T GetChild<T, _T1>(Type<_T1> ctxType, int i) where T:ParseTree where
public virtual T GetChild<T, _T1>(Type<_T1> ctxType, int i) where T:IParseTree where
_T1:T
{
if (children == null || i < 0 || i >= children.Count)
@ -242,7 +242,7 @@ namespace Antlr4.Runtime
}
int j = -1;
// what element have we found with ctxType?
foreach (ParseTree o in children)
foreach (IParseTree o in children)
{
if (ctxType.IsInstanceOfType(o))
{
@ -256,7 +256,7 @@ namespace Antlr4.Runtime
return null;
}
public virtual TerminalNode GetToken(int ttype, int i)
public virtual ITerminalNode GetToken(int ttype, int i)
{
if (children == null || i < 0 || i >= children.Count)
{
@ -264,11 +264,11 @@ namespace Antlr4.Runtime
}
int j = -1;
// what token with ttype have we found?
foreach (ParseTree o in children)
foreach (IParseTree o in children)
{
if (o is TerminalNode)
if (o is ITerminalNode)
{
TerminalNode tnode = (TerminalNode)o;
ITerminalNode tnode = (ITerminalNode)o;
Token symbol = tnode.GetSymbol();
if (symbol.GetType() == ttype)
{
@ -283,24 +283,24 @@ namespace Antlr4.Runtime
return null;
}
public virtual IList<TerminalNode> GetTokens(int ttype)
public virtual IList<ITerminalNode> GetTokens(int ttype)
{
if (children == null)
{
return Sharpen.Collections.EmptyList();
}
IList<TerminalNode> tokens = null;
foreach (ParseTree o in children)
IList<ITerminalNode> tokens = null;
foreach (IParseTree o in children)
{
if (o is TerminalNode)
if (o is ITerminalNode)
{
TerminalNode tnode = (TerminalNode)o;
ITerminalNode tnode = (ITerminalNode)o;
Token symbol = tnode.GetSymbol();
if (symbol.GetType() == ttype)
{
if (tokens == null)
{
tokens = new AList<TerminalNode>();
tokens = new AList<ITerminalNode>();
}
tokens.AddItem(tnode);
}
@ -327,7 +327,7 @@ namespace Antlr4.Runtime
return Sharpen.Collections.EmptyList();
}
IList<T> contexts = null;
foreach (ParseTree o in children)
foreach (IParseTree o in children)
{
if (ctxType.IsInstanceOfType(o))
{

View File

@ -34,16 +34,17 @@ using Sharpen;
namespace Antlr4.Runtime
{
/// <author>Sam Harwell</author>
public class ProxyErrorListener<Symbol> : ANTLRErrorListener<Symbol>
public class ProxyErrorListener<Symbol> : IAntlrErrorListener<Symbol>
{
private readonly ICollection<ANTLRErrorListener<Symbol>> delegates;
private readonly ICollection<IAntlrErrorListener<Symbol>> delegates;
public ProxyErrorListener(ICollection<ANTLRErrorListener<Symbol>> delegates)
public ProxyErrorListener(ICollection<IAntlrErrorListener<Symbol>> delegates)
{
this.delegates = delegates;
}
protected internal virtual ICollection<ANTLRErrorListener<Symbol>> GetDelegates()
protected internal virtual ICollection<IAntlrErrorListener<Symbol>> GetDelegates(
)
{
return delegates;
}
@ -52,7 +53,7 @@ namespace Antlr4.Runtime
, int line, int charPositionInLine, string msg, RecognitionException e) where T:
Symbol
{
foreach (ANTLRErrorListener<Symbol> listener in delegates)
foreach (IAntlrErrorListener<Symbol> listener in delegates)
{
listener.SyntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg,
e);

View File

@ -36,23 +36,23 @@ using Sharpen;
namespace Antlr4.Runtime
{
/// <author>Sam Harwell</author>
public class ProxyParserErrorListener : ProxyErrorListener<Token>, ParserErrorListener
public class ProxyParserErrorListener : ProxyErrorListener<Token>, IParserErrorListener
{
public ProxyParserErrorListener(ICollection<ANTLRErrorListener<Token>> delegates)
: base(delegates)
public ProxyParserErrorListener(ICollection<IAntlrErrorListener<Token>> delegates
) : base(delegates)
{
}
public virtual void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int
stopIndex, BitSet ambigAlts, ATNConfigSet configs)
{
foreach (ANTLRErrorListener<Token> listener in GetDelegates())
foreach (IAntlrErrorListener<Token> listener in GetDelegates())
{
if (!(listener is ParserErrorListener))
if (!(listener is IParserErrorListener))
{
continue;
}
ParserErrorListener parserErrorListener = (ParserErrorListener)listener;
IParserErrorListener parserErrorListener = (IParserErrorListener)listener;
parserErrorListener.ReportAmbiguity(recognizer, dfa, startIndex, stopIndex, ambigAlts
, configs);
}
@ -61,13 +61,13 @@ namespace Antlr4.Runtime
public virtual void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex
, int stopIndex, SimulatorState initialState)
{
foreach (ANTLRErrorListener<Token> listener in GetDelegates())
foreach (IAntlrErrorListener<Token> listener in GetDelegates())
{
if (!(listener is ParserErrorListener))
if (!(listener is IParserErrorListener))
{
continue;
}
ParserErrorListener parserErrorListener = (ParserErrorListener)listener;
IParserErrorListener parserErrorListener = (IParserErrorListener)listener;
parserErrorListener.ReportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex
, initialState);
}
@ -76,13 +76,13 @@ namespace Antlr4.Runtime
public virtual void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex
, int stopIndex, SimulatorState acceptState)
{
foreach (ANTLRErrorListener<Token> listener in GetDelegates())
foreach (IAntlrErrorListener<Token> listener in GetDelegates())
{
if (!(listener is ParserErrorListener))
if (!(listener is IParserErrorListener))
{
continue;
}
ParserErrorListener parserErrorListener = (ParserErrorListener)listener;
IParserErrorListener parserErrorListener = (IParserErrorListener)listener;
parserErrorListener.ReportContextSensitivity(recognizer, dfa, startIndex, stopIndex
, acceptState);
}

View File

@ -39,7 +39,7 @@ namespace Antlr4.Runtime
{
public const int Eof = -1;
private sealed class _CopyOnWriteArrayList_49 : CopyOnWriteArrayList<ANTLRErrorListener
private sealed class _CopyOnWriteArrayList_49 : CopyOnWriteArrayList<IAntlrErrorListener
<Symbol>>
{
public _CopyOnWriteArrayList_49()
@ -51,7 +51,7 @@ namespace Antlr4.Runtime
}
[NotNull]
private IList<ANTLRErrorListener<Symbol>> _listeners = new _CopyOnWriteArrayList_49
private IList<IAntlrErrorListener<Symbol>> _listeners = new _CopyOnWriteArrayList_49
();
protected internal ATNInterpreter _interp;
@ -146,13 +146,13 @@ namespace Antlr4.Runtime
/// <code>null</code>
/// .
/// </exception>
public virtual void AddErrorListener<_T0>(ANTLRErrorListener<_T0> listener)
public virtual void AddErrorListener<_T0>(IAntlrErrorListener<_T0> listener)
{
Args.NotNull("listener", listener);
_listeners.AddItem(listener);
}
public virtual void RemoveErrorListener<_T0>(ANTLRErrorListener<_T0> listener)
public virtual void RemoveErrorListener<_T0>(IAntlrErrorListener<_T0> listener)
{
_listeners.Remove(listener);
}
@ -163,12 +163,12 @@ namespace Antlr4.Runtime
}
[NotNull]
public virtual IList<ANTLRErrorListener<Symbol>> GetErrorListeners()
public virtual IList<IAntlrErrorListener<Symbol>> GetErrorListeners()
{
return new AList<ANTLRErrorListener<Symbol>>(_listeners);
return new AList<IAntlrErrorListener<Symbol>>(_listeners);
}
public virtual ANTLRErrorListener<Symbol> GetErrorListenerDispatch()
public virtual IAntlrErrorListener<Symbol> GetErrorListenerDispatch()
{
return new ProxyErrorListener<Symbol>(GetErrorListeners());
}

View File

@ -57,7 +57,7 @@ namespace Antlr4.Runtime
/// ParserRuleContext.
/// </remarks>
/// <seealso cref="ParserRuleContext">ParserRuleContext</seealso>
public class RuleContext : RuleNode
public class RuleContext : IRuleNode
{
/// <summary>What context invoked this rule?</summary>
public Antlr4.Runtime.RuleContext parent;
@ -165,7 +165,7 @@ namespace Antlr4.Runtime
return -1;
}
public virtual ParseTree GetChild(int i)
public virtual IParseTree GetChild(int i)
{
return null;
}
@ -175,7 +175,7 @@ namespace Antlr4.Runtime
return 0;
}
public virtual T Accept<T, _T1>(ParseTreeVisitor<_T1> visitor) where _T1:T
public virtual T Accept<T, _T1>(IParseTreeVisitor<_T1> visitor) where _T1:T
{
return visitor.VisitChildren(this);
}

View File

@ -136,10 +136,10 @@ namespace Antlr4.Runtime
/// <summary>
/// Gets the
/// <see cref="TokenSource">TokenSource</see>
/// <see cref="ITokenSource">ITokenSource</see>
/// which created this token.
/// </summary>
public abstract TokenSource GetTokenSource();
public abstract ITokenSource GetTokenSource();
/// <summary>
/// Gets the

View File

@ -51,7 +51,7 @@ namespace Antlr4.Runtime
/// are wiped to -1 in the text override is set in the CommonToken.
/// </remarks>
Token Create<_T0>(Tuple<_T0> source, int type, string text, int channel, int start
, int stop, int line, int charPositionInLine) where _T0:TokenSource;
, int stop, int line, int charPositionInLine) where _T0:ITokenSource;
/// <summary>Generically useful</summary>
Token Create(int type, string text);

View File

@ -88,9 +88,9 @@ namespace Antlr4.Runtime
/// <summary>Gets the factory used for constructing tokens.</summary>
/// <remarks>Gets the factory used for constructing tokens.</remarks>
TokenFactory GetTokenFactory();
ITokenFactory GetTokenFactory();
/// <summary>Optional method that lets users set factory in lexer or other source</summary>
void SetTokenFactory(TokenFactory factory);
void SetTokenFactory(ITokenFactory factory);
}
}

View File

@ -100,12 +100,12 @@ namespace Antlr4.Runtime
/// <summary>
/// Gets the underlying
/// <see cref="TokenSource">TokenSource</see>
/// <see cref="ITokenSource">ITokenSource</see>
/// which provides tokens for this
/// stream.
/// </summary>
[NotNull]
TokenSource GetTokenSource();
ITokenSource GetTokenSource();
/// <summary>
/// Return the text of all tokens within the specified

View File

@ -102,7 +102,7 @@ namespace Antlr4.Runtime
public class RewriteOperation
{
protected internal readonly TokenStream tokens;
protected internal readonly ITokenStream tokens;
/// <summary>What index into rewrites List are we?</summary>
protected internal int instructionIndex;
@ -113,14 +113,14 @@ namespace Antlr4.Runtime
protected internal object text;
protected internal RewriteOperation(TokenStream tokens, int index)
protected internal RewriteOperation(ITokenStream tokens, int index)
{
// Define the rewrite operation hierarchy
this.tokens = tokens;
this.index = index;
}
protected internal RewriteOperation(TokenStream tokens, int index, object text)
protected internal RewriteOperation(ITokenStream tokens, int index, object text)
{
this.tokens = tokens;
this.index = index;
@ -148,8 +148,8 @@ namespace Antlr4.Runtime
internal class InsertBeforeOp : TokenStreamRewriter.RewriteOperation
{
protected internal InsertBeforeOp(TokenStream tokens, int index, object text) : base
(tokens, index, text)
protected internal InsertBeforeOp(ITokenStream tokens, int index, object text) :
base(tokens, index, text)
{
}
@ -176,7 +176,7 @@ namespace Antlr4.Runtime
{
protected internal int lastIndex;
public ReplaceOp(TokenStream tokens, int from, int to, object text) : base(tokens
public ReplaceOp(ITokenStream tokens, int from, int to, object text) : base(tokens
, from, text)
{
lastIndex = to;
@ -203,7 +203,7 @@ namespace Antlr4.Runtime
}
/// <summary>Our source stream</summary>
protected internal readonly TokenStream tokens;
protected internal readonly ITokenStream tokens;
/// <summary>You may have multiple, named streams of rewrite operations.</summary>
/// <remarks>
@ -217,7 +217,7 @@ namespace Antlr4.Runtime
/// <summary>Map String (program name) -&gt; Integer index</summary>
protected internal readonly IDictionary<string, int> lastRewriteTokenIndexes;
public TokenStreamRewriter(TokenStream tokens)
public TokenStreamRewriter(ITokenStream tokens)
{
this.tokens = tokens;
programs = new Dictionary<string, IList<TokenStreamRewriter.RewriteOperation>>();
@ -226,7 +226,7 @@ namespace Antlr4.Runtime
lastRewriteTokenIndexes = new Dictionary<string, int>();
}
public TokenStream GetTokenStream()
public ITokenStream GetTokenStream()
{
return tokens;
}

View File

@ -32,18 +32,19 @@ using Sharpen;
namespace Antlr4.Runtime.Tree
{
public abstract class AbstractParseTreeVisitor<Result> : ParseTreeVisitor<Result>
public abstract class AbstractParseTreeVisitor<Result> : IParseTreeVisitor<Result
>
{
/// <summary>
/// <inheritDoc></inheritDoc>
/// <p/>
/// The default implementation calls
/// <see cref="ParseTree.Accept{T}(ParseTreeVisitor{Result})">ParseTree.Accept&lt;T&gt;(ParseTreeVisitor&lt;Result&gt;)
/// <see cref="IParseTree.Accept{T}(IParseTreeVisitor{Result})">IParseTree.Accept&lt;T&gt;(IParseTreeVisitor&lt;Result&gt;)
/// </see>
/// on the
/// specified tree.
/// </summary>
public virtual Result Visit(ParseTree tree)
public virtual Result Visit(IParseTree tree)
{
return tree.Accept(this);
}
@ -55,7 +56,7 @@ namespace Antlr4.Runtime.Tree
/// <see cref="AbstractParseTreeVisitor{Result}.DefaultResult()">defaultResult()</see>
/// . Before visiting each child, it
/// calls
/// <see cref="AbstractParseTreeVisitor{Result}.ShouldVisitNextChild(RuleNode, object)
/// <see cref="AbstractParseTreeVisitor{Result}.ShouldVisitNextChild(IRuleNode, object)
/// ">shouldVisitNextChild</see>
/// ; if the result
/// is
@ -68,7 +69,7 @@ namespace Antlr4.Runtime.Tree
/// with the
/// previous aggregate result and the result of visiting the child.
/// </summary>
public virtual Result VisitChildren(RuleNode node)
public virtual Result VisitChildren(IRuleNode node)
{
Result result = DefaultResult();
int n = node.GetChildCount();
@ -78,7 +79,7 @@ namespace Antlr4.Runtime.Tree
{
break;
}
ParseTree c = node.GetChild(i);
IParseTree c = node.GetChild(i);
Result childResult = c.Accept(this);
result = AggregateResult(result, childResult);
}
@ -92,7 +93,7 @@ namespace Antlr4.Runtime.Tree
/// <see cref="AbstractParseTreeVisitor{Result}.DefaultResult()">defaultResult</see>
/// .
/// </summary>
public virtual Result VisitTerminal(TerminalNode node)
public virtual Result VisitTerminal(ITerminalNode node)
{
return DefaultResult();
}
@ -104,7 +105,7 @@ namespace Antlr4.Runtime.Tree
/// <see cref="AbstractParseTreeVisitor{Result}.DefaultResult()">defaultResult</see>
/// .
/// </summary>
public virtual Result VisitErrorNode(ErrorNode node)
public virtual Result VisitErrorNode(IErrorNode node)
{
return DefaultResult();
}
@ -113,14 +114,14 @@ namespace Antlr4.Runtime.Tree
/// <remarks>
/// Gets the default value returned by visitor methods. This value is
/// returned by the default implementations of
/// <see cref="AbstractParseTreeVisitor{Result}.VisitTerminal(TerminalNode)">visitTerminal
/// <see cref="AbstractParseTreeVisitor{Result}.VisitTerminal(ITerminalNode)">visitTerminal
/// </see>
/// ,
/// <see cref="AbstractParseTreeVisitor{Result}.VisitErrorNode(ErrorNode)">visitErrorNode
/// <see cref="AbstractParseTreeVisitor{Result}.VisitErrorNode(IErrorNode)">visitErrorNode
/// </see>
/// .
/// The default implementation of
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(RuleNode)">visitChildren
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)">visitChildren
/// </see>
/// initializes its aggregate result to this value.
/// <p/>
@ -138,19 +139,20 @@ namespace Antlr4.Runtime.Tree
/// <remarks>
/// Aggregates the results of visiting multiple children of a node. After
/// either all children are visited or
/// <see cref="AbstractParseTreeVisitor{Result}.ShouldVisitNextChild(RuleNode, object)
/// ">AbstractParseTreeVisitor&lt;Result&gt;.ShouldVisitNextChild(RuleNode, object)</see>
/// <see cref="AbstractParseTreeVisitor{Result}.ShouldVisitNextChild(IRuleNode, object)
/// ">AbstractParseTreeVisitor&lt;Result&gt;.ShouldVisitNextChild(IRuleNode, object)
/// </see>
/// returns
/// <code>false</code>
/// , the aggregate value is returned as the result of
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(RuleNode)">AbstractParseTreeVisitor&lt;Result&gt;.VisitChildren(RuleNode)
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)">AbstractParseTreeVisitor&lt;Result&gt;.VisitChildren(IRuleNode)
/// </see>
/// .
/// <p/>
/// The default implementation returns
/// <code>nextResult</code>
/// , meaning
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(RuleNode)">AbstractParseTreeVisitor&lt;Result&gt;.VisitChildren(RuleNode)
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)">AbstractParseTreeVisitor&lt;Result&gt;.VisitChildren(IRuleNode)
/// </see>
/// will return the result of the last child visited
/// (or return the initial value if the node has no children).
@ -178,7 +180,7 @@ namespace Antlr4.Runtime.Tree
/// <summary>
/// This method is called after visiting each child in
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(RuleNode)">AbstractParseTreeVisitor&lt;Result&gt;.VisitChildren(RuleNode)
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)">AbstractParseTreeVisitor&lt;Result&gt;.VisitChildren(IRuleNode)
/// </see>
/// . This method is first called before the first
/// child is visited; at that point
@ -203,7 +205,7 @@ namespace Antlr4.Runtime.Tree
/// </summary>
/// <param name="node">
/// The
/// <see cref="RuleNode">RuleNode</see>
/// <see cref="IRuleNode">IRuleNode</see>
/// whose children are currently being
/// visited.
/// </param>
@ -218,11 +220,11 @@ namespace Antlr4.Runtime.Tree
/// <code>false</code>
/// to stop visiting children and immediately return the
/// current aggregate result from
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(RuleNode)">AbstractParseTreeVisitor&lt;Result&gt;.VisitChildren(RuleNode)
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)">AbstractParseTreeVisitor&lt;Result&gt;.VisitChildren(IRuleNode)
/// </see>
/// .
/// </returns>
protected internal virtual bool ShouldVisitNextChild(RuleNode node, Result currentResult
protected internal virtual bool ShouldVisitNextChild(IRuleNode node, Result currentResult
)
{
return true;

View File

@ -27,12 +27,11 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using Antlr4.Runtime.Tree;
using Sharpen;
namespace Antlr4.Runtime.Tree
{
public interface ErrorNode : TerminalNode
public interface ErrorNode : ITerminalNode
{
}
}

View File

@ -44,13 +44,13 @@ namespace Antlr4.Runtime.Tree
/// and deletion as well as during "consume until error recovery set"
/// upon no viable alternative exceptions.
/// </remarks>
public class ErrorNodeImpl : TerminalNodeImpl, ErrorNode
public class ErrorNodeImpl : TerminalNodeImpl, IErrorNode
{
public ErrorNodeImpl(Token token) : base(token)
{
}
public override T Accept<T, _T1>(ParseTreeVisitor<_T1> visitor)
public override T Accept<T, _T1>(IParseTreeVisitor<_T1> visitor)
{
return visitor.VisitErrorNode(this);
}

View File

@ -28,7 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using Sharpen;
namespace Antlr4.Runtime.Tree
@ -47,19 +46,19 @@ namespace Antlr4.Runtime.Tree
/// <see cref="Antlr4.Runtime.RuleContext">Antlr4.Runtime.RuleContext</see>
/// object.
/// </summary>
public interface ParseTree : SyntaxTree
public interface ParseTree : ISyntaxTree
{
// the following methods narrow the return type; they are not additional methods
ParseTree GetParent();
IParseTree GetParent();
ParseTree GetChild(int i);
IParseTree GetChild(int i);
/// <summary>
/// The
/// <see cref="ParseTreeVisitor{Result}">ParseTreeVisitor&lt;Result&gt;</see>
/// needs a double dispatch method.
/// </summary>
T Accept<T, _T1>(ParseTreeVisitor<_T1> visitor) where _T1:T;
T Accept<T, _T1>(IParseTreeVisitor<_T1> visitor) where _T1:T;
/// <summary>Return the combined text of all leaf nodes.</summary>
/// <remarks>

View File

@ -28,16 +28,15 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using Sharpen;
namespace Antlr4.Runtime.Tree
{
public interface ParseTreeListener
{
void VisitTerminal(TerminalNode node);
void VisitTerminal(ITerminalNode node);
void VisitErrorNode(ErrorNode node);
void VisitErrorNode(IErrorNode node);
void EnterEveryRule(ParserRuleContext ctx);

View File

@ -50,20 +50,20 @@ namespace Antlr4.Runtime.Tree
/// </remarks>
public class ParseTreeProperty<V>
{
protected internal IDictionary<ParseTree, V> annotations = new IdentityHashMap<ParseTree
protected internal IDictionary<IParseTree, V> annotations = new IdentityHashMap<IParseTree
, V>();
public virtual V Get(ParseTree node)
public virtual V Get(IParseTree node)
{
return annotations.Get(node);
}
public virtual void Put(ParseTree node, V value)
public virtual void Put(IParseTree node, V value)
{
annotations.Put(node, value);
}
public virtual V RemoveFrom(ParseTree node)
public virtual V RemoveFrom(IParseTree node)
{
return Sharpen.Collections.Remove(annotations, node);
}

View File

@ -27,7 +27,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using Antlr4.Runtime.Tree;
using Sharpen;
namespace Antlr4.Runtime.Tree
@ -50,11 +49,11 @@ namespace Antlr4.Runtime.Tree
/// <remarks>Visit a parse tree, and return a user-defined result of the operation.</remarks>
/// <param name="tree">
/// The
/// <see cref="ParseTree">ParseTree</see>
/// <see cref="IParseTree">IParseTree</see>
/// to visit.
/// </param>
/// <returns>The result of visiting the parse tree.</returns>
Result Visit(ParseTree tree);
Result Visit(IParseTree tree);
/// <summary>
/// Visit the children of a node, and return a user-defined result
@ -66,11 +65,11 @@ namespace Antlr4.Runtime.Tree
/// </remarks>
/// <param name="node">
/// The
/// <see cref="RuleNode">RuleNode</see>
/// <see cref="IRuleNode">IRuleNode</see>
/// whose children should be visited.
/// </param>
/// <returns>The result of visiting the children of the node.</returns>
Result VisitChildren(RuleNode node);
Result VisitChildren(IRuleNode node);
/// <summary>Visit a terminal node, and return a user-defined result of the operation.
/// </summary>
@ -78,20 +77,20 @@ namespace Antlr4.Runtime.Tree
/// </remarks>
/// <param name="node">
/// The
/// <see cref="TerminalNode">TerminalNode</see>
/// <see cref="ITerminalNode">ITerminalNode</see>
/// to visit.
/// </param>
/// <returns>The result of visiting the node.</returns>
Result VisitTerminal(TerminalNode node);
Result VisitTerminal(ITerminalNode node);
/// <summary>Visit an error node, and return a user-defined result of the operation.</summary>
/// <remarks>Visit an error node, and return a user-defined result of the operation.</remarks>
/// <param name="node">
/// The
/// <see cref="ErrorNode">ErrorNode</see>
/// <see cref="IErrorNode">IErrorNode</see>
/// to visit.
/// </param>
/// <returns>The result of visiting the node.</returns>
Result VisitErrorNode(ErrorNode node);
Result VisitErrorNode(IErrorNode node);
}
}

View File

@ -37,22 +37,22 @@ namespace Antlr4.Runtime.Tree
{
public static readonly ParseTreeWalker Default = new ParseTreeWalker();
public virtual void Walk(ParseTreeListener listener, ParseTree t)
public virtual void Walk(IParseTreeListener listener, IParseTree t)
{
if (t is ErrorNode)
if (t is IErrorNode)
{
listener.VisitErrorNode((ErrorNode)t);
listener.VisitErrorNode((IErrorNode)t);
return;
}
else
{
if (t is TerminalNode)
if (t is ITerminalNode)
{
listener.VisitTerminal((TerminalNode)t);
listener.VisitTerminal((ITerminalNode)t);
return;
}
}
RuleNode r = (RuleNode)t;
IRuleNode r = (IRuleNode)t;
EnterRule(listener, r);
int n = r.GetChildCount();
for (int i = 0; i < n; i++)
@ -64,21 +64,23 @@ namespace Antlr4.Runtime.Tree
/// <summary>
/// The discovery of a rule node, involves sending two events: the generic
/// <see cref="ParseTreeListener.EnterEveryRule(Antlr4.Runtime.ParserRuleContext)">ParseTreeListener.EnterEveryRule(Antlr4.Runtime.ParserRuleContext)
/// <see cref="IParseTreeListener.EnterEveryRule(Antlr4.Runtime.ParserRuleContext)">IParseTreeListener.EnterEveryRule(Antlr4.Runtime.ParserRuleContext)
/// </see>
/// and a
/// <see cref="Antlr4.Runtime.RuleContext">Antlr4.Runtime.RuleContext</see>
/// -specific event. First we trigger the generic and then
/// the rule specific. We to them in reverse order upon finishing the node.
/// </summary>
protected internal virtual void EnterRule(ParseTreeListener listener, RuleNode r)
protected internal virtual void EnterRule(IParseTreeListener listener, IRuleNode
r)
{
ParserRuleContext ctx = (ParserRuleContext)r.GetRuleContext();
listener.EnterEveryRule(ctx);
ctx.EnterRule(listener);
}
protected internal virtual void ExitRule(ParseTreeListener listener, RuleNode r)
protected internal virtual void ExitRule(IParseTreeListener listener, IRuleNode r
)
{
ParserRuleContext ctx = (ParserRuleContext)r.GetRuleContext();
ctx.ExitRule(listener);

View File

@ -28,15 +28,14 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using Sharpen;
namespace Antlr4.Runtime.Tree
{
public interface RuleNode : ParseTree
public interface RuleNode : IParseTree
{
RuleContext GetRuleContext();
RuleNode GetParent();
IRuleNode GetParent();
}
}

View File

@ -28,7 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using Antlr4.Runtime.Misc;
using Antlr4.Runtime.Tree;
using Sharpen;
namespace Antlr4.Runtime.Tree
@ -42,13 +41,13 @@ namespace Antlr4.Runtime.Tree
/// is some kind of syntax tree. Subinterfaces distinguish
/// between parse trees and other kinds of syntax trees we might want to create.
/// </remarks>
public interface SyntaxTree : Antlr4.Runtime.Tree.Tree
public interface SyntaxTree : ITree
{
/// <summary>
/// Return an
/// <see cref="Antlr4.Runtime.Misc.Interval">Antlr4.Runtime.Misc.Interval</see>
/// indicating the index in the
/// <see cref="Antlr4.Runtime.TokenStream">Antlr4.Runtime.TokenStream</see>
/// <see cref="ITokenStream">ITokenStream</see>
/// of the first and last token associated with this
/// subtree. If this node is a leaf, then the interval represents a single
/// token.

View File

@ -28,15 +28,14 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using Sharpen;
namespace Antlr4.Runtime.Tree
{
public interface TerminalNode : ParseTree
public interface TerminalNode : IParseTree
{
Token GetSymbol();
RuleNode GetParent();
IRuleNode GetParent();
}
}

View File

@ -29,23 +29,22 @@
*/
using Antlr4.Runtime;
using Antlr4.Runtime.Misc;
using Antlr4.Runtime.Tree;
using Sharpen;
namespace Antlr4.Runtime.Tree
{
public class TerminalNodeImpl : TerminalNode
public class TerminalNodeImpl : ITerminalNode
{
public Token symbol;
public RuleNode parent;
public IRuleNode parent;
public TerminalNodeImpl(Token symbol)
{
this.symbol = symbol;
}
public virtual ParseTree GetChild(int i)
public virtual IParseTree GetChild(int i)
{
return null;
}
@ -55,7 +54,7 @@ namespace Antlr4.Runtime.Tree
return symbol;
}
public virtual RuleNode GetParent()
public virtual IRuleNode GetParent()
{
return parent;
}
@ -80,7 +79,7 @@ namespace Antlr4.Runtime.Tree
return 0;
}
public virtual T Accept<T, _T1>(ParseTreeVisitor<_T1> visitor) where _T1:T
public virtual T Accept<T, _T1>(IParseTreeVisitor<_T1> visitor) where _T1:T
{
return visitor.VisitTerminal(this);
}

View File

@ -44,7 +44,7 @@ namespace Antlr4.Runtime.Tree
/// The parent of this node. If the return value is null, then this
/// node is the root of the tree.
/// </remarks>
Antlr4.Runtime.Tree.Tree GetParent();
ITree GetParent();
/// <summary>This method returns whatever object represents the data at this note.</summary>
/// <remarks>
@ -66,7 +66,7 @@ namespace Antlr4.Runtime.Tree
/// <code>i</code>
/// th value indexed from 0.
/// </summary>
Antlr4.Runtime.Tree.Tree GetChild(int i);
ITree GetChild(int i);
/// <summary>
/// How many children are there? If there is none, then this

View File

@ -32,7 +32,6 @@ using System.IO;
using System.Text;
using Antlr4.Runtime;
using Antlr4.Runtime.Misc;
using Antlr4.Runtime.Tree;
using Antlr4.Runtime.Tree.Gui;
using Sharpen;
@ -42,22 +41,22 @@ namespace Antlr4.Runtime.Tree
/// <remarks>A set of utility routines useful for all kinds of ANTLR trees.</remarks>
public class Trees
{
public static string GetPS(Antlr4.Runtime.Tree.Tree t, IList<string> ruleNames, string
fontName, int fontSize)
public static string GetPS(ITree t, IList<string> ruleNames, string fontName, int
fontSize)
{
TreePostScriptGenerator psgen = new TreePostScriptGenerator(ruleNames, t, fontName
, fontSize);
return psgen.GetPS();
}
public static string GetPS(Antlr4.Runtime.Tree.Tree t, IList<string> ruleNames)
public static string GetPS(ITree t, IList<string> ruleNames)
{
return GetPS(t, ruleNames, "Helvetica", 11);
}
/// <exception cref="System.IO.IOException"></exception>
public static void WritePS(Antlr4.Runtime.Tree.Tree t, IList<string> ruleNames, string
fileName, string fontName, int fontSize)
public static void WritePS(ITree t, IList<string> ruleNames, string fileName, string
fontName, int fontSize)
{
string ps = GetPS(t, ruleNames, fontName, fontSize);
FileWriter f = new FileWriter(fileName);
@ -67,8 +66,7 @@ namespace Antlr4.Runtime.Tree
}
/// <exception cref="System.IO.IOException"></exception>
public static void WritePS(Antlr4.Runtime.Tree.Tree t, IList<string> ruleNames, string
fileName)
public static void WritePS(ITree t, IList<string> ruleNames, string fileName)
{
WritePS(t, ruleNames, fileName, "Helvetica", 11);
}
@ -76,13 +74,13 @@ namespace Antlr4.Runtime.Tree
/// <summary>Print out a whole tree in LISP form.</summary>
/// <remarks>
/// Print out a whole tree in LISP form.
/// <see cref="GetNodeText(Tree, Antlr4.Runtime.Parser)">GetNodeText(Tree, Antlr4.Runtime.Parser)
/// <see cref="GetNodeText(ITree, Antlr4.Runtime.Parser)">GetNodeText(ITree, Antlr4.Runtime.Parser)
/// </see>
/// is used on the
/// node payloads to get the text for the nodes. Detect
/// parse trees and extract data appropriately.
/// </remarks>
public static string ToStringTree(Antlr4.Runtime.Tree.Tree t)
public static string ToStringTree(ITree t)
{
return ToStringTree(t, (IList<string>)null);
}
@ -90,13 +88,13 @@ namespace Antlr4.Runtime.Tree
/// <summary>Print out a whole tree in LISP form.</summary>
/// <remarks>
/// Print out a whole tree in LISP form.
/// <see cref="GetNodeText(Tree, Antlr4.Runtime.Parser)">GetNodeText(Tree, Antlr4.Runtime.Parser)
/// <see cref="GetNodeText(ITree, Antlr4.Runtime.Parser)">GetNodeText(ITree, Antlr4.Runtime.Parser)
/// </see>
/// is used on the
/// node payloads to get the text for the nodes. Detect
/// parse trees and extract data appropriately.
/// </remarks>
public static string ToStringTree(Antlr4.Runtime.Tree.Tree t, Parser recog)
public static string ToStringTree(ITree t, Parser recog)
{
string[] ruleNames = recog != null ? recog.GetRuleNames() : null;
IList<string> ruleNamesList = ruleNames != null ? Arrays.AsList(ruleNames) : null;
@ -106,14 +104,13 @@ namespace Antlr4.Runtime.Tree
/// <summary>Print out a whole tree in LISP form.</summary>
/// <remarks>
/// Print out a whole tree in LISP form.
/// <see cref="GetNodeText(Tree, Antlr4.Runtime.Parser)">GetNodeText(Tree, Antlr4.Runtime.Parser)
/// <see cref="GetNodeText(ITree, Antlr4.Runtime.Parser)">GetNodeText(ITree, Antlr4.Runtime.Parser)
/// </see>
/// is used on the
/// node payloads to get the text for the nodes. Detect
/// parse trees and extract data appropriately.
/// </remarks>
public static string ToStringTree(Antlr4.Runtime.Tree.Tree t, IList<string> ruleNames
)
public static string ToStringTree(ITree t, IList<string> ruleNames)
{
string s = Utils.EscapeWhitespace(GetNodeText(t, ruleNames), false);
if (t.GetChildCount() == 0)
@ -137,35 +134,34 @@ namespace Antlr4.Runtime.Tree
return buf.ToString();
}
public static string GetNodeText(Antlr4.Runtime.Tree.Tree t, Parser recog)
public static string GetNodeText(ITree t, Parser recog)
{
string[] ruleNames = recog != null ? recog.GetRuleNames() : null;
IList<string> ruleNamesList = ruleNames != null ? Arrays.AsList(ruleNames) : null;
return GetNodeText(t, ruleNamesList);
}
public static string GetNodeText(Antlr4.Runtime.Tree.Tree t, IList<string> ruleNames
)
public static string GetNodeText(ITree t, IList<string> ruleNames)
{
if (ruleNames != null)
{
if (t is RuleNode)
if (t is IRuleNode)
{
int ruleIndex = ((RuleNode)t).GetRuleContext().GetRuleIndex();
int ruleIndex = ((IRuleNode)t).GetRuleContext().GetRuleIndex();
string ruleName = ruleNames[ruleIndex];
return ruleName;
}
else
{
if (t is ErrorNode)
if (t is IErrorNode)
{
return t.ToString();
}
else
{
if (t is TerminalNode)
if (t is ITerminalNode)
{
object symbol = ((TerminalNode)t).GetSymbol();
object symbol = ((ITerminalNode)t).GetSymbol();
if (symbol is Token)
{
string s = ((Token)symbol).GetText();
@ -190,14 +186,13 @@ namespace Antlr4.Runtime.Tree
/// list is the root and the last is the parent of this node.
/// </remarks>
[NotNull]
public static IList<Antlr4.Runtime.Tree.Tree> GetAncestors(Antlr4.Runtime.Tree.Tree
t)
public static IList<ITree> GetAncestors(ITree t)
{
if (t.GetParent() == null)
{
return Sharpen.Collections.EmptyList();
}
IList<Antlr4.Runtime.Tree.Tree> ancestors = new AList<Antlr4.Runtime.Tree.Tree>();
IList<ITree> ancestors = new AList<ITree>();
t = t.GetParent();
while (t != null)
{

View File

@ -35,9 +35,9 @@ using Sharpen;
namespace Antlr4.Runtime
{
public class UnbufferedTokenStream : TokenStream
public class UnbufferedTokenStream : ITokenStream
{
protected internal TokenSource tokenSource;
protected internal ITokenSource tokenSource;
/// <summary>A moving window buffer of the data being scanned.</summary>
/// <remarks>
@ -123,16 +123,16 @@ namespace Antlr4.Runtime
/// <p/>
/// This value is used to set the token indexes if the stream provides tokens
/// that implement
/// <see cref="WritableToken">WritableToken</see>
/// <see cref="IWritableToken">IWritableToken</see>
/// .
/// </remarks>
protected internal int currentTokenIndex = 0;
public UnbufferedTokenStream(TokenSource tokenSource) : this(tokenSource, 256)
public UnbufferedTokenStream(ITokenSource tokenSource) : this(tokenSource, 256)
{
}
public UnbufferedTokenStream(TokenSource tokenSource, int bufferSize)
public UnbufferedTokenStream(ITokenSource tokenSource, int bufferSize)
{
this.tokenSource = tokenSource;
Token[] tokens = new Token[bufferSize];
@ -178,7 +178,7 @@ namespace Antlr4.Runtime
return Lt(i).GetType();
}
public virtual TokenSource GetTokenSource()
public virtual ITokenSource GetTokenSource()
{
return tokenSource;
}
@ -285,9 +285,9 @@ namespace Antlr4.Runtime
{
tokens = Arrays.CopyOf(tokens, tokens.Length * 2);
}
if (t is WritableToken)
if (t is IWritableToken)
{
((WritableToken)t).SetTokenIndex(GetBufferStartIndex() + n);
((IWritableToken)t).SetTokenIndex(GetBufferStartIndex() + n);
}
tokens[n++] = t;
}

View File

@ -183,3 +183,23 @@
-typeMapping org.antlr.v4.runtime.misc.Tuple2<,> System.Tuple
-typeMapping org.antlr.v4.runtime.misc.Tuple3<,,> System.Tuple
-typeMapping org.antlr.v4.runtime.ANTLRErrorListener<> IAntlrErrorListener
-typeMapping org.antlr.v4.runtime.ANTLRErrorStrategy IAntlrErrorStrategy
-typeMapping org.antlr.v4.runtime.ParserErrorListener IParserErrorListener
-typeMapping org.antlr.v4.runtime.TokenFactory ITokenFactory
-typeMapping org.antlr.v4.runtime.TokenSource ITokenSource
-typeMapping org.antlr.v4.runtime.TokenStream ITokenStream
-typeMapping org.antlr.v4.runtime.WritableToken IWritableToken
-typeMapping org.antlr.v4.runtime.dfa.EdgeMap<> IEdgeMap
-typeMapping org.antlr.v4.runtime.misc.IntSet IIntSet
-typeMapping org.antlr.v4.runtime.tree.ErrorNode IErrorNode
-typeMapping org.antlr.v4.runtime.tree.ParseTree IParseTree
-typeMapping org.antlr.v4.runtime.tree.ParseTreeListener IParseTreeListener
-typeMapping org.antlr.v4.runtime.tree.ParseTreeVisitor<> IParseTreeVisitor
-typeMapping org.antlr.v4.runtime.tree.RuleNode IRuleNode
-typeMapping org.antlr.v4.runtime.tree.SyntaxTree ISyntaxTree
-typeMapping org.antlr.v4.runtime.tree.TerminalNode ITerminalNode
-typeMapping org.antlr.v4.runtime.tree.Tree ITree