From: Eric Mahurin Date: 2008-02-04T09:02:22+09:00 Subject: Re: [QUIZ] Parsing JSON (#155) ------=_Part_3749_23467581.1202083347047 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Feb 3, 2008 8:14 AM, steve wrote: > Hey guys > > This is my first parser. I used Nathan Sobo's Treetop parsing library ( > http://treetop.rubyforge.org/, gem install treetop): > > http://pastie.caboo.se/146906 > > require 'treetop' > > > File.open("json.treetop", "w") {|f| f.write GRAMMAR } > > > Treetop.load "json" > > parser = JsonParser.new > > > pp parser.parse(STDIN.read).value if $0 == __FILE__ > > > > BEGIN { > > GRAMMAR = %q{ > > grammar Json > ... Steve, I tried this parser, but couldn't get it to work with the String interface of the quize testbench. Using an IO/stream is how a parser should work, but you should also be able to wrap a String in a StringIO. It complained about StringIO#index not being defined, but IO#index isn't defined either. Couldn't find anyplace where IO#index was monkey-patched. Eric ------=_Part_3749_23467581.1202083347047--