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
(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. =-)
Will "Coke" Coleda