Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JSON compiler

16 views
Skip to first unread message

Will Coleda

unread,
Sep 9, 2006, 7:30:19 PM9/9/06
to parrot-...@perl.org
Many moons ago, I added a JSON "dumper" like functionality to walk
PMCs and emit JSON strings for them. (http://www.json.org)

Finally got around to adding in a JSON "compiler" to take JSON
strings, and return a PMC. a PGE grammar is used, with a TGE backend
- unlike most other grammars, we go directly from PGE to PIR in one
transformation. (since we're only data, not code, there's not a lot
to transform.)

(from perldoc compilers/JSON/JSON.pir)

.local pmc JSON
JSON = compreg 'JSON'
$P0 = JSON("[1,2,3]")

Will create a pmc that "does" array, contains the values 1,
2, and 3,
and store it in register $P0.

There is a (terribly written!) sample in compilers/JSON called
"postalcodes.pir" that pulls JSON data from 'http://ws.geonames.org/
postalCodeSearchJSON', compiles the JSON response into PIR, and then
walks the PMC, dumping out results.

% ./parrot compilers/json/postalcodes.pir 06382
Place: Uncasville, US; Code: 06382


Many thanks to Jerry Gay for helping with the grammar - (esp. since
he had already written a grammar months ago that we had never
actually used anywhere! =-). Also thanks to Nuno Carvalho for writing
most of the tests (many of which caught bad behavior which I was
then able to fix easily. There are some more testings pending, so if
you find something odd, write a test and I'll fix it. =-)

Enjoy.

--
Will "Coke" Coleda
wi...@coleda.com


0 new messages