1# peg_from_json.tcl --
2#
3#	Conversion to PEG from JSON (Java Script Object Notation).
4#
5# Copyright (c) 2009 Andreas Kupries <andreas_kupries@sourceforge.net>
6#
7# See the file "license.terms" for information on usage and redistribution
8# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9#
10# RCS: @(#) $Id: pt_peg_from_json.tcl,v 1.1 2010/03/26 05:07:24 andreas_kupries Exp $
11
12# This package takes text in JSON format (Java Script data transfer
13# format) and produces the canonical serialization of a parsing
14# expression grammar.
15
16# ### ### ### ######### ######### #########
17## Requisites
18
19package require Tcl 8.5
20package require pt::peg ; # Verification that the input is proper.
21package require json
22
23# ### ### ### ######### ######### #########
24##
25
26namespace eval ::pt::peg::from::json {
27    namespace export convert
28    namespace ensemble create
29}
30
31# ### ### ### ######### ######### #########
32## API.
33
34proc ::pt::peg::from::json::convert {text} {
35    # Note: We cannot fail here on duplicate keys in the input, as we
36    # do for Tcl-based canonical PEG serializations, because our
37    # underlying JSON parser automatically merges them, by taking only
38    # the last found definition. I.e. of two or more definitions for
39    # some key X the last overwrites all previous occurences.
40
41    return [pt::peg canonicalize [json::json2dict $text]]
42}
43
44# ### ### ### ######### ######### #########
45## Ready
46
47package provide pt::peg::from::json 1
48return
49