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