parser.Trace not working

37 views
Skip to first unread message

edgar hoover

unread,
Oct 7, 2020, 10:04:35 AM10/7/20
to antlr-discussion
Hi all,
I've hit some odd behaviour that may be a bug somewhere in antlr (or may be me).

To try to track it down I tried using the trace thingy

...
var tokens = new CommonTokenStream(lexer);
var parser = new LDBParser(tokens);
parser
.Trace = true;    <------------- added this
var listener = new ErrorListener<IToken>(parser, lexer, tokens);
...

But when run this gives

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Antlr4.Runtime.Standard
  StackTrace:
   at Antlr4.Runtime.Parser.TraceListener.EnterEveryRule(ParserRuleContext ctx)
   at Antlr4.Runtime.Parser.TriggerEnterRuleEvent()
   at Antlr4.Runtime.Parser.EnterRule(ParserRuleContext localctx, Int32 state, Int32 ruleIndex)
   at LDB.LDBParser.start_parse() in [full path snipped]\LDB\obj\Debug\netcoreapp3.1\LDBParser.cs:line 1370

Is this an antlr problem or do I need to set some extra configs or something?

thanks

jan

Martin Mirchev

unread,
Oct 7, 2020, 10:10:35 AM10/7/20
to antlr-discussion
Yep, already filled an issue in Github. You are gonna have to use reflection to fix the tracer.

edgar hoover

unread,
Oct 8, 2020, 4:58:30 AM10/8/20
to antlr-discussion
Hi, per my other question which turns out to be me not antlr (well surprise),
I've no idea on what you mean by using reflection to fix it, can you post a few links please?

thanks

jan

Martin Mirchev

unread,
Oct 8, 2020, 5:09:33 AM10/8/20
to 'edgar hoover' via antlr-discussion

When you set .trace to true , the tracing listener it has does not have a stream set, so it throws a null pointer exception. If you put your own Trace Listener, which you construct from the consturctor, it does not have a reference to a parser. Link to faulty code. You will have to set the private field _enclosing (when you create a TraceListener) or Output,(if you use the original tracer).

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/antlr-discussion/2a0c2124-ead3-4167-9781-67921a18d779o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages