Re: json
- Posted by ghaberek (admin) Aug 02, 2012
- 2957 views
I've created a github project for this at https://github.com/axtens/euJSON. There's nothing there but a readme at this point.
Kind regards
Bruce/bugmagnet
Ah ha! In reading this post, I did some Googling and started poking around with the code from that very same page.
Unfortunately, I had to backtrack a bit, as I feel one thing that would help make file/string parsing a bit easier in Euphoria would be more dynamic file and memory stream I/O, especially buffered I/O with a putback() or peek_next_char() function.
Here's a quick example I threw together in my head.
stream s = stream:open( filename, STREAM_READ ) while not stream:eof( s ) do -- peek a single character (i.e. get the next character, but do not advance the -- file position, so the next call to stream:getc() returns the same character) char c = stream:peekc( s ) switch c do case '{' then process_json_object( s ) case '[' then process_json_array( s ) case else puts( 2, "Expected '{' or '['\n" ) abort( 1 ) end switch end while stream:close( s )
It may also be advantageous to have the programmers of Euphoria itself add one of the open-source C-based processors to Euphoria directly. It would be nice to have a proper in-built XML parser as well.
-Greg