Author: particle
Date: Mon Oct 24 07:35:38 2005
New Revision: 9543
Added:
trunk/runtime/parrot/library/JSON/
trunk/runtime/parrot/library/JSON/Parser.pir
Modified:
trunk/MANIFEST
Log:
JSON: added grammar for parsing JSON. parser is still incomplete.
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Mon Oct 24 07:35:38 2005
@@ -1630,6 +1630,7 @@ lib/Test/More.pm
lib/Test/Simple.pm [devel]
lib/Text/Balanced.pm [devel]
runtime/parrot/library/JSON.imc [library]
+runtime/parrot/library/JSON/Parser.pir [library]
runtime/parrot/library/Data/Sort.imc [library]
runtime/parrot/library/Data/Escape.imc [library]
runtime/parrot/library/Data/Replace.imc [library]
Added: trunk/runtime/parrot/library/JSON/Parser.pir
==============================================================================
--- (empty file)
+++ trunk/runtime/parrot/library/JSON/Parser.pir Mon Oct 24 07:35:38 2005
@@ -0,0 +1,76 @@
+# Copyright: 2001-2005 The Perl Foundation. All Rights Reserved.
+# $Id$
+
+=pod
+
+JSON::Parser
+
+=head1 DESCRIPTION
+
+This module uses a grammar designed to describe the syntax for B<JSON> files,
+in order to enable the conversion of data in the B<JSON> format to a B<PMC>.
+
+=cut
+
+.namespace [ 'JSON::Parser' ]
+
+
+.sub 'VERSION'
+ .return( '0.01' )
+.end
+
+
+.sub '__onload' :load
+ .local pmc p6rule_compile
+ .local string json_grammar
+ .local pmc rules
+
+ load_bytecode 'PGE.pbc'
+ p6rule_compile = find_global 'PGE', 'p6rule'
+
+ json_grammar = <<"JSON_GRAMMAR"
+grammar JSON;
+rule object { \{ <members>? \} }
+rule members { <string> \: <value> [ \, <string> \: <value> ]* }
+rule array { \[ <elements>? \] }
+rule elements { <value> [ \, <value> ]* }
+rule value { <string> | <number> | <object> | <array> | true | false | null }
+rule string { \" <char>* \" }
+rule char { \w | \" | \\ | \/ | \010 | \\u \x{4} }
+rule number { <int> <frac>? <exp>? }
+rule int { \-? \d+ }
+rule frac { \. \d+ }
+rule exp { <e> \d+ }
+rule e { e | e\+ | e\- | E | E\+ | E\- }
+JSON_GRAMMAR
+# this rule isn't working properly -----v------v----v----v
+#rule char { \w | \" | \\ | \/ | \010 | \014 | \n | \r | \t | \\u \x{4} }
+
+ rules = p6rule_compile( json_grammar )
+ store_global 'rules', rules
+.end
+
+
+.sub 'parser'
+ .param string json
+
+ .local pmc rules
+ rules = find_global 'rules'
+
+ .local pmc match
+ match = rules( json )
+
+ unless match goto match_fail
+
+ ## add meat to this skeleton
+
+MATCH_FAIL:
+ .return( match )
+.end
+
+
+=head1 AUTHOR
+
+Jerry Gay a.k.a. particle (E<[EMAIL PROTECTED]>)
+
+=cut