From: Ryan Davis Date: 2011-02-17T06:37:53+09:00 Subject: Re: Treetop - parsing to nil result On Feb 16, 2011, at 13:13 , Christopher Rose wrote: > irb(main):178:0> pA = VHDLParser.new > => # > > irb(main):188:0> resA = pA.parse(exA) > => nil > > irb(main):189:0> resA.failure_reason > NoMethodError: undefined method `failure_reason' for nil:NilClass > from (irb):189 > from :0 > > The description at treetop.rubyforge.org seems to suggest that if the > parse fails, the methods failure_reason, failure_line, and > failure_column would exist in such a way as to point to and describe the > reason for failure. > > Can someone please suggest some other avenues for debugging this? nil is nil... so once you get it there is no reason to call unrelated methods on it. The doco suggests asking the parser object, not the result object: parser = ArithmeticParser.new result = parser.parse('4+=3') if !result puts parser.failure_reason puts parser.failure_line puts parser.failure_column end via http://treetop.rubyforge.org/using_in_ruby.html