[svn:parrot] r41138 - in trunk: compilers/data_json examples/json
japhb at svn.parrot.org
japhb at svn.parrot.org
Mon Sep 7 21:53:10 UTC 2009
Author: japhb
Date: Mon Sep 7 21:53:09 2009
New Revision: 41138
URL: https://trac.parrot.org/parrot/changeset/41138
Log:
[data_json] More pedantic .HLL handling; switch examples/json/* to use data_json (with minor cleanups)
Modified:
trunk/compilers/data_json/data_json.pir
trunk/examples/json/postalcodes.pir
trunk/examples/json/test.pir
Modified: trunk/compilers/data_json/data_json.pir
==============================================================================
--- trunk/compilers/data_json/data_json.pir Mon Sep 7 21:07:11 2009 (r41137)
+++ trunk/compilers/data_json/data_json.pir Mon Sep 7 21:53:09 2009 (r41138)
@@ -24,12 +24,6 @@
=cut
-.include 'compilers/data_json/data_json/grammar.pir'
-.include 'compilers/data_json/data_json/pge2pir.pir'
-# .include 'data_json/grammar.pir'
-# .include 'data_json/pge2pir.pir'
-
-
.HLL 'data_json'
.sub '__onload' :load
@@ -85,6 +79,13 @@
throw $P0
.end
+
+.HLL 'parrot'
+
+.include 'compilers/data_json/data_json/grammar.pir'
+.include 'compilers/data_json/data_json/pge2pir.pir'
+
+
# Local Variables:
# mode: pir
# fill-column: 100
Modified: trunk/examples/json/postalcodes.pir
==============================================================================
--- trunk/examples/json/postalcodes.pir Mon Sep 7 21:07:11 2009 (r41137)
+++ trunk/examples/json/postalcodes.pir Mon Sep 7 21:53:09 2009 (r41138)
@@ -4,15 +4,15 @@
=head1 NAME
-postalcodes.pir
+postalcodes.pir - Show info about a postal code
=head1 SYNOPSIS
- % ./parrot postalcodes.pir <postal>
+ % parrot postalcodes.pir <postal>
=head1 DESCRIPTION
-Given a postal code (like, '06382'), print some information about various
+Given a postal code (e.g. '06382'), print some information about various
places with that code from around the world.
=cut
@@ -70,16 +70,15 @@
$I0 = index json_result, "\r\n\r\n"
substr json_result, 0, $I0, ""
- load_bytecode 'compilers/json/JSON.pbc'
- $P1 = compreg 'JSON'
- $P2 = $P1(json_result)
-
- $P3 = $P2['error']
- unless null $P3 goto bad_code
-
- $P2 = $P2['postalCodes']
+ load_language 'data_json'
+ $P1 = compreg 'data_json'
+ push_eh bad_code
+ $P2 = $P1.'compile'(json_result)
+ pop_eh
+ $P3 = $P2()
+ $P4 = $P3['postalCodes']
.local pmc it, code
- it = iter $P2
+ it = iter $P4
code_loop:
push_eh code_end
@@ -108,7 +107,7 @@
.return()
bad_code:
- say $P3
+ say $P2
.end
# Local Variables:
Modified: trunk/examples/json/test.pir
==============================================================================
--- trunk/examples/json/test.pir Mon Sep 7 21:07:11 2009 (r41137)
+++ trunk/examples/json/test.pir Mon Sep 7 21:53:09 2009 (r41138)
@@ -3,28 +3,27 @@
# $Id$
.sub main :main
- .param pmc argv
+ .param pmc argv
- .local int argc
- argc = elements argv
+ .local int argc
+ argc = elements argv
- if argc != 2 goto bad_args
+ if argc != 2 goto bad_args
- load_bytecode 'PGE.pbc'
- load_bytecode 'PGE/Util.pbc'
- load_bytecode 'compilers/json/JSON.pbc'
-
- .local pmc JSON
- JSON = compreg "JSON"
- $S0 = argv[1]
- $P1 = JSON($S0)
+ .local pmc json, code, data
+ .local string text
+ load_language 'data_json'
+ json = compreg 'data_json'
+ text = argv[1]
+ code = json.'compile'(text)
+ data = code()
load_bytecode 'dumper.pbc'
- _dumper($P1, "JSON")
+ _dumper(data, 'JSON')
end
bad_args:
- say "must specify a single arg."
+ say "Must specify a single arg."
end
.end
More information about the parrot-commits
mailing list