forked from jasder/antlr
Merge pull request #2934 from Marti2203/master
Made C# Trace Listener usable for most cases
This commit is contained in:
commit
79808cdcbd
|
@ -258,3 +258,4 @@ YYYY/MM/DD, github id, Full name, email
|
|||
2020/09/06, ArthurSonzogni, Sonzogni Arthur, arthursonzogni@gmail.com
|
||||
2020/09/12, Clcanny, Charles Ruan, a837940593@gmail.com
|
||||
2020/09/15, rmcgregor1990, Robert McGregor, rmcgregor1990@gmail.com
|
||||
2020/10/08, Marti2203, Martin Mirchev, mirchevmartin2203@gmail.com
|
||||
|
|
|
@ -22,20 +22,20 @@ namespace Antlr4.Runtime
|
|||
#if !PORTABLE
|
||||
public class TraceListener : IParseTreeListener
|
||||
{
|
||||
private readonly TextWriter Output;
|
||||
|
||||
public TraceListener(TextWriter output) {
|
||||
Output = output;
|
||||
public TraceListener(TextWriter output,Parser enclosing) {
|
||||
_output = output;
|
||||
_enclosing = enclosing;
|
||||
}
|
||||
|
||||
public virtual void EnterEveryRule(ParserRuleContext ctx)
|
||||
{
|
||||
Output.WriteLine("enter " + this._enclosing.RuleNames[ctx.RuleIndex] + ", LT(1)=" + this._enclosing._input.LT(1).Text);
|
||||
_output.WriteLine("enter " + this._enclosing.RuleNames[ctx.RuleIndex] + ", LT(1)=" + this._enclosing._input.LT(1).Text);
|
||||
}
|
||||
|
||||
public virtual void ExitEveryRule(ParserRuleContext ctx)
|
||||
{
|
||||
Output.WriteLine("exit " + this._enclosing.RuleNames[ctx.RuleIndex] + ", LT(1)=" + this._enclosing._input.LT(1).Text);
|
||||
_output.WriteLine("exit " + this._enclosing.RuleNames[ctx.RuleIndex] + ", LT(1)=" + this._enclosing._input.LT(1).Text);
|
||||
}
|
||||
|
||||
public virtual void VisitErrorNode(IErrorNode node)
|
||||
|
@ -46,15 +46,17 @@ namespace Antlr4.Runtime
|
|||
{
|
||||
ParserRuleContext parent = (ParserRuleContext)((IRuleNode)node.Parent).RuleContext;
|
||||
IToken token = node.Symbol;
|
||||
Output.WriteLine("consume " + token + " rule " + this._enclosing.RuleNames[parent.RuleIndex]);
|
||||
_output.WriteLine("consume " + token + " rule " + this._enclosing.RuleNames[parent.RuleIndex]);
|
||||
}
|
||||
|
||||
internal TraceListener(Parser _enclosing)
|
||||
{
|
||||
this._enclosing = _enclosing;
|
||||
_output = Console.Out;
|
||||
}
|
||||
|
||||
private readonly Parser _enclosing;
|
||||
private readonly TextWriter _output;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue