forked from jasder/antlr
Updated type mappings for interfaces
This commit is contained in:
parent
457d6e0aa4
commit
fdec53d82d
|
@ -232,8 +232,7 @@ namespace Antlr4.Runtime.Atn
|
||||||
/// <code>true</code>
|
/// <code>true</code>
|
||||||
/// , ambiguous alternatives are reported when they are
|
/// , ambiguous alternatives are reported when they are
|
||||||
/// encountered within
|
/// encountered within
|
||||||
/// <see cref="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)
|
||||||
/// ">ExecATN(Antlr4.Runtime.Dfa.DFA, Antlr4.Runtime.TokenStream, int, SimulatorState)
|
|
||||||
/// </see>
|
/// </see>
|
||||||
/// . When
|
/// . When
|
||||||
/// <code>false</code>
|
/// <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)
|
outerContext)
|
||||||
{
|
{
|
||||||
return AdaptivePredict(input, decision, outerContext, false);
|
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)
|
outerContext, bool useContext)
|
||||||
{
|
{
|
||||||
DFA dfa = atn.decisionToDFA[decision];
|
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)
|
outerContext, bool useContext)
|
||||||
{
|
{
|
||||||
if (!useContext)
|
if (!useContext)
|
||||||
|
@ -391,7 +390,7 @@ namespace Antlr4.Runtime.Atn
|
||||||
return new SimulatorState(outerContext, s0, useContext, remainingContext);
|
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)
|
, bool useContext)
|
||||||
{
|
{
|
||||||
if (outerContext == null)
|
if (outerContext == null)
|
||||||
|
@ -425,7 +424,7 @@ namespace Antlr4.Runtime.Atn
|
||||||
return alt;
|
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)
|
state)
|
||||||
{
|
{
|
||||||
ParserRuleContext outerContext = state.outerContext;
|
ParserRuleContext outerContext = state.outerContext;
|
||||||
|
@ -648,7 +647,7 @@ namespace Antlr4.Runtime.Atn
|
||||||
/// conflict + preds
|
/// conflict + preds
|
||||||
/// TODO: greedy + those
|
/// TODO: greedy + those
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual int ExecATN(DFA dfa, TokenStream input, int startIndex, SimulatorState
|
public virtual int ExecATN(DFA dfa, ITokenStream input, int startIndex, SimulatorState
|
||||||
initialState)
|
initialState)
|
||||||
{
|
{
|
||||||
ParserRuleContext outerContext = initialState.outerContext;
|
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)
|
, SimulatorState previous)
|
||||||
{
|
{
|
||||||
if (previous.s0 != null)
|
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(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());
|
())).GetTokens());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1846,7 +1845,7 @@ namespace Antlr4.Runtime.Atn
|
||||||
return t.ToString();
|
return t.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual string GetLookaheadName(TokenStream input)
|
public virtual string GetLookaheadName(ITokenStream input)
|
||||||
{
|
{
|
||||||
return GetTokenName(input.La(1));
|
return GetTokenName(input.La(1));
|
||||||
}
|
}
|
||||||
|
@ -1880,7 +1879,7 @@ namespace Antlr4.Runtime.Atn
|
||||||
}
|
}
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public virtual NoViableAltException NoViableAlt(TokenStream input, ParserRuleContext
|
public virtual NoViableAltException NoViableAlt(ITokenStream input, ParserRuleContext
|
||||||
outerContext, ATNConfigSet configs, int startIndex)
|
outerContext, ATNConfigSet configs, int startIndex)
|
||||||
{
|
{
|
||||||
return new NoViableAltException(parser, input, input.Get(startIndex), input.Lt(1)
|
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);
|
Interval interval = Interval.Of(startIndex, stopIndex);
|
||||||
System.Console.Out.WriteLine("reportAttemptingFullContext decision=" + dfa.decision
|
System.Console.Out.WriteLine("reportAttemptingFullContext decision=" + dfa.decision
|
||||||
+ ":" + initialState.s0.configs + ", input=" + ((TokenStream)parser.GetInputStream
|
+ ":" + initialState.s0.configs + ", input=" + ((ITokenStream)parser.GetInputStream
|
||||||
()).GetText(interval));
|
()).GetText(interval));
|
||||||
}
|
}
|
||||||
if (parser != null)
|
if (parser != null)
|
||||||
{
|
{
|
||||||
((ParserErrorListener)parser.GetErrorListenerDispatch()).ReportAttemptingFullContext
|
((IParserErrorListener)parser.GetErrorListenerDispatch()).ReportAttemptingFullContext
|
||||||
(parser, dfa, startIndex, stopIndex, initialState);
|
(parser, dfa, startIndex, stopIndex, initialState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2102,12 +2101,12 @@ namespace Antlr4.Runtime.Atn
|
||||||
{
|
{
|
||||||
Interval interval = Interval.Of(startIndex, stopIndex);
|
Interval interval = Interval.Of(startIndex, stopIndex);
|
||||||
System.Console.Out.WriteLine("reportContextSensitivity decision=" + dfa.decision
|
System.Console.Out.WriteLine("reportContextSensitivity decision=" + dfa.decision
|
||||||
+ ":" + acceptState.s0.configs + ", input=" + ((TokenStream)parser.GetInputStream
|
+ ":" + acceptState.s0.configs + ", input=" + ((ITokenStream)parser.GetInputStream
|
||||||
()).GetText(interval));
|
()).GetText(interval));
|
||||||
}
|
}
|
||||||
if (parser != null)
|
if (parser != null)
|
||||||
{
|
{
|
||||||
((ParserErrorListener)parser.GetErrorListenerDispatch()).ReportContextSensitivity
|
((IParserErrorListener)parser.GetErrorListenerDispatch()).ReportContextSensitivity
|
||||||
(parser, dfa, startIndex, stopIndex, acceptState);
|
(parser, dfa, startIndex, stopIndex, acceptState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2136,11 +2135,11 @@ namespace Antlr4.Runtime.Atn
|
||||||
// }
|
// }
|
||||||
Interval interval = Interval.Of(startIndex, stopIndex);
|
Interval interval = Interval.Of(startIndex, stopIndex);
|
||||||
System.Console.Out.WriteLine("reportAmbiguity " + ambigAlts + ":" + configs + ", input="
|
System.Console.Out.WriteLine("reportAmbiguity " + ambigAlts + ":" + configs + ", input="
|
||||||
+ ((TokenStream)parser.GetInputStream()).GetText(interval));
|
+ ((ITokenStream)parser.GetInputStream()).GetText(interval));
|
||||||
}
|
}
|
||||||
if (parser != null)
|
if (parser != null)
|
||||||
{
|
{
|
||||||
((ParserErrorListener)parser.GetErrorListenerDispatch()).ReportAmbiguity(parser,
|
((IParserErrorListener)parser.GetErrorListenerDispatch()).ReportAmbiguity(parser,
|
||||||
dfa, startIndex, stopIndex, ambigAlts, configs);
|
dfa, startIndex, stopIndex, ambigAlts, configs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ using Sharpen;
|
||||||
namespace Antlr4.Runtime
|
namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
/// <author>Sam Harwell</author>
|
/// <author>Sam Harwell</author>
|
||||||
public class BaseErrorListener : ParserErrorListener
|
public class BaseErrorListener : IParserErrorListener
|
||||||
{
|
{
|
||||||
public virtual void SyntaxError<T>(Recognizer<T, object> recognizer, T offendingSymbol
|
public virtual void SyntaxError<T>(Recognizer<T, object> recognizer, T offendingSymbol
|
||||||
, int line, int charPositionInLine, string msg, RecognitionException e) where T:
|
, int line, int charPositionInLine, string msg, RecognitionException e) where T:
|
||||||
|
|
|
@ -64,10 +64,10 @@ namespace Antlr4.Runtime
|
||||||
/// because I don't want
|
/// because I don't want
|
||||||
/// to confuse small moving window of tokens it uses for the full buffer.
|
/// to confuse small moving window of tokens it uses for the full buffer.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class BufferedTokenStream : TokenStream
|
public class BufferedTokenStream : ITokenStream
|
||||||
{
|
{
|
||||||
[NotNull]
|
[NotNull]
|
||||||
protected internal TokenSource tokenSource;
|
protected internal ITokenSource tokenSource;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Record every single token pulled from the source so we can reproduce
|
/// 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>
|
/// <seealso cref="Fetch(int)">Fetch(int)</seealso>
|
||||||
protected internal bool fetchedEOF;
|
protected internal bool fetchedEOF;
|
||||||
|
|
||||||
public BufferedTokenStream(TokenSource tokenSource)
|
public BufferedTokenStream(ITokenSource tokenSource)
|
||||||
{
|
{
|
||||||
if (tokenSource == null)
|
if (tokenSource == null)
|
||||||
{
|
{
|
||||||
|
@ -122,7 +122,7 @@ namespace Antlr4.Runtime
|
||||||
this.tokenSource = tokenSource;
|
this.tokenSource = tokenSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual TokenSource GetTokenSource()
|
public virtual ITokenSource GetTokenSource()
|
||||||
{
|
{
|
||||||
return tokenSource;
|
return tokenSource;
|
||||||
}
|
}
|
||||||
|
@ -215,9 +215,9 @@ namespace Antlr4.Runtime
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
Token t = tokenSource.NextToken();
|
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);
|
tokens.AddItem(t);
|
||||||
if (t.GetType() == Token.Eof)
|
if (t.GetType() == Token.Eof)
|
||||||
|
@ -344,7 +344,7 @@ namespace Antlr4.Runtime
|
||||||
|
|
||||||
/// <summary>Reset this token stream by setting its token source.</summary>
|
/// <summary>Reset this token stream by setting its token source.</summary>
|
||||||
/// <remarks>Reset this token stream by setting its token source.</remarks>
|
/// <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;
|
this.tokenSource = tokenSource;
|
||||||
tokens.Clear();
|
tokens.Clear();
|
||||||
|
|
|
@ -35,7 +35,7 @@ using Sharpen;
|
||||||
namespace Antlr4.Runtime
|
namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class CommonToken : WritableToken
|
public class CommonToken : IWritableToken
|
||||||
{
|
{
|
||||||
private const long serialVersionUID = -6708843461296520577L;
|
private const long serialVersionUID = -6708843461296520577L;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ namespace Antlr4.Runtime
|
||||||
|
|
||||||
protected internal int channel = DefaultChannel;
|
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>
|
/// <summary>We need to be able to change the text once in a while.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
@ -74,7 +74,7 @@ namespace Antlr4.Runtime
|
||||||
this.type = type;
|
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)
|
int start, int stop)
|
||||||
{
|
{
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
@ -220,7 +220,7 @@ namespace Antlr4.Runtime
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual TokenSource GetTokenSource()
|
public virtual ITokenSource GetTokenSource()
|
||||||
{
|
{
|
||||||
return source.GetItem1();
|
return source.GetItem1();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime
|
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>
|
/// <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,
|
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);
|
CommonToken t = new CommonToken(source, type, channel, start, stop);
|
||||||
t.SetLine(line);
|
t.SetLine(line);
|
||||||
|
|
|
@ -66,11 +66,11 @@ namespace Antlr4.Runtime
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected internal int channel = Token.DefaultChannel;
|
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;
|
this.channel = channel;
|
||||||
|
|
|
@ -33,7 +33,7 @@ using Sharpen;
|
||||||
namespace Antlr4.Runtime
|
namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
/// <author>Sam Harwell</author>
|
/// <author>Sam Harwell</author>
|
||||||
public class ConsoleErrorListener : ANTLRErrorListener<object>
|
public class ConsoleErrorListener : IAntlrErrorListener<object>
|
||||||
{
|
{
|
||||||
public static readonly ConsoleErrorListener Instance = new ConsoleErrorListener();
|
public static readonly ConsoleErrorListener Instance = new ConsoleErrorListener();
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace Antlr4.Runtime
|
||||||
/// This is the default error handling mechanism for ANTLR parsers
|
/// This is the default error handling mechanism for ANTLR parsers
|
||||||
/// and tree parsers.
|
/// and tree parsers.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class DefaultErrorStrategy : ANTLRErrorStrategy
|
public class DefaultErrorStrategy : IAntlrErrorStrategy
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is true after we see an error and before having successfully
|
/// This is true after we see an error and before having successfully
|
||||||
|
@ -145,7 +145,7 @@ namespace Antlr4.Runtime
|
||||||
// ", lastErrorIndex="+
|
// ", lastErrorIndex="+
|
||||||
// lastErrorIndex+
|
// lastErrorIndex+
|
||||||
// ", states="+lastErrorStates);
|
// ", states="+lastErrorStates);
|
||||||
if (lastErrorIndex == ((TokenStream)recognizer.GetInputStream()).Index() && lastErrorStates
|
if (lastErrorIndex == ((ITokenStream)recognizer.GetInputStream()).Index() && lastErrorStates
|
||||||
!= null && lastErrorStates.Contains(recognizer.GetState()))
|
!= null && lastErrorStates.Contains(recognizer.GetState()))
|
||||||
{
|
{
|
||||||
// uh oh, another error at same token index and previously-visited
|
// 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)]);
|
// System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]);
|
||||||
recognizer.Consume();
|
recognizer.Consume();
|
||||||
}
|
}
|
||||||
lastErrorIndex = ((TokenStream)recognizer.GetInputStream()).Index();
|
lastErrorIndex = ((ITokenStream)recognizer.GetInputStream()).Index();
|
||||||
if (lastErrorStates == null)
|
if (lastErrorStates == null)
|
||||||
{
|
{
|
||||||
lastErrorStates = new IntervalSet();
|
lastErrorStates = new IntervalSet();
|
||||||
|
@ -193,7 +193,7 @@ namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TokenStream tokens = ((TokenStream)recognizer.GetInputStream());
|
ITokenStream tokens = ((ITokenStream)recognizer.GetInputStream());
|
||||||
int la = tokens.La(1);
|
int la = tokens.La(1);
|
||||||
// try cheaper subset first; might get lucky. seems to shave a wee bit off
|
// try cheaper subset first; might get lucky. seems to shave a wee bit off
|
||||||
if (recognizer.GetATN().NextTokens(s).Contains(la) || la == Token.Eof)
|
if (recognizer.GetATN().NextTokens(s).Contains(la) || la == Token.Eof)
|
||||||
|
@ -245,7 +245,7 @@ namespace Antlr4.Runtime
|
||||||
public virtual void ReportNoViableAlternative(Parser recognizer, NoViableAltException
|
public virtual void ReportNoViableAlternative(Parser recognizer, NoViableAltException
|
||||||
e)
|
e)
|
||||||
{
|
{
|
||||||
TokenStream tokens = ((TokenStream)recognizer.GetInputStream());
|
ITokenStream tokens = ((ITokenStream)recognizer.GetInputStream());
|
||||||
string input;
|
string input;
|
||||||
if (tokens != null)
|
if (tokens != null)
|
||||||
{
|
{
|
||||||
|
@ -363,7 +363,7 @@ namespace Antlr4.Runtime
|
||||||
// if next token is what we are looking for then "delete" this token
|
// if next token is what we are looking for then "delete" this token
|
||||||
public virtual bool SingleTokenInsertion(Parser recognizer)
|
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
|
// if current token is consistent with what could come after current
|
||||||
// ATN state, then we know we're missing a token; error recovery
|
// ATN state, then we know we're missing a token; error recovery
|
||||||
// is free to conjure up and insert the missing token
|
// is free to conjure up and insert the missing token
|
||||||
|
@ -384,7 +384,7 @@ namespace Antlr4.Runtime
|
||||||
|
|
||||||
public virtual Token SingleTokenDeletion(Parser recognizer)
|
public virtual Token SingleTokenDeletion(Parser recognizer)
|
||||||
{
|
{
|
||||||
int nextTokenType = ((TokenStream)recognizer.GetInputStream()).La(2);
|
int nextTokenType = ((ITokenStream)recognizer.GetInputStream()).La(2);
|
||||||
IntervalSet expecting = GetExpectedTokens(recognizer);
|
IntervalSet expecting = GetExpectedTokens(recognizer);
|
||||||
if (expecting.Contains(nextTokenType))
|
if (expecting.Contains(nextTokenType))
|
||||||
{
|
{
|
||||||
|
@ -436,19 +436,19 @@ namespace Antlr4.Runtime
|
||||||
tokenText = "<missing " + recognizer.GetTokenNames()[expectedTokenType] + ">";
|
tokenText = "<missing " + recognizer.GetTokenNames()[expectedTokenType] + ">";
|
||||||
}
|
}
|
||||||
Token current = currentSymbol;
|
Token current = currentSymbol;
|
||||||
Token lookback = ((TokenStream)recognizer.GetInputStream()).Lt(-1);
|
Token lookback = ((ITokenStream)recognizer.GetInputStream()).Lt(-1);
|
||||||
if (current.GetType() == Token.Eof && lookback != null)
|
if (current.GetType() == Token.Eof && lookback != null)
|
||||||
{
|
{
|
||||||
current = lookback;
|
current = lookback;
|
||||||
}
|
}
|
||||||
return ConstructToken(((TokenStream)recognizer.GetInputStream()).GetTokenSource()
|
return ConstructToken(((ITokenStream)recognizer.GetInputStream()).GetTokenSource(
|
||||||
, expectedTokenType, tokenText, current);
|
), 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)
|
, string tokenText, Token current)
|
||||||
{
|
{
|
||||||
TokenFactory factory = tokenSource.GetTokenFactory();
|
ITokenFactory factory = tokenSource.GetTokenFactory();
|
||||||
return factory.Create(Tuple.Create(tokenSource, current.GetTokenSource().GetInputStream
|
return factory.Create(Tuple.Create(tokenSource, current.GetTokenSource().GetInputStream
|
||||||
()), expectedTokenType, tokenText, Token.DefaultChannel, -1, -1, current.GetLine
|
()), expectedTokenType, tokenText, Token.DefaultChannel, -1, -1, current.GetLine
|
||||||
(), current.GetCharPositionInLine());
|
(), current.GetCharPositionInLine());
|
||||||
|
@ -536,13 +536,13 @@ namespace Antlr4.Runtime
|
||||||
public virtual void ConsumeUntil(Parser recognizer, IntervalSet set)
|
public virtual void ConsumeUntil(Parser recognizer, IntervalSet set)
|
||||||
{
|
{
|
||||||
// System.err.println("consumeUntil("+set.toString(recognizer.getTokenNames())+")");
|
// 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))
|
while (ttype != Token.Eof && !set.Contains(ttype))
|
||||||
{
|
{
|
||||||
//System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]);
|
//System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]);
|
||||||
// recognizer.getInputStream().consume();
|
// recognizer.getInputStream().consume();
|
||||||
recognizer.Consume();
|
recognizer.Consume();
|
||||||
ttype = ((TokenStream)recognizer.GetInputStream()).La(1);
|
ttype = ((ITokenStream)recognizer.GetInputStream()).La(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ using Sharpen;
|
||||||
namespace Antlr4.Runtime.Dfa
|
namespace Antlr4.Runtime.Dfa
|
||||||
{
|
{
|
||||||
/// <author>Sam Harwell</author>
|
/// <author>Sam Harwell</author>
|
||||||
public abstract class AbstractEdgeMap<T> : EdgeMap<T>
|
public abstract class AbstractEdgeMap<T> : IEdgeMap<T>
|
||||||
{
|
{
|
||||||
protected internal readonly int minIndex;
|
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 abstract Antlr4.Runtime.Dfa.AbstractEdgeMap<T> Put(int key, T value);
|
||||||
|
|
||||||
public virtual Antlr4.Runtime.Dfa.AbstractEdgeMap<T> PutAll<_T0>(EdgeMap<_T0> m) where
|
public virtual Antlr4.Runtime.Dfa.AbstractEdgeMap<T> PutAll<_T0>(IEdgeMap<_T0> m)
|
||||||
_T0:T
|
where _T0:T
|
||||||
{
|
{
|
||||||
Antlr4.Runtime.Dfa.AbstractEdgeMap<T> result = this;
|
Antlr4.Runtime.Dfa.AbstractEdgeMap<T> result = this;
|
||||||
foreach (KeyValuePair<int, T> entry in m.EntrySet())
|
foreach (KeyValuePair<int, T> entry in m.EntrySet())
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace Antlr4.Runtime.Dfa
|
||||||
return ((Antlr4.Runtime.Dfa.ArrayEdgeMap<T>)Put(key, null));
|
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())
|
if (m.IsEmpty())
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,8 +68,8 @@ namespace Antlr4.Runtime.Dfa
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set of configs for a DFA state with at least one conflict? Mainly used as "return value"
|
/// Set of configs for a DFA state with at least one conflict? Mainly used as "return value"
|
||||||
/// from
|
/// from
|
||||||
/// <see cref="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, Antlr4.Runtime.TokenStream, Antlr4.Runtime.ParserRuleContext, bool)
|
/// ">Antlr4.Runtime.Atn.ParserATNSimulator.PredictATN(DFA, ITokenStream, Antlr4.Runtime.ParserRuleContext, bool)
|
||||||
/// </see>
|
/// </see>
|
||||||
/// for retry.
|
/// for retry.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Antlr4.Runtime.Dfa;
|
|
||||||
using Antlr4.Runtime.Misc;
|
using Antlr4.Runtime.Misc;
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
|
@ -47,16 +46,16 @@ namespace Antlr4.Runtime.Dfa
|
||||||
T Get(int key);
|
T Get(int key);
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
EdgeMap<T> Put(int key, T value);
|
IEdgeMap<T> Put(int key, T value);
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
EdgeMap<T> Remove(int key);
|
IEdgeMap<T> Remove(int key);
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
EdgeMap<T> PutAll<_T0>(EdgeMap<_T0> m) where _T0:T;
|
IEdgeMap<T> PutAll<_T0>(IEdgeMap<_T0> m) where _T0:T;
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
EdgeMap<T> Clear();
|
IEdgeMap<T> Clear();
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
IDictionary<int, T> ToMap();
|
IDictionary<int, T> ToMap();
|
||||||
|
|
|
@ -42,8 +42,8 @@ namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
string format = "reportAmbiguity d=%s: ambigAlts=%s, input='%s'";
|
string format = "reportAmbiguity d=%s: ambigAlts=%s, input='%s'";
|
||||||
recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer
|
recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer
|
||||||
, dfa.decision), ambigAlts, ((TokenStream)recognizer.GetInputStream()).GetText(Interval
|
, dfa.decision), ambigAlts, ((ITokenStream)recognizer.GetInputStream()).GetText(
|
||||||
.Of(startIndex, stopIndex))));
|
Interval.Of(startIndex, stopIndex))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int
|
public override void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int
|
||||||
|
@ -51,8 +51,8 @@ namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
string format = "reportAttemptingFullContext d=%s, input='%s'";
|
string format = "reportAttemptingFullContext d=%s, input='%s'";
|
||||||
recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer
|
recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer
|
||||||
, dfa.decision), ((TokenStream)recognizer.GetInputStream()).GetText(Interval.Of(
|
, dfa.decision), ((ITokenStream)recognizer.GetInputStream()).GetText(Interval.Of
|
||||||
startIndex, stopIndex))));
|
(startIndex, stopIndex))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex
|
public override void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex
|
||||||
|
@ -60,8 +60,8 @@ namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
string format = "reportContextSensitivity d=%s, input='%s'";
|
string format = "reportContextSensitivity d=%s, input='%s'";
|
||||||
recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer
|
recognizer.NotifyErrorListeners(string.Format(format, GetDecisionDescription(recognizer
|
||||||
, dfa.decision), ((TokenStream)recognizer.GetInputStream()).GetText(Interval.Of(
|
, dfa.decision), ((ITokenStream)recognizer.GetInputStream()).GetText(Interval.Of
|
||||||
startIndex, stopIndex))));
|
(startIndex, stopIndex))));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal virtual string GetDecisionDescription(Parser recognizer, int decision
|
protected internal virtual string GetDecisionDescription(Parser recognizer, int decision
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace Antlr4.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
public FailedPredicateException(Parser recognizer, string predicate, string message
|
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)
|
.GetInputStream()), recognizer._ctx)
|
||||||
{
|
{
|
||||||
ATNState s = recognizer.GetInterpreter().atn.states[recognizer.GetState()];
|
ATNState s = recognizer.GetInterpreter().atn.states[recognizer.GetState()];
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
private const long serialVersionUID = 1532568338707443067L;
|
private const long serialVersionUID = 1532568338707443067L;
|
||||||
|
|
||||||
public InputMismatchException(Parser recognizer) : base(recognizer, ((TokenStream
|
public InputMismatchException(Parser recognizer) : base(recognizer, ((ITokenStream
|
||||||
)recognizer.GetInputStream()), recognizer._ctx)
|
)recognizer.GetInputStream()), recognizer._ctx)
|
||||||
{
|
{
|
||||||
this.SetOffendingToken(recognizer.GetCurrentToken());
|
this.SetOffendingToken(recognizer.GetCurrentToken());
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace Antlr4.Runtime
|
||||||
/// uses simplified match() and error recovery mechanisms in the interest
|
/// uses simplified match() and error recovery mechanisms in the interest
|
||||||
/// of speed.
|
/// of speed.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public abstract class Lexer : Recognizer<int, LexerATNSimulator>, TokenSource
|
public abstract class Lexer : Recognizer<int, LexerATNSimulator>, ITokenSource
|
||||||
{
|
{
|
||||||
public const int DefaultMode = 0;
|
public const int DefaultMode = 0;
|
||||||
|
|
||||||
|
@ -62,10 +62,10 @@ namespace Antlr4.Runtime
|
||||||
|
|
||||||
public CharStream _input;
|
public CharStream _input;
|
||||||
|
|
||||||
protected internal Tuple<TokenSource, CharStream> _tokenFactorySourcePair;
|
protected internal Tuple<ITokenSource, CharStream> _tokenFactorySourcePair;
|
||||||
|
|
||||||
/// <summary>How to create token objects</summary>
|
/// <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>
|
/// <summary>The goal of all lexer rules/methods is to create a token object.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
@ -274,12 +274,12 @@ outer_break: ;
|
||||||
return _mode;
|
return _mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual TokenFactory GetTokenFactory()
|
public virtual ITokenFactory GetTokenFactory()
|
||||||
{
|
{
|
||||||
return _factory;
|
return _factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void SetTokenFactory(TokenFactory factory)
|
public virtual void SetTokenFactory(ITokenFactory factory)
|
||||||
{
|
{
|
||||||
this._factory = factory;
|
this._factory = factory;
|
||||||
}
|
}
|
||||||
|
@ -492,7 +492,7 @@ outer_break: ;
|
||||||
{
|
{
|
||||||
string text = _input.GetText(Interval.Of(_tokenStartCharIndex, _input.Index()));
|
string text = _input.GetText(Interval.Of(_tokenStartCharIndex, _input.Index()));
|
||||||
string msg = "token recognition error at: '" + GetErrorDisplay(text) + "'";
|
string msg = "token recognition error at: '" + GetErrorDisplay(text) + "'";
|
||||||
ANTLRErrorListener<int> listener = GetErrorListenerDispatch();
|
IAntlrErrorListener<int> listener = GetErrorListenerDispatch();
|
||||||
listener.SyntaxError(this, null, _tokenStartLine, _tokenStartCharPositionInLine,
|
listener.SyntaxError(this, null, _tokenStartLine, _tokenStartCharPositionInLine,
|
||||||
msg, e);
|
msg, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Antlr4.Runtime.Misc;
|
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime.Misc
|
namespace Antlr4.Runtime.Misc
|
||||||
|
@ -46,7 +45,7 @@ namespace Antlr4.Runtime.Misc
|
||||||
/// Add all elements from incoming set to this set. Can limit
|
/// Add all elements from incoming set to this set. Can limit
|
||||||
/// to set of its own type. Return "this" so we can chain calls.
|
/// to set of its own type. Return "this" so we can chain calls.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
IntSet AddAll(IntSet set);
|
IIntSet AddAll(IIntSet set);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the intersection of this set with the argument, creating
|
/// 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
|
/// Return the intersection of this set with the argument, creating
|
||||||
/// a new set.
|
/// a new set.
|
||||||
/// </remarks>
|
/// </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>
|
/// <summary>
|
||||||
/// Return the size of this set (not the underlying implementation's
|
/// Return the size of this set (not the underlying implementation's
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace Antlr4.Runtime.Misc
|
||||||
/// elements are encoded with an index pair where both intervals are the same.
|
/// 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.
|
/// The ranges are ordered and disjoint so that 2..6 appears before 101..103.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class IntervalSet : IntSet
|
public class IntervalSet : IIntSet
|
||||||
{
|
{
|
||||||
public static readonly Antlr4.Runtime.Misc.IntervalSet CompleteCharSet = Antlr4.Runtime.Misc.IntervalSet
|
public static readonly Antlr4.Runtime.Misc.IntervalSet CompleteCharSet = Antlr4.Runtime.Misc.IntervalSet
|
||||||
.Of(0, Lexer.MaxCharValue);
|
.Of(0, Lexer.MaxCharValue);
|
||||||
|
@ -219,7 +219,7 @@ namespace Antlr4.Runtime.Misc
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Antlr4.Runtime.Misc.IntervalSet AddAll(IntSet set)
|
public virtual Antlr4.Runtime.Misc.IntervalSet AddAll(IIntSet set)
|
||||||
{
|
{
|
||||||
if (set == null)
|
if (set == null)
|
||||||
{
|
{
|
||||||
|
@ -259,7 +259,7 @@ namespace Antlr4.Runtime.Misc
|
||||||
/// this. The computation is (vocabulary - this).
|
/// this. The computation is (vocabulary - this).
|
||||||
/// 'this' is assumed to be either a subset or equal to vocabulary.
|
/// 'this' is assumed to be either a subset or equal to vocabulary.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual Antlr4.Runtime.Misc.IntervalSet Complement(IntSet vocabulary)
|
public virtual Antlr4.Runtime.Misc.IntervalSet Complement(IIntSet vocabulary)
|
||||||
{
|
{
|
||||||
if (vocabulary == null)
|
if (vocabulary == null)
|
||||||
{
|
{
|
||||||
|
@ -318,7 +318,7 @@ namespace Antlr4.Runtime.Misc
|
||||||
/// other is assumed to be a subset of this;
|
/// other is assumed to be a subset of this;
|
||||||
/// anything that is in other but not in this will be ignored.
|
/// anything that is in other but not in this will be ignored.
|
||||||
/// </remarks>
|
/// </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
|
// assume the whole unicode range here for the complement
|
||||||
// because it doesn't matter. Anything beyond the max of this' set
|
// 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();
|
Antlr4.Runtime.Misc.IntervalSet o = new Antlr4.Runtime.Misc.IntervalSet();
|
||||||
o.AddAll(this);
|
o.AddAll(this);
|
||||||
|
@ -345,7 +345,7 @@ namespace Antlr4.Runtime.Misc
|
||||||
/// just walk them together. This is roughly O(min(n,m)) for interval
|
/// just walk them together. This is roughly O(min(n,m)) for interval
|
||||||
/// list lengths n and m.
|
/// list lengths n and m.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual Antlr4.Runtime.Misc.IntervalSet And(IntSet other)
|
public virtual Antlr4.Runtime.Misc.IntervalSet And(IIntSet other)
|
||||||
{
|
{
|
||||||
if (other == null)
|
if (other == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -214,8 +214,8 @@ namespace Antlr4.Runtime.Misc
|
||||||
{
|
{
|
||||||
System.Console.Error.WriteLine("Can't load " + parserName);
|
System.Console.Error.WriteLine("Can't load " + parserName);
|
||||||
}
|
}
|
||||||
Constructor<Parser> parserCtor = parserClass.GetConstructor(typeof(TokenStream));
|
Constructor<Parser> parserCtor = parserClass.GetConstructor(typeof(ITokenStream));
|
||||||
parser = parserCtor.NewInstance((TokenStream)null);
|
parser = parserCtor.NewInstance((ITokenStream)null);
|
||||||
}
|
}
|
||||||
if (inputFiles.IsEmpty())
|
if (inputFiles.IsEmpty())
|
||||||
{
|
{
|
||||||
|
|
|
@ -67,13 +67,13 @@ namespace Antlr4.Runtime
|
||||||
[NotNull]
|
[NotNull]
|
||||||
private readonly Token startToken;
|
private readonly Token startToken;
|
||||||
|
|
||||||
public NoViableAltException(Parser recognizer) : this(recognizer, ((TokenStream)recognizer
|
public NoViableAltException(Parser recognizer) : this(recognizer, ((ITokenStream)
|
||||||
.GetInputStream()), recognizer.GetCurrentToken(), recognizer.GetCurrentToken(),
|
recognizer.GetInputStream()), recognizer.GetCurrentToken(), recognizer.GetCurrentToken
|
||||||
null, recognizer._ctx)
|
(), 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
|
, Token startToken, Token offendingToken, ATNConfigSet deadEndConfigs, ParserRuleContext
|
||||||
ctx) : base(recognizer, input, ctx)
|
ctx) : base(recognizer, input, ctx)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,7 +33,6 @@ using Antlr4.Runtime;
|
||||||
using Antlr4.Runtime.Atn;
|
using Antlr4.Runtime.Atn;
|
||||||
using Antlr4.Runtime.Dfa;
|
using Antlr4.Runtime.Dfa;
|
||||||
using Antlr4.Runtime.Misc;
|
using Antlr4.Runtime.Misc;
|
||||||
using Antlr4.Runtime.Tree;
|
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime
|
namespace Antlr4.Runtime
|
||||||
|
@ -44,7 +43,7 @@ namespace Antlr4.Runtime
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public abstract class Parser : Recognizer<Token, ParserATNSimulator>
|
public abstract class Parser : Recognizer<Token, ParserATNSimulator>
|
||||||
{
|
{
|
||||||
public class TraceListener : ParseTreeListener
|
public class TraceListener : IParseTreeListener
|
||||||
{
|
{
|
||||||
public virtual void EnterEveryRule(ParserRuleContext ctx)
|
public virtual void EnterEveryRule(ParserRuleContext ctx)
|
||||||
{
|
{
|
||||||
|
@ -58,11 +57,11 @@ namespace Antlr4.Runtime
|
||||||
()] + ", LT(1)=" + this._enclosing._input.Lt(1).GetText());
|
()] + ", 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();
|
ParserRuleContext parent = (ParserRuleContext)node.GetParent().GetRuleContext();
|
||||||
Token token = node.GetSymbol();
|
Token token = node.GetSymbol();
|
||||||
|
@ -78,16 +77,16 @@ namespace Antlr4.Runtime
|
||||||
private readonly Parser _enclosing;
|
private readonly Parser _enclosing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TrimToSizeListener : ParseTreeListener
|
public class TrimToSizeListener : IParseTreeListener
|
||||||
{
|
{
|
||||||
public static readonly Parser.TrimToSizeListener Instance = new Parser.TrimToSizeListener
|
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;
|
protected internal readonly IntegerStack _precedenceStack;
|
||||||
|
|
||||||
|
@ -137,13 +136,13 @@ namespace Antlr4.Runtime
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <seealso cref="Antlr4.Runtime.Tree.ParseTreeWalker">Antlr4.Runtime.Tree.ParseTreeWalker
|
/// <seealso cref="Antlr4.Runtime.Tree.ParseTreeWalker">Antlr4.Runtime.Tree.ParseTreeWalker
|
||||||
/// </seealso>
|
/// </seealso>
|
||||||
protected internal IList<ParseTreeListener> _parseListeners;
|
protected internal IList<IParseTreeListener> _parseListeners;
|
||||||
|
|
||||||
/// <summary>Did the recognizer encounter a syntax error? Track how many.</summary>
|
/// <summary>Did the recognizer encounter a syntax error? Track how many.</summary>
|
||||||
/// <remarks>Did the recognizer encounter a syntax error? Track how many.</remarks>
|
/// <remarks>Did the recognizer encounter a syntax error? Track how many.</remarks>
|
||||||
protected internal int _syntaxErrors = 0;
|
protected internal int _syntaxErrors = 0;
|
||||||
|
|
||||||
public Parser(TokenStream input)
|
public Parser(ITokenStream input)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
_precedenceStack = new IntegerStack();
|
_precedenceStack = new IntegerStack();
|
||||||
|
@ -155,9 +154,9 @@ namespace Antlr4.Runtime
|
||||||
/// <summary>reset the parser's state</summary>
|
/// <summary>reset the parser's state</summary>
|
||||||
public virtual void Reset()
|
public virtual void Reset()
|
||||||
{
|
{
|
||||||
if (((TokenStream)GetInputStream()) != null)
|
if (((ITokenStream)GetInputStream()) != null)
|
||||||
{
|
{
|
||||||
((TokenStream)GetInputStream()).Seek(0);
|
((ITokenStream)GetInputStream()).Seek(0);
|
||||||
}
|
}
|
||||||
_errHandler.EndErrorCondition(this);
|
_errHandler.EndErrorCondition(this);
|
||||||
_ctx = null;
|
_ctx = null;
|
||||||
|
@ -311,7 +310,7 @@ namespace Antlr4.Runtime
|
||||||
// public boolean getTraceATNStates() {
|
// public boolean getTraceATNStates() {
|
||||||
// return traceATNStates;
|
// return traceATNStates;
|
||||||
// }
|
// }
|
||||||
public virtual IList<ParseTreeListener> GetParseListeners()
|
public virtual IList<IParseTreeListener> GetParseListeners()
|
||||||
{
|
{
|
||||||
return _parseListeners;
|
return _parseListeners;
|
||||||
}
|
}
|
||||||
|
@ -329,7 +328,7 @@ namespace Antlr4.Runtime
|
||||||
/// ParseTreeListener to a ParseTreeWalker instead of giving it to
|
/// ParseTreeListener to a ParseTreeWalker instead of giving it to
|
||||||
/// the parser!!!!
|
/// the parser!!!!
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual void AddParseListener(ParseTreeListener listener)
|
public virtual void AddParseListener(IParseTreeListener listener)
|
||||||
{
|
{
|
||||||
if (listener == null)
|
if (listener == null)
|
||||||
{
|
{
|
||||||
|
@ -337,12 +336,12 @@ namespace Antlr4.Runtime
|
||||||
}
|
}
|
||||||
if (_parseListeners == null)
|
if (_parseListeners == null)
|
||||||
{
|
{
|
||||||
_parseListeners = new AList<ParseTreeListener>();
|
_parseListeners = new AList<IParseTreeListener>();
|
||||||
}
|
}
|
||||||
this._parseListeners.AddItem(listener);
|
this._parseListeners.AddItem(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void RemoveParseListener(ParseTreeListener l)
|
public virtual void RemoveParseListener(IParseTreeListener l)
|
||||||
{
|
{
|
||||||
if (l == null)
|
if (l == null)
|
||||||
{
|
{
|
||||||
|
@ -375,7 +374,7 @@ namespace Antlr4.Runtime
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual void TriggerEnterRuleEvent()
|
public virtual void TriggerEnterRuleEvent()
|
||||||
{
|
{
|
||||||
foreach (ParseTreeListener l in _parseListeners)
|
foreach (IParseTreeListener l in _parseListeners)
|
||||||
{
|
{
|
||||||
l.EnterEveryRule(_ctx);
|
l.EnterEveryRule(_ctx);
|
||||||
_ctx.EnterRule(l);
|
_ctx.EnterRule(l);
|
||||||
|
@ -397,7 +396,7 @@ namespace Antlr4.Runtime
|
||||||
// reverse order walk of listeners
|
// reverse order walk of listeners
|
||||||
for (int i = _parseListeners.Count - 1; i >= 0; i--)
|
for (int i = _parseListeners.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
ParseTreeListener l = _parseListeners[i];
|
IParseTreeListener l = _parseListeners[i];
|
||||||
_ctx.ExitRule(l);
|
_ctx.ExitRule(l);
|
||||||
l.ExitEveryRule(_ctx);
|
l.ExitEveryRule(_ctx);
|
||||||
}
|
}
|
||||||
|
@ -416,12 +415,12 @@ namespace Antlr4.Runtime
|
||||||
return _syntaxErrors;
|
return _syntaxErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual ANTLRErrorStrategy GetErrorHandler()
|
public virtual IAntlrErrorStrategy GetErrorHandler()
|
||||||
{
|
{
|
||||||
return _errHandler;
|
return _errHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void SetErrorHandler(ANTLRErrorStrategy handler)
|
public virtual void SetErrorHandler(IAntlrErrorStrategy handler)
|
||||||
{
|
{
|
||||||
this._errHandler = handler;
|
this._errHandler = handler;
|
||||||
}
|
}
|
||||||
|
@ -432,7 +431,7 @@ namespace Antlr4.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Set the token stream and reset the parser</summary>
|
/// <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;
|
this._input = null;
|
||||||
Reset();
|
Reset();
|
||||||
|
@ -467,7 +466,7 @@ namespace Antlr4.Runtime
|
||||||
line = offendingToken.GetLine();
|
line = offendingToken.GetLine();
|
||||||
charPositionInLine = offendingToken.GetCharPositionInLine();
|
charPositionInLine = offendingToken.GetCharPositionInLine();
|
||||||
}
|
}
|
||||||
ANTLRErrorListener<Token> listener = ((ParserErrorListener)GetErrorListenerDispatch
|
IAntlrErrorListener<Token> listener = ((IParserErrorListener)GetErrorListenerDispatch
|
||||||
());
|
());
|
||||||
listener.SyntaxError(this, offendingToken, line, charPositionInLine, msg, e);
|
listener.SyntaxError(this, offendingToken, line, charPositionInLine, msg, e);
|
||||||
}
|
}
|
||||||
|
@ -488,17 +487,17 @@ namespace Antlr4.Runtime
|
||||||
Token o = GetCurrentToken();
|
Token o = GetCurrentToken();
|
||||||
if (o.GetType() != Eof)
|
if (o.GetType() != Eof)
|
||||||
{
|
{
|
||||||
((TokenStream)GetInputStream()).Consume();
|
((ITokenStream)GetInputStream()).Consume();
|
||||||
}
|
}
|
||||||
bool hasListener = _parseListeners != null && !_parseListeners.IsEmpty();
|
bool hasListener = _parseListeners != null && !_parseListeners.IsEmpty();
|
||||||
if (_buildParseTrees || hasListener)
|
if (_buildParseTrees || hasListener)
|
||||||
{
|
{
|
||||||
if (_errHandler.InErrorRecoveryMode(this))
|
if (_errHandler.InErrorRecoveryMode(this))
|
||||||
{
|
{
|
||||||
ErrorNode node = _ctx.AddErrorNode(o);
|
IErrorNode node = _ctx.AddErrorNode(o);
|
||||||
if (_parseListeners != null)
|
if (_parseListeners != null)
|
||||||
{
|
{
|
||||||
foreach (ParseTreeListener listener in _parseListeners)
|
foreach (IParseTreeListener listener in _parseListeners)
|
||||||
{
|
{
|
||||||
listener.VisitErrorNode(node);
|
listener.VisitErrorNode(node);
|
||||||
}
|
}
|
||||||
|
@ -506,10 +505,10 @@ namespace Antlr4.Runtime
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TerminalNode node = _ctx.AddChild(o);
|
ITerminalNode node = _ctx.AddChild(o);
|
||||||
if (_parseListeners != null)
|
if (_parseListeners != null)
|
||||||
{
|
{
|
||||||
foreach (ParseTreeListener listener in _parseListeners)
|
foreach (IParseTreeListener listener in _parseListeners)
|
||||||
{
|
{
|
||||||
listener.VisitTerminal(node);
|
listener.VisitTerminal(node);
|
||||||
}
|
}
|
||||||
|
@ -691,7 +690,7 @@ namespace Antlr4.Runtime
|
||||||
return precedence >= _precedenceStack.Peek();
|
return precedence >= _precedenceStack.Peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ANTLRErrorListener<Token> GetErrorListenerDispatch()
|
public override IAntlrErrorListener<Token> GetErrorListenerDispatch()
|
||||||
{
|
{
|
||||||
return new ProxyParserErrorListener(GetErrorListeners());
|
return new ProxyParserErrorListener(GetErrorListeners());
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ using Sharpen;
|
||||||
namespace Antlr4.Runtime
|
namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
/// <summary>How to emit recognition errors</summary>
|
/// <summary>How to emit recognition errors</summary>
|
||||||
public interface ParserErrorListener : ANTLRErrorListener<Token>
|
public interface ParserErrorListener : IAntlrErrorListener<Token>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the parser detects a true ambiguity: an input sequence can be matched
|
/// Called when the parser detects a true ambiguity: an input sequence can be matched
|
||||||
|
|
|
@ -74,7 +74,7 @@ namespace Antlr4.Runtime
|
||||||
/// operation because we don't the need to track the details about
|
/// operation because we don't the need to track the details about
|
||||||
/// how we parse this rule.
|
/// how we parse this rule.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public IList<ParseTree> children;
|
public IList<IParseTree> children;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For debugging/tracing purposes, we want to track all of the nodes in
|
/// 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
|
// 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>
|
/// <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)
|
if (children == null)
|
||||||
{
|
{
|
||||||
children = new AList<ParseTree>();
|
children = new AList<IParseTree>();
|
||||||
}
|
}
|
||||||
children.AddItem(t);
|
children.AddItem(t);
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
if (children == null)
|
if (children == null)
|
||||||
{
|
{
|
||||||
children = new AList<ParseTree>();
|
children = new AList<IParseTree>();
|
||||||
}
|
}
|
||||||
children.AddItem(ruleInvocation);
|
children.AddItem(ruleInvocation);
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ namespace Antlr4.Runtime
|
||||||
// if ( states==null ) states = new ArrayList<Integer>();
|
// if ( states==null ) states = new ArrayList<Integer>();
|
||||||
// states.add(s);
|
// states.add(s);
|
||||||
// }
|
// }
|
||||||
public virtual TerminalNode AddChild(Token matchedToken)
|
public virtual ITerminalNode AddChild(Token matchedToken)
|
||||||
{
|
{
|
||||||
TerminalNodeImpl t = new TerminalNodeImpl(matchedToken);
|
TerminalNodeImpl t = new TerminalNodeImpl(matchedToken);
|
||||||
AddChild(t);
|
AddChild(t);
|
||||||
|
@ -215,7 +215,7 @@ namespace Antlr4.Runtime
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual ErrorNode AddErrorNode(Token badToken)
|
public virtual IErrorNode AddErrorNode(Token badToken)
|
||||||
{
|
{
|
||||||
ErrorNodeImpl t = new ErrorNodeImpl(badToken);
|
ErrorNodeImpl t = new ErrorNodeImpl(badToken);
|
||||||
AddChild(t);
|
AddChild(t);
|
||||||
|
@ -228,12 +228,12 @@ namespace Antlr4.Runtime
|
||||||
return (Antlr4.Runtime.ParserRuleContext)base.GetParent();
|
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;
|
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
|
_T1:T
|
||||||
{
|
{
|
||||||
if (children == null || i < 0 || i >= children.Count)
|
if (children == null || i < 0 || i >= children.Count)
|
||||||
|
@ -242,7 +242,7 @@ namespace Antlr4.Runtime
|
||||||
}
|
}
|
||||||
int j = -1;
|
int j = -1;
|
||||||
// what element have we found with ctxType?
|
// what element have we found with ctxType?
|
||||||
foreach (ParseTree o in children)
|
foreach (IParseTree o in children)
|
||||||
{
|
{
|
||||||
if (ctxType.IsInstanceOfType(o))
|
if (ctxType.IsInstanceOfType(o))
|
||||||
{
|
{
|
||||||
|
@ -256,7 +256,7 @@ namespace Antlr4.Runtime
|
||||||
return null;
|
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)
|
if (children == null || i < 0 || i >= children.Count)
|
||||||
{
|
{
|
||||||
|
@ -264,11 +264,11 @@ namespace Antlr4.Runtime
|
||||||
}
|
}
|
||||||
int j = -1;
|
int j = -1;
|
||||||
// what token with ttype have we found?
|
// 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();
|
Token symbol = tnode.GetSymbol();
|
||||||
if (symbol.GetType() == ttype)
|
if (symbol.GetType() == ttype)
|
||||||
{
|
{
|
||||||
|
@ -283,24 +283,24 @@ namespace Antlr4.Runtime
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IList<TerminalNode> GetTokens(int ttype)
|
public virtual IList<ITerminalNode> GetTokens(int ttype)
|
||||||
{
|
{
|
||||||
if (children == null)
|
if (children == null)
|
||||||
{
|
{
|
||||||
return Sharpen.Collections.EmptyList();
|
return Sharpen.Collections.EmptyList();
|
||||||
}
|
}
|
||||||
IList<TerminalNode> tokens = null;
|
IList<ITerminalNode> tokens = null;
|
||||||
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();
|
Token symbol = tnode.GetSymbol();
|
||||||
if (symbol.GetType() == ttype)
|
if (symbol.GetType() == ttype)
|
||||||
{
|
{
|
||||||
if (tokens == null)
|
if (tokens == null)
|
||||||
{
|
{
|
||||||
tokens = new AList<TerminalNode>();
|
tokens = new AList<ITerminalNode>();
|
||||||
}
|
}
|
||||||
tokens.AddItem(tnode);
|
tokens.AddItem(tnode);
|
||||||
}
|
}
|
||||||
|
@ -327,7 +327,7 @@ namespace Antlr4.Runtime
|
||||||
return Sharpen.Collections.EmptyList();
|
return Sharpen.Collections.EmptyList();
|
||||||
}
|
}
|
||||||
IList<T> contexts = null;
|
IList<T> contexts = null;
|
||||||
foreach (ParseTree o in children)
|
foreach (IParseTree o in children)
|
||||||
{
|
{
|
||||||
if (ctxType.IsInstanceOfType(o))
|
if (ctxType.IsInstanceOfType(o))
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,16 +34,17 @@ using Sharpen;
|
||||||
namespace Antlr4.Runtime
|
namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
/// <author>Sam Harwell</author>
|
/// <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;
|
this.delegates = delegates;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal virtual ICollection<ANTLRErrorListener<Symbol>> GetDelegates()
|
protected internal virtual ICollection<IAntlrErrorListener<Symbol>> GetDelegates(
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return delegates;
|
return delegates;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +53,7 @@ namespace Antlr4.Runtime
|
||||||
, int line, int charPositionInLine, string msg, RecognitionException e) where T:
|
, int line, int charPositionInLine, string msg, RecognitionException e) where T:
|
||||||
Symbol
|
Symbol
|
||||||
{
|
{
|
||||||
foreach (ANTLRErrorListener<Symbol> listener in delegates)
|
foreach (IAntlrErrorListener<Symbol> listener in delegates)
|
||||||
{
|
{
|
||||||
listener.SyntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg,
|
listener.SyntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg,
|
||||||
e);
|
e);
|
||||||
|
|
|
@ -36,23 +36,23 @@ using Sharpen;
|
||||||
namespace Antlr4.Runtime
|
namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
/// <author>Sam Harwell</author>
|
/// <author>Sam Harwell</author>
|
||||||
public class ProxyParserErrorListener : ProxyErrorListener<Token>, ParserErrorListener
|
public class ProxyParserErrorListener : ProxyErrorListener<Token>, IParserErrorListener
|
||||||
{
|
{
|
||||||
public ProxyParserErrorListener(ICollection<ANTLRErrorListener<Token>> delegates)
|
public ProxyParserErrorListener(ICollection<IAntlrErrorListener<Token>> delegates
|
||||||
: base(delegates)
|
) : base(delegates)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int
|
public virtual void ReportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int
|
||||||
stopIndex, BitSet ambigAlts, ATNConfigSet configs)
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
ParserErrorListener parserErrorListener = (ParserErrorListener)listener;
|
IParserErrorListener parserErrorListener = (IParserErrorListener)listener;
|
||||||
parserErrorListener.ReportAmbiguity(recognizer, dfa, startIndex, stopIndex, ambigAlts
|
parserErrorListener.ReportAmbiguity(recognizer, dfa, startIndex, stopIndex, ambigAlts
|
||||||
, configs);
|
, configs);
|
||||||
}
|
}
|
||||||
|
@ -61,13 +61,13 @@ namespace Antlr4.Runtime
|
||||||
public virtual void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex
|
public virtual void ReportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex
|
||||||
, int stopIndex, SimulatorState initialState)
|
, 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;
|
continue;
|
||||||
}
|
}
|
||||||
ParserErrorListener parserErrorListener = (ParserErrorListener)listener;
|
IParserErrorListener parserErrorListener = (IParserErrorListener)listener;
|
||||||
parserErrorListener.ReportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex
|
parserErrorListener.ReportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex
|
||||||
, initialState);
|
, initialState);
|
||||||
}
|
}
|
||||||
|
@ -76,13 +76,13 @@ namespace Antlr4.Runtime
|
||||||
public virtual void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex
|
public virtual void ReportContextSensitivity(Parser recognizer, DFA dfa, int startIndex
|
||||||
, int stopIndex, SimulatorState acceptState)
|
, 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;
|
continue;
|
||||||
}
|
}
|
||||||
ParserErrorListener parserErrorListener = (ParserErrorListener)listener;
|
IParserErrorListener parserErrorListener = (IParserErrorListener)listener;
|
||||||
parserErrorListener.ReportContextSensitivity(recognizer, dfa, startIndex, stopIndex
|
parserErrorListener.ReportContextSensitivity(recognizer, dfa, startIndex, stopIndex
|
||||||
, acceptState);
|
, acceptState);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
public const int Eof = -1;
|
public const int Eof = -1;
|
||||||
|
|
||||||
private sealed class _CopyOnWriteArrayList_49 : CopyOnWriteArrayList<ANTLRErrorListener
|
private sealed class _CopyOnWriteArrayList_49 : CopyOnWriteArrayList<IAntlrErrorListener
|
||||||
<Symbol>>
|
<Symbol>>
|
||||||
{
|
{
|
||||||
public _CopyOnWriteArrayList_49()
|
public _CopyOnWriteArrayList_49()
|
||||||
|
@ -51,7 +51,7 @@ namespace Antlr4.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
private IList<ANTLRErrorListener<Symbol>> _listeners = new _CopyOnWriteArrayList_49
|
private IList<IAntlrErrorListener<Symbol>> _listeners = new _CopyOnWriteArrayList_49
|
||||||
();
|
();
|
||||||
|
|
||||||
protected internal ATNInterpreter _interp;
|
protected internal ATNInterpreter _interp;
|
||||||
|
@ -146,13 +146,13 @@ namespace Antlr4.Runtime
|
||||||
/// <code>null</code>
|
/// <code>null</code>
|
||||||
/// .
|
/// .
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public virtual void AddErrorListener<_T0>(ANTLRErrorListener<_T0> listener)
|
public virtual void AddErrorListener<_T0>(IAntlrErrorListener<_T0> listener)
|
||||||
{
|
{
|
||||||
Args.NotNull("listener", listener);
|
Args.NotNull("listener", listener);
|
||||||
_listeners.AddItem(listener);
|
_listeners.AddItem(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void RemoveErrorListener<_T0>(ANTLRErrorListener<_T0> listener)
|
public virtual void RemoveErrorListener<_T0>(IAntlrErrorListener<_T0> listener)
|
||||||
{
|
{
|
||||||
_listeners.Remove(listener);
|
_listeners.Remove(listener);
|
||||||
}
|
}
|
||||||
|
@ -163,12 +163,12 @@ namespace Antlr4.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
[NotNull]
|
[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());
|
return new ProxyErrorListener<Symbol>(GetErrorListeners());
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace Antlr4.Runtime
|
||||||
/// ParserRuleContext.
|
/// ParserRuleContext.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <seealso cref="ParserRuleContext">ParserRuleContext</seealso>
|
/// <seealso cref="ParserRuleContext">ParserRuleContext</seealso>
|
||||||
public class RuleContext : RuleNode
|
public class RuleContext : IRuleNode
|
||||||
{
|
{
|
||||||
/// <summary>What context invoked this rule?</summary>
|
/// <summary>What context invoked this rule?</summary>
|
||||||
public Antlr4.Runtime.RuleContext parent;
|
public Antlr4.Runtime.RuleContext parent;
|
||||||
|
@ -165,7 +165,7 @@ namespace Antlr4.Runtime
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual ParseTree GetChild(int i)
|
public virtual IParseTree GetChild(int i)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ namespace Antlr4.Runtime
|
||||||
return 0;
|
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);
|
return visitor.VisitChildren(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,10 +136,10 @@ namespace Antlr4.Runtime
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the
|
/// Gets the
|
||||||
/// <see cref="TokenSource">TokenSource</see>
|
/// <see cref="ITokenSource">ITokenSource</see>
|
||||||
/// which created this token.
|
/// which created this token.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract TokenSource GetTokenSource();
|
public abstract ITokenSource GetTokenSource();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the
|
/// Gets the
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace Antlr4.Runtime
|
||||||
/// are wiped to -1 in the text override is set in the CommonToken.
|
/// are wiped to -1 in the text override is set in the CommonToken.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
Token Create<_T0>(Tuple<_T0> source, int type, string text, int channel, int start
|
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>
|
/// <summary>Generically useful</summary>
|
||||||
Token Create(int type, string text);
|
Token Create(int type, string text);
|
||||||
|
|
|
@ -88,9 +88,9 @@ namespace Antlr4.Runtime
|
||||||
|
|
||||||
/// <summary>Gets the factory used for constructing tokens.</summary>
|
/// <summary>Gets the factory used for constructing tokens.</summary>
|
||||||
/// <remarks>Gets the factory used for constructing tokens.</remarks>
|
/// <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>
|
/// <summary>Optional method that lets users set factory in lexer or other source</summary>
|
||||||
void SetTokenFactory(TokenFactory factory);
|
void SetTokenFactory(ITokenFactory factory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,12 +100,12 @@ namespace Antlr4.Runtime
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the underlying
|
/// Gets the underlying
|
||||||
/// <see cref="TokenSource">TokenSource</see>
|
/// <see cref="ITokenSource">ITokenSource</see>
|
||||||
/// which provides tokens for this
|
/// which provides tokens for this
|
||||||
/// stream.
|
/// stream.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NotNull]
|
[NotNull]
|
||||||
TokenSource GetTokenSource();
|
ITokenSource GetTokenSource();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the text of all tokens within the specified
|
/// Return the text of all tokens within the specified
|
||||||
|
|
|
@ -102,7 +102,7 @@ namespace Antlr4.Runtime
|
||||||
|
|
||||||
public class RewriteOperation
|
public class RewriteOperation
|
||||||
{
|
{
|
||||||
protected internal readonly TokenStream tokens;
|
protected internal readonly ITokenStream tokens;
|
||||||
|
|
||||||
/// <summary>What index into rewrites List are we?</summary>
|
/// <summary>What index into rewrites List are we?</summary>
|
||||||
protected internal int instructionIndex;
|
protected internal int instructionIndex;
|
||||||
|
@ -113,14 +113,14 @@ namespace Antlr4.Runtime
|
||||||
|
|
||||||
protected internal object text;
|
protected internal object text;
|
||||||
|
|
||||||
protected internal RewriteOperation(TokenStream tokens, int index)
|
protected internal RewriteOperation(ITokenStream tokens, int index)
|
||||||
{
|
{
|
||||||
// Define the rewrite operation hierarchy
|
// Define the rewrite operation hierarchy
|
||||||
this.tokens = tokens;
|
this.tokens = tokens;
|
||||||
this.index = index;
|
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.tokens = tokens;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
|
@ -148,8 +148,8 @@ namespace Antlr4.Runtime
|
||||||
|
|
||||||
internal class InsertBeforeOp : TokenStreamRewriter.RewriteOperation
|
internal class InsertBeforeOp : TokenStreamRewriter.RewriteOperation
|
||||||
{
|
{
|
||||||
protected internal InsertBeforeOp(TokenStream tokens, int index, object text) : base
|
protected internal InsertBeforeOp(ITokenStream tokens, int index, object text) :
|
||||||
(tokens, index, text)
|
base(tokens, index, text)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
protected internal int lastIndex;
|
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)
|
, from, text)
|
||||||
{
|
{
|
||||||
lastIndex = to;
|
lastIndex = to;
|
||||||
|
@ -203,7 +203,7 @@ namespace Antlr4.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Our source stream</summary>
|
/// <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>
|
/// <summary>You may have multiple, named streams of rewrite operations.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
@ -217,7 +217,7 @@ namespace Antlr4.Runtime
|
||||||
/// <summary>Map String (program name) -> Integer index</summary>
|
/// <summary>Map String (program name) -> Integer index</summary>
|
||||||
protected internal readonly IDictionary<string, int> lastRewriteTokenIndexes;
|
protected internal readonly IDictionary<string, int> lastRewriteTokenIndexes;
|
||||||
|
|
||||||
public TokenStreamRewriter(TokenStream tokens)
|
public TokenStreamRewriter(ITokenStream tokens)
|
||||||
{
|
{
|
||||||
this.tokens = tokens;
|
this.tokens = tokens;
|
||||||
programs = new Dictionary<string, IList<TokenStreamRewriter.RewriteOperation>>();
|
programs = new Dictionary<string, IList<TokenStreamRewriter.RewriteOperation>>();
|
||||||
|
@ -226,7 +226,7 @@ namespace Antlr4.Runtime
|
||||||
lastRewriteTokenIndexes = new Dictionary<string, int>();
|
lastRewriteTokenIndexes = new Dictionary<string, int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TokenStream GetTokenStream()
|
public ITokenStream GetTokenStream()
|
||||||
{
|
{
|
||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,18 +32,19 @@ using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime.Tree
|
namespace Antlr4.Runtime.Tree
|
||||||
{
|
{
|
||||||
public abstract class AbstractParseTreeVisitor<Result> : ParseTreeVisitor<Result>
|
public abstract class AbstractParseTreeVisitor<Result> : IParseTreeVisitor<Result
|
||||||
|
>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <inheritDoc></inheritDoc>
|
/// <inheritDoc></inheritDoc>
|
||||||
/// <p/>
|
/// <p/>
|
||||||
/// The default implementation calls
|
/// The default implementation calls
|
||||||
/// <see cref="ParseTree.Accept{T}(ParseTreeVisitor{Result})">ParseTree.Accept<T>(ParseTreeVisitor<Result>)
|
/// <see cref="IParseTree.Accept{T}(IParseTreeVisitor{Result})">IParseTree.Accept<T>(IParseTreeVisitor<Result>)
|
||||||
/// </see>
|
/// </see>
|
||||||
/// on the
|
/// on the
|
||||||
/// specified tree.
|
/// specified tree.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Result Visit(ParseTree tree)
|
public virtual Result Visit(IParseTree tree)
|
||||||
{
|
{
|
||||||
return tree.Accept(this);
|
return tree.Accept(this);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.DefaultResult()">defaultResult()</see>
|
/// <see cref="AbstractParseTreeVisitor{Result}.DefaultResult()">defaultResult()</see>
|
||||||
/// . Before visiting each child, it
|
/// . Before visiting each child, it
|
||||||
/// calls
|
/// calls
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.ShouldVisitNextChild(RuleNode, object)
|
/// <see cref="AbstractParseTreeVisitor{Result}.ShouldVisitNextChild(IRuleNode, object)
|
||||||
/// ">shouldVisitNextChild</see>
|
/// ">shouldVisitNextChild</see>
|
||||||
/// ; if the result
|
/// ; if the result
|
||||||
/// is
|
/// is
|
||||||
|
@ -68,7 +69,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// with the
|
/// with the
|
||||||
/// previous aggregate result and the result of visiting the child.
|
/// previous aggregate result and the result of visiting the child.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Result VisitChildren(RuleNode node)
|
public virtual Result VisitChildren(IRuleNode node)
|
||||||
{
|
{
|
||||||
Result result = DefaultResult();
|
Result result = DefaultResult();
|
||||||
int n = node.GetChildCount();
|
int n = node.GetChildCount();
|
||||||
|
@ -78,7 +79,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ParseTree c = node.GetChild(i);
|
IParseTree c = node.GetChild(i);
|
||||||
Result childResult = c.Accept(this);
|
Result childResult = c.Accept(this);
|
||||||
result = AggregateResult(result, childResult);
|
result = AggregateResult(result, childResult);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +93,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.DefaultResult()">defaultResult</see>
|
/// <see cref="AbstractParseTreeVisitor{Result}.DefaultResult()">defaultResult</see>
|
||||||
/// .
|
/// .
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Result VisitTerminal(TerminalNode node)
|
public virtual Result VisitTerminal(ITerminalNode node)
|
||||||
{
|
{
|
||||||
return DefaultResult();
|
return DefaultResult();
|
||||||
}
|
}
|
||||||
|
@ -104,7 +105,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.DefaultResult()">defaultResult</see>
|
/// <see cref="AbstractParseTreeVisitor{Result}.DefaultResult()">defaultResult</see>
|
||||||
/// .
|
/// .
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual Result VisitErrorNode(ErrorNode node)
|
public virtual Result VisitErrorNode(IErrorNode node)
|
||||||
{
|
{
|
||||||
return DefaultResult();
|
return DefaultResult();
|
||||||
}
|
}
|
||||||
|
@ -113,14 +114,14 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Gets the default value returned by visitor methods. This value is
|
/// Gets the default value returned by visitor methods. This value is
|
||||||
/// returned by the default implementations of
|
/// returned by the default implementations of
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.VisitTerminal(TerminalNode)">visitTerminal
|
/// <see cref="AbstractParseTreeVisitor{Result}.VisitTerminal(ITerminalNode)">visitTerminal
|
||||||
/// </see>
|
/// </see>
|
||||||
/// ,
|
/// ,
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.VisitErrorNode(ErrorNode)">visitErrorNode
|
/// <see cref="AbstractParseTreeVisitor{Result}.VisitErrorNode(IErrorNode)">visitErrorNode
|
||||||
/// </see>
|
/// </see>
|
||||||
/// .
|
/// .
|
||||||
/// The default implementation of
|
/// The default implementation of
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(RuleNode)">visitChildren
|
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)">visitChildren
|
||||||
/// </see>
|
/// </see>
|
||||||
/// initializes its aggregate result to this value.
|
/// initializes its aggregate result to this value.
|
||||||
/// <p/>
|
/// <p/>
|
||||||
|
@ -138,19 +139,20 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Aggregates the results of visiting multiple children of a node. After
|
/// Aggregates the results of visiting multiple children of a node. After
|
||||||
/// either all children are visited or
|
/// either all children are visited or
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.ShouldVisitNextChild(RuleNode, object)
|
/// <see cref="AbstractParseTreeVisitor{Result}.ShouldVisitNextChild(IRuleNode, object)
|
||||||
/// ">AbstractParseTreeVisitor<Result>.ShouldVisitNextChild(RuleNode, object)</see>
|
/// ">AbstractParseTreeVisitor<Result>.ShouldVisitNextChild(IRuleNode, object)
|
||||||
|
/// </see>
|
||||||
/// returns
|
/// returns
|
||||||
/// <code>false</code>
|
/// <code>false</code>
|
||||||
/// , the aggregate value is returned as the result of
|
/// , the aggregate value is returned as the result of
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(RuleNode)">AbstractParseTreeVisitor<Result>.VisitChildren(RuleNode)
|
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)">AbstractParseTreeVisitor<Result>.VisitChildren(IRuleNode)
|
||||||
/// </see>
|
/// </see>
|
||||||
/// .
|
/// .
|
||||||
/// <p/>
|
/// <p/>
|
||||||
/// The default implementation returns
|
/// The default implementation returns
|
||||||
/// <code>nextResult</code>
|
/// <code>nextResult</code>
|
||||||
/// , meaning
|
/// , meaning
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(RuleNode)">AbstractParseTreeVisitor<Result>.VisitChildren(RuleNode)
|
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)">AbstractParseTreeVisitor<Result>.VisitChildren(IRuleNode)
|
||||||
/// </see>
|
/// </see>
|
||||||
/// will return the result of the last child visited
|
/// will return the result of the last child visited
|
||||||
/// (or return the initial value if the node has no children).
|
/// (or return the initial value if the node has no children).
|
||||||
|
@ -178,7 +180,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method is called after visiting each child in
|
/// This method is called after visiting each child in
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(RuleNode)">AbstractParseTreeVisitor<Result>.VisitChildren(RuleNode)
|
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)">AbstractParseTreeVisitor<Result>.VisitChildren(IRuleNode)
|
||||||
/// </see>
|
/// </see>
|
||||||
/// . This method is first called before the first
|
/// . This method is first called before the first
|
||||||
/// child is visited; at that point
|
/// child is visited; at that point
|
||||||
|
@ -203,7 +205,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="node">
|
/// <param name="node">
|
||||||
/// The
|
/// The
|
||||||
/// <see cref="RuleNode">RuleNode</see>
|
/// <see cref="IRuleNode">IRuleNode</see>
|
||||||
/// whose children are currently being
|
/// whose children are currently being
|
||||||
/// visited.
|
/// visited.
|
||||||
/// </param>
|
/// </param>
|
||||||
|
@ -218,11 +220,11 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <code>false</code>
|
/// <code>false</code>
|
||||||
/// to stop visiting children and immediately return the
|
/// to stop visiting children and immediately return the
|
||||||
/// current aggregate result from
|
/// current aggregate result from
|
||||||
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(RuleNode)">AbstractParseTreeVisitor<Result>.VisitChildren(RuleNode)
|
/// <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)">AbstractParseTreeVisitor<Result>.VisitChildren(IRuleNode)
|
||||||
/// </see>
|
/// </see>
|
||||||
/// .
|
/// .
|
||||||
/// </returns>
|
/// </returns>
|
||||||
protected internal virtual bool ShouldVisitNextChild(RuleNode node, Result currentResult
|
protected internal virtual bool ShouldVisitNextChild(IRuleNode node, Result currentResult
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -27,12 +27,11 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
using Antlr4.Runtime.Tree;
|
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime.Tree
|
namespace Antlr4.Runtime.Tree
|
||||||
{
|
{
|
||||||
public interface ErrorNode : TerminalNode
|
public interface ErrorNode : ITerminalNode
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,13 +44,13 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// and deletion as well as during "consume until error recovery set"
|
/// and deletion as well as during "consume until error recovery set"
|
||||||
/// upon no viable alternative exceptions.
|
/// upon no viable alternative exceptions.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class ErrorNodeImpl : TerminalNodeImpl, ErrorNode
|
public class ErrorNodeImpl : TerminalNodeImpl, IErrorNode
|
||||||
{
|
{
|
||||||
public ErrorNodeImpl(Token token) : base(token)
|
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);
|
return visitor.VisitErrorNode(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
using Antlr4.Runtime;
|
using Antlr4.Runtime;
|
||||||
using Antlr4.Runtime.Tree;
|
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime.Tree
|
namespace Antlr4.Runtime.Tree
|
||||||
|
@ -47,19 +46,19 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <see cref="Antlr4.Runtime.RuleContext">Antlr4.Runtime.RuleContext</see>
|
/// <see cref="Antlr4.Runtime.RuleContext">Antlr4.Runtime.RuleContext</see>
|
||||||
/// object.
|
/// object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ParseTree : SyntaxTree
|
public interface ParseTree : ISyntaxTree
|
||||||
{
|
{
|
||||||
// the following methods narrow the return type; they are not additional methods
|
// 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>
|
/// <summary>
|
||||||
/// The
|
/// The
|
||||||
/// <see cref="ParseTreeVisitor{Result}">ParseTreeVisitor<Result></see>
|
/// <see cref="ParseTreeVisitor{Result}">ParseTreeVisitor<Result></see>
|
||||||
/// needs a double dispatch method.
|
/// needs a double dispatch method.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>Return the combined text of all leaf nodes.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
|
|
@ -28,16 +28,15 @@
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
using Antlr4.Runtime;
|
using Antlr4.Runtime;
|
||||||
using Antlr4.Runtime.Tree;
|
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime.Tree
|
namespace Antlr4.Runtime.Tree
|
||||||
{
|
{
|
||||||
public interface ParseTreeListener
|
public interface ParseTreeListener
|
||||||
{
|
{
|
||||||
void VisitTerminal(TerminalNode node);
|
void VisitTerminal(ITerminalNode node);
|
||||||
|
|
||||||
void VisitErrorNode(ErrorNode node);
|
void VisitErrorNode(IErrorNode node);
|
||||||
|
|
||||||
void EnterEveryRule(ParserRuleContext ctx);
|
void EnterEveryRule(ParserRuleContext ctx);
|
||||||
|
|
||||||
|
|
|
@ -50,20 +50,20 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class ParseTreeProperty<V>
|
public class ParseTreeProperty<V>
|
||||||
{
|
{
|
||||||
protected internal IDictionary<ParseTree, V> annotations = new IdentityHashMap<ParseTree
|
protected internal IDictionary<IParseTree, V> annotations = new IdentityHashMap<IParseTree
|
||||||
, V>();
|
, V>();
|
||||||
|
|
||||||
public virtual V Get(ParseTree node)
|
public virtual V Get(IParseTree node)
|
||||||
{
|
{
|
||||||
return annotations.Get(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);
|
annotations.Put(node, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual V RemoveFrom(ParseTree node)
|
public virtual V RemoveFrom(IParseTree node)
|
||||||
{
|
{
|
||||||
return Sharpen.Collections.Remove(annotations, node);
|
return Sharpen.Collections.Remove(annotations, node);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
using Antlr4.Runtime.Tree;
|
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime.Tree
|
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>
|
/// <remarks>Visit a parse tree, and return a user-defined result of the operation.</remarks>
|
||||||
/// <param name="tree">
|
/// <param name="tree">
|
||||||
/// The
|
/// The
|
||||||
/// <see cref="ParseTree">ParseTree</see>
|
/// <see cref="IParseTree">IParseTree</see>
|
||||||
/// to visit.
|
/// to visit.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>The result of visiting the parse tree.</returns>
|
/// <returns>The result of visiting the parse tree.</returns>
|
||||||
Result Visit(ParseTree tree);
|
Result Visit(IParseTree tree);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Visit the children of a node, and return a user-defined result
|
/// Visit the children of a node, and return a user-defined result
|
||||||
|
@ -66,11 +65,11 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="node">
|
/// <param name="node">
|
||||||
/// The
|
/// The
|
||||||
/// <see cref="RuleNode">RuleNode</see>
|
/// <see cref="IRuleNode">IRuleNode</see>
|
||||||
/// whose children should be visited.
|
/// whose children should be visited.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>The result of visiting the children of the node.</returns>
|
/// <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>Visit a terminal node, and return a user-defined result of the operation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -78,20 +77,20 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="node">
|
/// <param name="node">
|
||||||
/// The
|
/// The
|
||||||
/// <see cref="TerminalNode">TerminalNode</see>
|
/// <see cref="ITerminalNode">ITerminalNode</see>
|
||||||
/// to visit.
|
/// to visit.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>The result of visiting the node.</returns>
|
/// <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>
|
/// <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>
|
/// <remarks>Visit an error node, and return a user-defined result of the operation.</remarks>
|
||||||
/// <param name="node">
|
/// <param name="node">
|
||||||
/// The
|
/// The
|
||||||
/// <see cref="ErrorNode">ErrorNode</see>
|
/// <see cref="IErrorNode">IErrorNode</see>
|
||||||
/// to visit.
|
/// to visit.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>The result of visiting the node.</returns>
|
/// <returns>The result of visiting the node.</returns>
|
||||||
Result VisitErrorNode(ErrorNode node);
|
Result VisitErrorNode(IErrorNode node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,22 +37,22 @@ namespace Antlr4.Runtime.Tree
|
||||||
{
|
{
|
||||||
public static readonly ParseTreeWalker Default = new ParseTreeWalker();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (t is TerminalNode)
|
if (t is ITerminalNode)
|
||||||
{
|
{
|
||||||
listener.VisitTerminal((TerminalNode)t);
|
listener.VisitTerminal((ITerminalNode)t);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RuleNode r = (RuleNode)t;
|
IRuleNode r = (IRuleNode)t;
|
||||||
EnterRule(listener, r);
|
EnterRule(listener, r);
|
||||||
int n = r.GetChildCount();
|
int n = r.GetChildCount();
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
|
@ -64,21 +64,23 @@ namespace Antlr4.Runtime.Tree
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The discovery of a rule node, involves sending two events: the generic
|
/// 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>
|
/// </see>
|
||||||
/// and a
|
/// and a
|
||||||
/// <see cref="Antlr4.Runtime.RuleContext">Antlr4.Runtime.RuleContext</see>
|
/// <see cref="Antlr4.Runtime.RuleContext">Antlr4.Runtime.RuleContext</see>
|
||||||
/// -specific event. First we trigger the generic and then
|
/// -specific event. First we trigger the generic and then
|
||||||
/// the rule specific. We to them in reverse order upon finishing the node.
|
/// the rule specific. We to them in reverse order upon finishing the node.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected internal virtual void EnterRule(ParseTreeListener listener, RuleNode r)
|
protected internal virtual void EnterRule(IParseTreeListener listener, IRuleNode
|
||||||
|
r)
|
||||||
{
|
{
|
||||||
ParserRuleContext ctx = (ParserRuleContext)r.GetRuleContext();
|
ParserRuleContext ctx = (ParserRuleContext)r.GetRuleContext();
|
||||||
listener.EnterEveryRule(ctx);
|
listener.EnterEveryRule(ctx);
|
||||||
ctx.EnterRule(listener);
|
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();
|
ParserRuleContext ctx = (ParserRuleContext)r.GetRuleContext();
|
||||||
ctx.ExitRule(listener);
|
ctx.ExitRule(listener);
|
||||||
|
|
|
@ -28,15 +28,14 @@
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
using Antlr4.Runtime;
|
using Antlr4.Runtime;
|
||||||
using Antlr4.Runtime.Tree;
|
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime.Tree
|
namespace Antlr4.Runtime.Tree
|
||||||
{
|
{
|
||||||
public interface RuleNode : ParseTree
|
public interface RuleNode : IParseTree
|
||||||
{
|
{
|
||||||
RuleContext GetRuleContext();
|
RuleContext GetRuleContext();
|
||||||
|
|
||||||
RuleNode GetParent();
|
IRuleNode GetParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
using Antlr4.Runtime.Misc;
|
using Antlr4.Runtime.Misc;
|
||||||
using Antlr4.Runtime.Tree;
|
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime.Tree
|
namespace Antlr4.Runtime.Tree
|
||||||
|
@ -42,13 +41,13 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// is some kind of syntax tree. Subinterfaces distinguish
|
/// is some kind of syntax tree. Subinterfaces distinguish
|
||||||
/// between parse trees and other kinds of syntax trees we might want to create.
|
/// between parse trees and other kinds of syntax trees we might want to create.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public interface SyntaxTree : Antlr4.Runtime.Tree.Tree
|
public interface SyntaxTree : ITree
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return an
|
/// Return an
|
||||||
/// <see cref="Antlr4.Runtime.Misc.Interval">Antlr4.Runtime.Misc.Interval</see>
|
/// <see cref="Antlr4.Runtime.Misc.Interval">Antlr4.Runtime.Misc.Interval</see>
|
||||||
/// indicating the index in the
|
/// 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
|
/// of the first and last token associated with this
|
||||||
/// subtree. If this node is a leaf, then the interval represents a single
|
/// subtree. If this node is a leaf, then the interval represents a single
|
||||||
/// token.
|
/// token.
|
||||||
|
|
|
@ -28,15 +28,14 @@
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
using Antlr4.Runtime;
|
using Antlr4.Runtime;
|
||||||
using Antlr4.Runtime.Tree;
|
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime.Tree
|
namespace Antlr4.Runtime.Tree
|
||||||
{
|
{
|
||||||
public interface TerminalNode : ParseTree
|
public interface TerminalNode : IParseTree
|
||||||
{
|
{
|
||||||
Token GetSymbol();
|
Token GetSymbol();
|
||||||
|
|
||||||
RuleNode GetParent();
|
IRuleNode GetParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,23 +29,22 @@
|
||||||
*/
|
*/
|
||||||
using Antlr4.Runtime;
|
using Antlr4.Runtime;
|
||||||
using Antlr4.Runtime.Misc;
|
using Antlr4.Runtime.Misc;
|
||||||
using Antlr4.Runtime.Tree;
|
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime.Tree
|
namespace Antlr4.Runtime.Tree
|
||||||
{
|
{
|
||||||
public class TerminalNodeImpl : TerminalNode
|
public class TerminalNodeImpl : ITerminalNode
|
||||||
{
|
{
|
||||||
public Token symbol;
|
public Token symbol;
|
||||||
|
|
||||||
public RuleNode parent;
|
public IRuleNode parent;
|
||||||
|
|
||||||
public TerminalNodeImpl(Token symbol)
|
public TerminalNodeImpl(Token symbol)
|
||||||
{
|
{
|
||||||
this.symbol = symbol;
|
this.symbol = symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual ParseTree GetChild(int i)
|
public virtual IParseTree GetChild(int i)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +54,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual RuleNode GetParent()
|
public virtual IRuleNode GetParent()
|
||||||
{
|
{
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +79,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
return 0;
|
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);
|
return visitor.VisitTerminal(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// The parent of this node. If the return value is null, then this
|
/// The parent of this node. If the return value is null, then this
|
||||||
/// node is the root of the tree.
|
/// node is the root of the tree.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
Antlr4.Runtime.Tree.Tree GetParent();
|
ITree GetParent();
|
||||||
|
|
||||||
/// <summary>This method returns whatever object represents the data at this note.</summary>
|
/// <summary>This method returns whatever object represents the data at this note.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
@ -66,7 +66,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <code>i</code>
|
/// <code>i</code>
|
||||||
/// th value indexed from 0.
|
/// th value indexed from 0.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Antlr4.Runtime.Tree.Tree GetChild(int i);
|
ITree GetChild(int i);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How many children are there? If there is none, then this
|
/// How many children are there? If there is none, then this
|
||||||
|
|
|
@ -32,7 +32,6 @@ using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Antlr4.Runtime;
|
using Antlr4.Runtime;
|
||||||
using Antlr4.Runtime.Misc;
|
using Antlr4.Runtime.Misc;
|
||||||
using Antlr4.Runtime.Tree;
|
|
||||||
using Antlr4.Runtime.Tree.Gui;
|
using Antlr4.Runtime.Tree.Gui;
|
||||||
using Sharpen;
|
using Sharpen;
|
||||||
|
|
||||||
|
@ -42,22 +41,22 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <remarks>A set of utility routines useful for all kinds of ANTLR trees.</remarks>
|
/// <remarks>A set of utility routines useful for all kinds of ANTLR trees.</remarks>
|
||||||
public class Trees
|
public class Trees
|
||||||
{
|
{
|
||||||
public static string GetPS(Antlr4.Runtime.Tree.Tree t, IList<string> ruleNames, string
|
public static string GetPS(ITree t, IList<string> ruleNames, string fontName, int
|
||||||
fontName, int fontSize)
|
fontSize)
|
||||||
{
|
{
|
||||||
TreePostScriptGenerator psgen = new TreePostScriptGenerator(ruleNames, t, fontName
|
TreePostScriptGenerator psgen = new TreePostScriptGenerator(ruleNames, t, fontName
|
||||||
, fontSize);
|
, fontSize);
|
||||||
return psgen.GetPS();
|
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);
|
return GetPS(t, ruleNames, "Helvetica", 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="System.IO.IOException"></exception>
|
/// <exception cref="System.IO.IOException"></exception>
|
||||||
public static void WritePS(Antlr4.Runtime.Tree.Tree t, IList<string> ruleNames, string
|
public static void WritePS(ITree t, IList<string> ruleNames, string fileName, string
|
||||||
fileName, string fontName, int fontSize)
|
fontName, int fontSize)
|
||||||
{
|
{
|
||||||
string ps = GetPS(t, ruleNames, fontName, fontSize);
|
string ps = GetPS(t, ruleNames, fontName, fontSize);
|
||||||
FileWriter f = new FileWriter(fileName);
|
FileWriter f = new FileWriter(fileName);
|
||||||
|
@ -67,8 +66,7 @@ namespace Antlr4.Runtime.Tree
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <exception cref="System.IO.IOException"></exception>
|
/// <exception cref="System.IO.IOException"></exception>
|
||||||
public static void WritePS(Antlr4.Runtime.Tree.Tree t, IList<string> ruleNames, string
|
public static void WritePS(ITree t, IList<string> ruleNames, string fileName)
|
||||||
fileName)
|
|
||||||
{
|
{
|
||||||
WritePS(t, ruleNames, fileName, "Helvetica", 11);
|
WritePS(t, ruleNames, fileName, "Helvetica", 11);
|
||||||
}
|
}
|
||||||
|
@ -76,13 +74,13 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <summary>Print out a whole tree in LISP form.</summary>
|
/// <summary>Print out a whole tree in LISP form.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Print out a whole tree in LISP form.
|
/// 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>
|
/// </see>
|
||||||
/// is used on the
|
/// is used on the
|
||||||
/// node payloads to get the text for the nodes. Detect
|
/// node payloads to get the text for the nodes. Detect
|
||||||
/// parse trees and extract data appropriately.
|
/// parse trees and extract data appropriately.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static string ToStringTree(Antlr4.Runtime.Tree.Tree t)
|
public static string ToStringTree(ITree t)
|
||||||
{
|
{
|
||||||
return ToStringTree(t, (IList<string>)null);
|
return ToStringTree(t, (IList<string>)null);
|
||||||
}
|
}
|
||||||
|
@ -90,13 +88,13 @@ namespace Antlr4.Runtime.Tree
|
||||||
/// <summary>Print out a whole tree in LISP form.</summary>
|
/// <summary>Print out a whole tree in LISP form.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Print out a whole tree in LISP form.
|
/// 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>
|
/// </see>
|
||||||
/// is used on the
|
/// is used on the
|
||||||
/// node payloads to get the text for the nodes. Detect
|
/// node payloads to get the text for the nodes. Detect
|
||||||
/// parse trees and extract data appropriately.
|
/// parse trees and extract data appropriately.
|
||||||
/// </remarks>
|
/// </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;
|
string[] ruleNames = recog != null ? recog.GetRuleNames() : null;
|
||||||
IList<string> ruleNamesList = ruleNames != null ? Arrays.AsList(ruleNames) : 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>
|
/// <summary>Print out a whole tree in LISP form.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Print out a whole tree in LISP form.
|
/// 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>
|
/// </see>
|
||||||
/// is used on the
|
/// is used on the
|
||||||
/// node payloads to get the text for the nodes. Detect
|
/// node payloads to get the text for the nodes. Detect
|
||||||
/// parse trees and extract data appropriately.
|
/// parse trees and extract data appropriately.
|
||||||
/// </remarks>
|
/// </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);
|
string s = Utils.EscapeWhitespace(GetNodeText(t, ruleNames), false);
|
||||||
if (t.GetChildCount() == 0)
|
if (t.GetChildCount() == 0)
|
||||||
|
@ -137,35 +134,34 @@ namespace Antlr4.Runtime.Tree
|
||||||
return buf.ToString();
|
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;
|
string[] ruleNames = recog != null ? recog.GetRuleNames() : null;
|
||||||
IList<string> ruleNamesList = ruleNames != null ? Arrays.AsList(ruleNames) : null;
|
IList<string> ruleNamesList = ruleNames != null ? Arrays.AsList(ruleNames) : null;
|
||||||
return GetNodeText(t, ruleNamesList);
|
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 (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];
|
string ruleName = ruleNames[ruleIndex];
|
||||||
return ruleName;
|
return ruleName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (t is ErrorNode)
|
if (t is IErrorNode)
|
||||||
{
|
{
|
||||||
return t.ToString();
|
return t.ToString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (t is TerminalNode)
|
if (t is ITerminalNode)
|
||||||
{
|
{
|
||||||
object symbol = ((TerminalNode)t).GetSymbol();
|
object symbol = ((ITerminalNode)t).GetSymbol();
|
||||||
if (symbol is Token)
|
if (symbol is Token)
|
||||||
{
|
{
|
||||||
string s = ((Token)symbol).GetText();
|
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.
|
/// list is the root and the last is the parent of this node.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public static IList<Antlr4.Runtime.Tree.Tree> GetAncestors(Antlr4.Runtime.Tree.Tree
|
public static IList<ITree> GetAncestors(ITree t)
|
||||||
t)
|
|
||||||
{
|
{
|
||||||
if (t.GetParent() == null)
|
if (t.GetParent() == null)
|
||||||
{
|
{
|
||||||
return Sharpen.Collections.EmptyList();
|
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();
|
t = t.GetParent();
|
||||||
while (t != null)
|
while (t != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,9 +35,9 @@ using Sharpen;
|
||||||
|
|
||||||
namespace Antlr4.Runtime
|
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>
|
/// <summary>A moving window buffer of the data being scanned.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
@ -123,16 +123,16 @@ namespace Antlr4.Runtime
|
||||||
/// <p/>
|
/// <p/>
|
||||||
/// This value is used to set the token indexes if the stream provides tokens
|
/// This value is used to set the token indexes if the stream provides tokens
|
||||||
/// that implement
|
/// that implement
|
||||||
/// <see cref="WritableToken">WritableToken</see>
|
/// <see cref="IWritableToken">IWritableToken</see>
|
||||||
/// .
|
/// .
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected internal int currentTokenIndex = 0;
|
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;
|
this.tokenSource = tokenSource;
|
||||||
Token[] tokens = new Token[bufferSize];
|
Token[] tokens = new Token[bufferSize];
|
||||||
|
@ -178,7 +178,7 @@ namespace Antlr4.Runtime
|
||||||
return Lt(i).GetType();
|
return Lt(i).GetType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual TokenSource GetTokenSource()
|
public virtual ITokenSource GetTokenSource()
|
||||||
{
|
{
|
||||||
return tokenSource;
|
return tokenSource;
|
||||||
}
|
}
|
||||||
|
@ -285,9 +285,9 @@ namespace Antlr4.Runtime
|
||||||
{
|
{
|
||||||
tokens = Arrays.CopyOf(tokens, tokens.Length * 2);
|
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;
|
tokens[n++] = t;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,3 +183,23 @@
|
||||||
-typeMapping org.antlr.v4.runtime.misc.Tuple2<,> System.Tuple
|
-typeMapping org.antlr.v4.runtime.misc.Tuple2<,> System.Tuple
|
||||||
-typeMapping org.antlr.v4.runtime.misc.Tuple3<,,> 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
|
||||||
|
|
Loading…
Reference in New Issue