# ACTIVESTATE TEAPOT-PKG BEGIN TM -*- tcl -*- # -- Tcl Module # @@ Meta Begin # Package pt::peg::from::json 1 # Meta as::build::date 2015-05-25 # Meta as::origin http://sourceforge.net/projects/tcllib # Meta category Parser Tools # Meta description PEG Conversion. Read JSON format # Meta license BSD # Meta platform tcl # Meta require {Tcl 8.5} # Meta require json # Meta require pt::peg # Meta subject expression {push down automaton} state JSON EBNF # Meta subject {context-free languages} matching PEG TDPL # Meta subject {parsing expression} parser serialization conversion # Meta subject {recursive descent} grammar transducer # Meta subject {top-down parsing languages} # Meta subject {parsing expression grammar} LL(k) {format conversion} # Meta summary pt::peg::from::json # @@ Meta End # ACTIVESTATE TEAPOT-PKG BEGIN REQUIREMENTS package require Tcl 8.5 package require json package require pt::peg # ACTIVESTATE TEAPOT-PKG END REQUIREMENTS # ACTIVESTATE TEAPOT-PKG BEGIN DECLARE package provide pt::peg::from::json 1 # ACTIVESTATE TEAPOT-PKG END DECLARE # ACTIVESTATE TEAPOT-PKG END TM # peg_from_json.tcl -- # # Conversion to PEG from JSON (Java Script Object Notation). # # Copyright (c) 2009 Andreas Kupries # # 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