UnitTest( orderly.asp )

Output

JScriptTypeInfo

{"type":"object","properties":{"name":{"type":"string"},"description":{"type":"string","optional":true},"homepage":{"type":"string","pattern":"^http:"},"invented":{"type":"integer","minimum":1500,"maximum":3000}},"additionalProperties":true}

{
    "type": "object",
    "properties": {
        "name": {
            "type": "string"
        },
        "description": {
            "type": "string",
            "optional": true
        },
        "homepage": {
            "type": "string",
            "pattern": "^http:"
        },
        "invented": {
            "type": "integer",
            "minimum": 1500,
            "maximum": 3000
        }
    },
    "additionalProperties": true
}

Sources

/unittests/orderly.unit.test.asp

<!--#include virtual="/lib/unit-tests.asp"-->
<!--#include virtual="/lib/axe/Parsers/json2.asp"-->
<!--#include virtual="/lib/axe/Parsers/orderly.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en">
    <head>
        <title>AXE - Unit Test - Orderly</title>
        <!--// meta tags //-->
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <!--// link tags //-->
        <link rel="stylesheet" type="text/css" media="screen" href="/lib/unit-tests.css" />
    </head>
    <body>
        <div id="container">
            <div id="container-hd">
                <h1>UnitTest( orderly.asp )</h1>
            </div>
            <div id="container-bd">
 
<h2>Output</h2>
<div class="code"><pre><%
 
dim source : source = join(array( _
    "object {", _
    "  string name;", _
    "  string description?;", _
    "  string homepage /^http:/;", _
    "  integer {1500,3000} invented;", _
    "}*;" _
), vbNewline)
 
dim Schema : set Schema = Orderly.parse(source)
 
Response.write( typename( Schema ) & vbNewline )
Response.write( vbNewline )
Response.write( JSON.stringify(Schema) & vbNewline )
Response.write( vbNewline )
Response.write( Orderly.compile(source) & vbNewline )
 
set Schema = nothing
 
%></pre></div>
 
            </div>
            <div id="container-ft">
                <h2>Sources</h2>
                <h3><%= Request.ServerVariables("SCRIPT_NAME") %></h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( Request.ServerVariables("SCRIPT_NAME") ) ), "asp" ) %></div>
                <h3>orderly.asp</h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( "/lib/axe/Parsers/orderly.asp" ) ), "javascript" ) %></div>
                <h3>json2.asp</h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( "/lib/axe/Parsers/json2.asp" ) ), "javascript" ) %></div>
            </div>
        </div>
        <!--// javascript tags //-->
    </body>
</html>
 
 

orderly.asp

<script language="Javascript" runat="server">
 
/*
 
File: orderly.asp
 
AXE(ASP Xtreme Evolution) Orderly parser by Zach Carter.
 
Orderly.ASP leverages javascript to implement, without any modification, Zach 
Carter's orderly.js <http://github.com/zaach/orderly.js>. AXE documentation and 
examples inserted by Fabio Zendhi Nagao (nagaozen).
 
License:
 
This file is part of ASP Xtreme Evolution.
Copyright (C) 2007-2010 Fabio Zendhi Nagao
 
ASP Xtreme Evolution is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
ASP Xtreme Evolution is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public License
along with ASP Xtreme Evolution. If not, see <http://www.gnu.org/licenses/>.
 
 
 
 
 
Class: Orderly
 
Orderly is an ergonomic micro-language that can represent a subset of JSONSchema.
Orderly is designed to feel familiar to the average programmer and to be 
extremely easy to learn and remember.
 
License:
 
Copyright (c) 2009 Zachary Carter
 
Permission is hereby granted, free of charge, to any person obtaining a copy of 
this software and associated documentation files (the "Software"), to deal in 
the Software without restriction, including without limitation the rights to 
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so, 
subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
About:
 
    - Written by Zach Carter <http://zaa.ch/> @ March 2010
 
Notes:
 
    - Javascript compiler is based on the Orderly concepts from Lloyd Hilaiel of Yahoo! <http://orderly-json.org/> @ December 2009
 
 
 
 
 
Function: parse
 
This method parses an orderly source to build a javascript object which represents
the subset of JSONSchema <http://json-schema.org/> that Orderly is designed to
return.
 
Parameters:
 
    (string) - Valid Orderly text.
 
Returns:
 
    (mixed) - a JavaScript object.
 
Example:
 
(start code)
 
dim def : def = join(array( _
    "object {", _
    "  string name;", _
    "  string description?;", _
    "  string homepage /^http:/;", _
    "  integer {1500,3000} invented;", _
    "}*;" _
), vbNewline)
 
Response.write( typename(Orderly.parse(def)) )' prints JScriptTypeInfo
 
(end code)
 
 
 
 
 
Function: compile
 
This method parses an orderly source to build a string representation of the 
javascript object which represents the subset of JSONSchema <http://json-schema.org/>
generated by Orderly.
 
Parameters:
 
    (string) - Valid Orderly text.
 
Returns:
 
    (string) - The stringified version of the JSONSchema subset.
 
Example:
 
(start code)
 
dim def : def = join(array( _
    "object {", _
    "  string name;", _
    "  string description?;", _
    "  string homepage /^http:/;", _
    "  integer {1500,3000} invented;", _
    "}*;" _
), vbNewline)
 
Response.write( Orderly.compile(def) )' prints the string below:
 
' {
'     "type": "object",
'     "properties": {
'         "name": {
'             "type": "string"
'         },
'         "description": {
'             "type": "string",
'             "optional": true
'         },
'         "homepage": {
'             "type": "string",
'             "pattern": "^http:"
'         },
'         "invented": {
'             "type": "integer",
'             "minimum": 1500,
'             "maximum": 3000
'         }
'     },
'     "additionalProperties": true
' }
 
(end code)
 
Notes:
 
    - This method requires the JSON class to work.
 
*/
 
var Orderly = (function () {
    var exports = {};
    var parser = (function () {
        var parser = {
            trace: function trace() {},
            yy: {},
            symbols_: {
                "orderly_schema": 2,
                "unnamed_entry": 3,
                ";": 4,
                "named_entries": 5,
                "named_entry": 6,
                "unnamed_entries": 7,
                "definition_prefix": 8,
                "property_name": 9,
                "definition_suffix": 10,
                "string_prefix": 11,
                "string_suffix": 12,
                "INTEGER": 13,
                "optional_range": 14,
                "NUMBER": 15,
                "BOOLEAN": 16,
                "NULL": 17,
                "ANY": 18,
                "ARRAY": 19,
                "{": 20,
                "}": 21,
                "optional_additional_marker": 22,
                "[": 23,
                "]": 24,
                "OBJECT": 25,
                "UNION": 26,
                "STRING": 27,
                "optional_perl_regex": 28,
                "optional_enum_values": 29,
                "optional_default_value": 30,
                "optional_requires": 31,
                "optional_optional_marker": 32,
                "optional_extra_properties": 33,
                "csv_property_names": 34,
                ",": 35,
                "`": 36,
                "JSONObject": 37,
                "<": 38,
                ">": 39,
                "?": 40,
                "*": 41,
                "JSONArray": 42,
                "=": 43,
                "JSONValue": 44,
                "JSONNumber": 45,
                "JSONString": 46,
                "PROPERTY": 47,
                "REGEX": 48,
                "STRING_LIT": 49,
                "NUMBER_LIT": 50,
                "JSONNullLiteral": 51,
                "JSONBooleanLiteral": 52,
                "TRUE": 53,
                "FALSE": 54,
                "JSONText": 55,
                "JSONMemberList": 56,
                "JSONMember": 57,
                ":": 58,
                "JSONElementList": 59,
                "$accept": 0,
                "$end": 1
            },
            terminals_: {
                "4": ";",
                "13": "INTEGER",
                "15": "NUMBER",
                "16": "BOOLEAN",
                "17": "NULL",
                "18": "ANY",
                "19": "ARRAY",
                "20": "{",
                "21": "}",
                "23": "[",
                "24": "]",
                "25": "OBJECT",
                "26": "UNION",
                "27": "STRING",
                "35": ",",
                "36": "`",
                "38": "<",
                "39": ">",
                "40": "?",
                "41": "*",
                "43": "=",
                "47": "PROPERTY",
                "48": "REGEX",
                "49": "STRING_LIT",
                "50": "NUMBER_LIT",
                "53": "TRUE",
                "54": "FALSE",
                "58": ":"
            },
            productions_: [0, [2, 2],
                [2, 1],
                [5, 3],
                [5, 1],
                [5, 0],
                [7, 3],
                [7, 1],
                [7, 0],
                [6, 3],
                [6, 3],
                [3, 2],
                [3, 2],
                [8, 2],
                [8, 2],
                [8, 1],
                [8, 1],
                [8, 1],
                [8, 6],
                [8, 5],
                [8, 5],
                [8, 4],
                [11, 2],
                [12, 2],
                [10, 5],
                [34, 3],
                [34, 1],
                [33, 3],
                [33, 0],
                [31, 3],
                [31, 0],
                [32, 1],
                [32, 0],
                [22, 1],
                [22, 0],
                [29, 1],
                [29, 0],
                [30, 2],
                [30, 0],
                [14, 5],
                [14, 4],
                [14, 4],
                [14, 3],
                [14, 0],
                [9, 1],
                [9, 1],
                [28, 1],
                [28, 0],
                [46, 1],
                [45, 1],
                [51, 1],
                [52, 1],
                [52, 1],
                [55, 1],
                [44, 1],
                [44, 1],
                [44, 1],
                [44, 1],
                [44, 1],
                [44, 1],
                [37, 2],
                [37, 3],
                [57, 3],
                [56, 1],
                [56, 3],
                [42, 2],
                [42, 3],
                [59, 1],
                [59, 3]
            ],
            performAction: function anonymous(yytext, yyleng, yylineno, yy) {
                var Type = yy.Type;
                var $$ = arguments[5],
                    $0 = arguments[5].length;
                switch (arguments[4]) {
                case 1:
                    return $$[$0 - 2 + 1 - 1];
                    break;
                case 2:
                    return $$[$0 - 1 + 1 - 1];
                    break;
                case 3:
                    this.$ = $$[$0 - 3 + 3 - 1];
                    this.$.unshift($$[$0 - 3 + 1 - 1]);
                    break;
                case 4:
                    this.$ = [$$[$0 - 1 + 1 - 1]];
                    break;
                case 5:
                    this.$ = [];
                    break;
                case 6:
                    this.$ = $$[$0 - 3 + 3 - 1];
                    $$[$0 - 3 + 3 - 1].unshift($$[$0 - 3 + 1 - 1]);
                    break;
                case 7:
                    this.$ = [$$[$0 - 1 + 1 - 1]];
                    break;
                case 8:
                    this.$ = [];
                    break;
                case 9:
                    this.$ = [$$[$0 - 3 + 2 - 1], $$[$0 - 3 + 1 - 1]];
                    Type.addOptionals($$[$0 - 3 + 1 - 1], $$[$0 - 3 + 3 - 1]);
                    break;
                case 10:
                    this.$ = [$$[$0 - 3 + 2 - 1], $$[$0 - 3 + 1 - 1]];
                    Type.addOptionals($$[$0 - 3 + 1 - 1], $$[$0 - 3 + 3 - 1]);
                    break;
                case 11:
                    this.$ = $$[$0 - 2 + 1 - 1];
                    Type.addOptionals(this.$, $$[$0 - 2 + 2 - 1]);
                    break;
                case 12:
                    this.$ = $$[$0 - 2 + 1 - 1];
                    Type.addOptionals(this.$, $$[$0 - 2 + 2 - 1]);
                    break;
                case 13:
                    this.$ = new Type("integer", $$[$0 - 2 + 2 - 1]);
                    break;
                case 14:
                    this.$ = new Type("number", $$[$0 - 2 + 2 - 1]);
                    break;
                case 15:
                    this.$ = new Type("boolean");
                    break;
                case 16:
                    this.$ = new Type("null");
                    break;
                case 17:
                    this.$ = new Type("any");
                    break;
                case 18:
                    this.$ = new Type("array", $$[$0 - 6 + 6 - 1], $$[$0 - 6 + 3 - 1], $$[$0 - 6 + 5 - 1]);
                    break;
                case 19:
                    this.$ = new Type("array", $$[$0 - 5 + 5 - 1], $$[$0 - 5 + 3 - 1]);
                    break;
                case 20:
                    this.$ = new Type("object", null, $$[$0 - 5 + 3 - 1], $$[$0 - 5 + 5 - 1]);
                    break;
                case 21:
                    this.$ = new Type($$[$0 - 4 + 3 - 1]);
                    break;
                case 22:
                    this.$ = new Type("string", $$[$0 - 2 + 2 - 1]);
                    break;
                case 23:
                    this.$ = $$[$0 - 2 + 2 - 1];
                    this.$.pattern = $$[$0 - 2 + 1 - 1];
                    break;
                case 24:
                    this.$ = {
                        enums: $$[$0 - 5 + 1 - 1],
                        defaultv: $$[$0 - 5 + 2 - 1],
                        requires: $$[$0 - 5 + 3 - 1],
                        optional: $$[$0 - 5 + 4 - 1],
                        extras: $$[$0 - 5 + 5 - 1]
                    };
                    break;
                case 25:
                    this.$ = $$[$0 - 3 + 1 - 1];
                    this.$.push($$[$0 - 3 + 3 - 1]);
                    break;
                case 26:
                    this.$ = [$$[$0 - 1 + 1 - 1]];
                    break;
                case 27:
                    this.$ = $$[$0 - 3 + 2 - 1];
                    break;
                case 28:
                    this.$ = null;
                    break;
                case 29:
                    this.$ = $$[$0 - 3 + 2 - 1];
                    break;
                case 30:
                    this.$ = null;
                    break;
                case 31:
                    this.$ = true;
                    break;
                case 32:
                    this.$ = null;
                    break;
                case 33:
                    this.$ = true;
                    break;
                case 34:
                    this.$ = null;
                    break;
                case 35:
                    this.$ = $$[$0 - 1 + 1 - 1];
                    break;
                case 36:
                    this.$ = null;
                    break;
                case 37:
                    this.$ = $$[$0 - 2 + 2 - 1];
                    break;
                case 38:
                    this.$ = yy.NOVALUE;
                    break;
                case 39:
                    this.$ = [$$[$0 - 5 + 2 - 1], $$[$0 - 5 + 4 - 1]];
                    break;
                case 40:
                    this.$ = [$$[$0 - 4 + 2 - 1], null];
                    break;
                case 41:
                    this.$ = [null, $$[$0 - 4 + 3 - 1]];
                    break;
                case 42:
                    this.$ = null;
                    break;
                case 43:
                    this.$ = null;
                    break;
                case 44:
                    this.$ = $$[$0 - 1 + 1 - 1];
                    break;
                case 45:
                    this.$ = yytext;
                    break;
                case 46:
                    this.$ = yytext.substr(1, yytext.length - 2);
                    break;
                case 47:
                    this.$ = null;
                    break;
                case 48:
                    this.$ = yytext;
                    break;
                case 49:
                    this.$ = Number(yytext);
                    break;
                case 50:
                    this.$ = null;
                    break;
                case 51:
                    this.$ = true;
                    break;
                case 52:
                    this.$ = false;
                    break;
                case 53:
                    return this.$ = $$[$0 - 1 + 1 - 1];
                    break;
                case 54:
                    this.$ = $$[$0 - 1 + 1 - 1];
                    break;
                case 55:
                    this.$ = $$[$0 - 1 + 1 - 1];
                    break;
                case 56:
                    this.$ = $$[$0 - 1 + 1 - 1];
                    break;
                case 57:
                    this.$ = $$[$0 - 1 + 1 - 1];
                    break;
                case 58:
                    this.$ = $$[$0 - 1 + 1 - 1];
                    break;
                case 59:
                    this.$ = $$[$0 - 1 + 1 - 1];
                    break;
                case 60:
                    this.$ = {};
                    break;
                case 61:
                    this.$ = $$[$0 - 3 + 2 - 1];
                    break;
                case 62:
                    this.$ = [$$[$0 - 3 + 1 - 1], $$[$0 - 3 + 3 - 1]];
                    break;
                case 63:
                    this.$ = {};
                    this.$[$$[$0 - 1 + 1 - 1][0]] = $$[$0 - 1 + 1 - 1][1];
                    break;
                case 64:
                    this.$ = $$[$0 - 3 + 1 - 1];
                    $$[$0 - 3 + 1 - 1][$$[$0 - 3 + 3 - 1][0]] = $$[$0 - 3 + 3 - 1][1];
                    break;
                case 65:
                    this.$ = [];
                    break;
                case 66:
                    this.$ = $$[$0 - 3 + 2 - 1];
                    break;
                case 67:
                    this.$ = [$$[$0 - 1 + 1 - 1]];
                    break;
                case 68:
                    this.$ = $$[$0 - 3 + 1 - 1];
                    $$[$0 - 3 + 1 - 1].push($$[$0 - 3 + 3 - 1]);
                    break;
                default:
                    ;
                }
            },
            table: [{
                "2": 1,
                "3": 2,
                "8": 3,
                "11": 4,
                "13": [1, 5],
                "15": [1, 6],
                "16": [1, 7],
                "17": [1, 8],
                "18": [1, 9],
                "19": [1, 10],
                "25": [1, 11],
                "26": [1, 12],
                "27": [1, 13]
            },
            {
                "1": [3]
            },
            {
                "4": [1, 14],
                "1": [2, 2]
            },
            {
                "10": 15,
                "29": 16,
                "42": 17,
                "23": [1, 18],
                "4": [2, 36],
                "1": [2, 36],
                "36": [2, 36],
                "40": [2, 36],
                "38": [2, 36],
                "43": [2, 36],
                "21": [2, 36],
                "24": [2, 36]
            },
            {
                "12": 19,
                "28": 20,
                "48": [1, 21],
                "4": [2, 47],
                "1": [2, 47],
                "36": [2, 47],
                "40": [2, 47],
                "38": [2, 47],
                "43": [2, 47],
                "23": [2, 47],
                "21": [2, 47],
                "24": [2, 47]
            },
            {
                "14": 22,
                "20": [1, 23],
                "23": [2, 43],
                "43": [2, 43],
                "38": [2, 43],
                "40": [2, 43],
                "36": [2, 43],
                "4": [2, 43],
                "1": [2, 43],
                "21": [2, 43],
                "24": [2, 43],
                "47": [2, 43],
                "49": [2, 43]
            },
            {
                "14": 24,
                "20": [1, 23],
                "23": [2, 43],
                "43": [2, 43],
                "38": [2, 43],
                "40": [2, 43],
                "36": [2, 43],
                "4": [2, 43],
                "1": [2, 43],
                "21": [2, 43],
                "24": [2, 43],
                "47": [2, 43],
                "49": [2, 43]
            },
            {
                "1": [2, 15],
                "4": [2, 15],
                "36": [2, 15],
                "40": [2, 15],
                "38": [2, 15],
                "43": [2, 15],
                "23": [2, 15],
                "21": [2, 15],
                "24": [2, 15],
                "49": [2, 15],
                "47": [2, 15]
            },
            {
                "1": [2, 16],
                "4": [2, 16],
                "36": [2, 16],
                "40": [2, 16],
                "38": [2, 16],
                "43": [2, 16],
                "23": [2, 16],
                "21": [2, 16],
                "24": [2, 16],
                "49": [2, 16],
                "47": [2, 16]
            },
            {
                "1": [2, 17],
                "4": [2, 17],
                "36": [2, 17],
                "40": [2, 17],
                "38": [2, 17],
                "43": [2, 17],
                "23": [2, 17],
                "21": [2, 17],
                "24": [2, 17],
                "49": [2, 17],
                "47": [2, 17]
            },
            {
                "20": [1, 25],
                "23": [1, 26]
            },
            {
                "20": [1, 27]
            },
            {
                "20": [1, 28]
            },
            {
                "14": 29,
                "20": [1, 23],
                "48": [2, 43],
                "23": [2, 43],
                "43": [2, 43],
                "38": [2, 43],
                "40": [2, 43],
                "36": [2, 43],
                "4": [2, 43],
                "1": [2, 43],
                "21": [2, 43],
                "24": [2, 43],
                "47": [2, 43],
                "49": [2, 43]
            },
            {
                "1": [2, 1]
            },
            {
                "4": [2, 11],
                "1": [2, 11],
                "21": [2, 11],
                "24": [2, 11]
            },
            {
                "30": 30,
                "43": [1, 31],
                "4": [2, 38],
                "1": [2, 38],
                "36": [2, 38],
                "40": [2, 38],
                "38": [2, 38],
                "21": [2, 38],
                "24": [2, 38]
            },
            {
                "4": [2, 35],
                "1": [2, 35],
                "36": [2, 35],
                "40": [2, 35],
                "38": [2, 35],
                "43": [2, 35],
                "21": [2, 35],
                "24": [2, 35]
            },
            {
                "24": [1, 32],
                "59": 33,
                "44": 34,
                "51": 35,
                "52": 36,
                "46": 37,
                "45": 38,
                "37": 39,
                "42": 40,
                "17": [1, 41],
                "53": [1, 42],
                "54": [1, 43],
                "49": [1, 44],
                "50": [1, 45],
                "20": [1, 46],
                "23": [1, 18]
            },
            {
                "4": [2, 12],
                "1": [2, 12],
                "21": [2, 12],
                "24": [2, 12]
            },
            {
                "10": 47,
                "29": 16,
                "42": 17,
                "23": [1, 18],
                "1": [2, 36],
                "4": [2, 36],
                "36": [2, 36],
                "40": [2, 36],
                "38": [2, 36],
                "43": [2, 36],
                "21": [2, 36],
                "24": [2, 36]
            },
            {
                "4": [2, 46],
                "1": [2, 46],
                "36": [2, 46],
                "40": [2, 46],
                "38": [2, 46],
                "43": [2, 46],
                "23": [2, 46],
                "21": [2, 46],
                "24": [2, 46]
            },
            {
                "1": [2, 13],
                "4": [2, 13],
                "36": [2, 13],
                "40": [2, 13],
                "38": [2, 13],
                "43": [2, 13],
                "23": [2, 13],
                "21": [2, 13],
                "24": [2, 13],
                "49": [2, 13],
                "47": [2, 13]
            },
            {
                "45": 48,
                "35": [1, 49],
                "50": [1, 45]
            },
            {
                "1": [2, 14],
                "4": [2, 14],
                "36": [2, 14],
                "40": [2, 14],
                "38": [2, 14],
                "43": [2, 14],
                "23": [2, 14],
                "21": [2, 14],
                "24": [2, 14],
                "49": [2, 14],
                "47": [2, 14]
            },
            {
                "7": 50,
                "3": 51,
                "8": 3,
                "11": 4,
                "13": [1, 5],
                "15": [1, 6],
                "16": [1, 7],
                "17": [1, 8],
                "18": [1, 9],
                "19": [1, 10],
                "25": [1, 11],
                "26": [1, 12],
                "27": [1, 13],
                "21": [2, 8]
            },
            {
                "3": 52,
                "8": 3,
                "11": 4,
                "13": [1, 5],
                "15": [1, 6],
                "16": [1, 7],
                "17": [1, 8],
                "18": [1, 9],
                "19": [1, 10],
                "25": [1, 11],
                "26": [1, 12],
                "27": [1, 13]
            },
            {
                "5": 53,
                "6": 54,
                "8": 55,
                "11": 56,
                "13": [1, 5],
                "15": [1, 6],
                "16": [1, 7],
                "17": [1, 8],
                "18": [1, 9],
                "19": [1, 10],
                "25": [1, 11],
                "26": [1, 12],
                "27": [1, 13],
                "21": [2, 5]
            },
            {
                "7": 57,
                "3": 51,
                "8": 3,
                "11": 4,
                "13": [1, 5],
                "15": [1, 6],
                "16": [1, 7],
                "17": [1, 8],
                "18": [1, 9],
                "19": [1, 10],
                "25": [1, 11],
                "26": [1, 12],
                "27": [1, 13],
                "21": [2, 8]
            },
            {
                "1": [2, 22],
                "4": [2, 22],
                "36": [2, 22],
                "40": [2, 22],
                "38": [2, 22],
                "43": [2, 22],
                "23": [2, 22],
                "48": [2, 22],
                "21": [2, 22],
                "24": [2, 22],
                "49": [2, 22],
                "47": [2, 22]
            },
            {
                "31": 58,
                "38": [1, 59],
                "4": [2, 30],
                "1": [2, 30],
                "36": [2, 30],
                "40": [2, 30],
                "21": [2, 30],
                "24": [2, 30]
            },
            {
                "44": 60,
                "51": 35,
                "52": 36,
                "46": 37,
                "45": 38,
                "37": 39,
                "42": 40,
                "17": [1, 41],
                "53": [1, 42],
                "54": [1, 43],
                "49": [1, 44],
                "50": [1, 45],
                "20": [1, 46],
                "23": [1, 18]
            },
            {
                "43": [2, 65],
                "38": [2, 65],
                "40": [2, 65],
                "36": [2, 65],
                "1": [2, 65],
                "4": [2, 65],
                "21": [2, 65],
                "24": [2, 65],
                "35": [2, 65]
            },
            {
                "24": [1, 61],
                "35": [1, 62]
            },
            {
                "24": [2, 67],
                "35": [2, 67]
            },
            {
                "24": [2, 54],
                "35": [2, 54],
                "38": [2, 54],
                "40": [2, 54],
                "36": [2, 54],
                "1": [2, 54],
                "4": [2, 54],
                "21": [2, 54]
            },
            {
                "24": [2, 55],
                "35": [2, 55],
                "38": [2, 55],
                "40": [2, 55],
                "36": [2, 55],
                "1": [2, 55],
                "4": [2, 55],
                "21": [2, 55]
            },
            {
                "24": [2, 56],
                "35": [2, 56],
                "38": [2, 56],
                "40": [2, 56],
                "36": [2, 56],
                "1": [2, 56],
                "4": [2, 56],
                "21": [2, 56]
            },
            {
                "24": [2, 57],
                "35": [2, 57],
                "38": [2, 57],
                "40": [2, 57],
                "36": [2, 57],
                "1": [2, 57],
                "4": [2, 57],
                "21": [2, 57]
            },
            {
                "24": [2, 58],
                "35": [2, 58],
                "38": [2, 58],
                "40": [2, 58],
                "36": [2, 58],
                "1": [2, 58],
                "4": [2, 58],
                "21": [2, 58]
            },
            {
                "24": [2, 59],
                "35": [2, 59],
                "38": [2, 59],
                "40": [2, 59],
                "36": [2, 59],
                "1": [2, 59],
                "4": [2, 59],
                "21": [2, 59]
            },
            {
                "24": [2, 50],
                "35": [2, 50],
                "4": [2, 50],
                "1": [2, 50],
                "36": [2, 50],
                "40": [2, 50],
                "38": [2, 50],
                "21": [2, 50]
            },
            {
                "24": [2, 51],
                "35": [2, 51],
                "4": [2, 51],
                "1": [2, 51],
                "36": [2, 51],
                "40": [2, 51],
                "38": [2, 51],
                "21": [2, 51]
            },
            {
                "24": [2, 52],
                "35": [2, 52],
                "4": [2, 52],
                "1": [2, 52],
                "36": [2, 52],
                "40": [2, 52],
                "38": [2, 52],
                "21": [2, 52]
            },
            {
                "24": [2, 48],
                "35": [2, 48],
                "4": [2, 48],
                "1": [2, 48],
                "36": [2, 48],
                "40": [2, 48],
                "38": [2, 48],
                "21": [2, 48],
                "58": [2, 48],
                "23": [2, 48],
                "43": [2, 48],
                "48": [2, 48],
                "39": [2, 48]
            },
            {
                "24": [2, 49],
                "35": [2, 49],
                "4": [2, 49],
                "1": [2, 49],
                "36": [2, 49],
                "40": [2, 49],
                "38": [2, 49],
                "21": [2, 49]
            },
            {
                "21": [1, 63],
                "56": 64,
                "57": 65,
                "46": 66,
                "49": [1, 44]
            },
            {
                "1": [2, 23],
                "4": [2, 23],
                "21": [2, 23],
                "24": [2, 23]
            },
            {
                "35": [1, 67]
            },
            {
                "45": 68,
                "21": [1, 69],
                "50": [1, 45]
            },
            {
                "21": [1, 70]
            },
            {
                "4": [1, 71],
                "21": [2, 7]
            },
            {
                "24": [1, 72]
            },
            {
                "21": [1, 73]
            },
            {
                "4": [1, 74],
                "21": [2, 4]
            },
            {
                "9": 75,
                "46": 76,
                "47": [1, 77],
                "49": [1, 44]
            },
            {
                "9": 78,
                "46": 76,
                "47": [1, 77],
                "49": [1, 44]
            },
            {
                "21": [1, 79]
            },
            {
                "32": 80,
                "40": [1, 81],
                "4": [2, 32],
                "1": [2, 32],
                "36": [2, 32],
                "21": [2, 32],
                "24": [2, 32]
            },
            {
                "34": 82,
                "9": 83,
                "46": 76,
                "47": [1, 77],
                "49": [1, 44]
            },
            {
                "4": [2, 37],
                "1": [2, 37],
                "36": [2, 37],
                "40": [2, 37],
                "38": [2, 37],
                "21": [2, 37],
                "24": [2, 37]
            },
            {
                "43": [2, 66],
                "38": [2, 66],
                "40": [2, 66],
                "36": [2, 66],
                "1": [2, 66],
                "4": [2, 66],
                "21": [2, 66],
                "24": [2, 66],
                "35": [2, 66]
            },
            {
                "44": 84,
                "51": 35,
                "52": 36,
                "46": 37,
                "45": 38,
                "37": 39,
                "42": 40,
                "17": [1, 41],
                "53": [1, 42],
                "54": [1, 43],
                "49": [1, 44],
                "50": [1, 45],
                "20": [1, 46],
                "23": [1, 18]
            },
            {
                "24": [2, 60],
                "35": [2, 60],
                "4": [2, 60],
                "1": [2, 60],
                "36": [2, 60],
                "40": [2, 60],
                "38": [2, 60],
                "21": [2, 60]
            },
            {
                "21": [1, 85],
                "35": [1, 86]
            },
            {
                "21": [2, 63],
                "35": [2, 63]
            },
            {
                "58": [1, 87]
            },
            {
                "45": 88,
                "21": [1, 89],
                "50": [1, 45]
            },
            {
                "21": [1, 90]
            },
            {
                "23": [2, 42],
                "43": [2, 42],
                "38": [2, 42],
                "40": [2, 42],
                "36": [2, 42],
                "4": [2, 42],
                "1": [2, 42],
                "21": [2, 42],
                "24": [2, 42],
                "47": [2, 42],
                "49": [2, 42],
                "48": [2, 42]
            },
            {
                "22": 91,
                "41": [1, 92],
                "23": [2, 34],
                "43": [2, 34],
                "38": [2, 34],
                "40": [2, 34],
                "36": [2, 34],
                "4": [2, 34],
                "1": [2, 34],
                "20": [2, 34],
                "21": [2, 34],
                "24": [2, 34],
                "47": [2, 34],
                "49": [2, 34]
            },
            {
                "7": 93,
                "3": 51,
                "8": 3,
                "11": 4,
                "13": [1, 5],
                "15": [1, 6],
                "16": [1, 7],
                "17": [1, 8],
                "18": [1, 9],
                "19": [1, 10],
                "25": [1, 11],
                "26": [1, 12],
                "27": [1, 13],
                "21": [2, 8]
            },
            {
                "14": 94,
                "20": [1, 23],
                "23": [2, 43],
                "43": [2, 43],
                "38": [2, 43],
                "40": [2, 43],
                "36": [2, 43],
                "4": [2, 43],
                "1": [2, 43],
                "21": [2, 43],
                "24": [2, 43],
                "47": [2, 43],
                "49": [2, 43]
            },
            {
                "22": 95,
                "41": [1, 92],
                "23": [2, 34],
                "43": [2, 34],
                "38": [2, 34],
                "40": [2, 34],
                "36": [2, 34],
                "4": [2, 34],
                "1": [2, 34],
                "21": [2, 34],
                "24": [2, 34],
                "47": [2, 34],
                "49": [2, 34]
            },
            {
                "5": 96,
                "6": 54,
                "8": 55,
                "11": 56,
                "13": [1, 5],
                "15": [1, 6],
                "16": [1, 7],
                "17": [1, 8],
                "18": [1, 9],
                "19": [1, 10],
                "25": [1, 11],
                "26": [1, 12],
                "27": [1, 13],
                "21": [2, 5]
            },
            {
                "10": 97,
                "29": 16,
                "42": 17,
                "23": [1, 18],
                "4": [2, 36],
                "21": [2, 36],
                "36": [2, 36],
                "40": [2, 36],
                "38": [2, 36],
                "43": [2, 36]
            },
            {
                "21": [2, 44],
                "4": [2, 44],
                "36": [2, 44],
                "40": [2, 44],
                "38": [2, 44],
                "43": [2, 44],
                "23": [2, 44],
                "48": [2, 44],
                "35": [2, 44],
                "39": [2, 44]
            },
            {
                "21": [2, 45],
                "4": [2, 45],
                "36": [2, 45],
                "40": [2, 45],
                "38": [2, 45],
                "43": [2, 45],
                "23": [2, 45],
                "48": [2, 45],
                "35": [2, 45],
                "39": [2, 45]
            },
            {
                "12": 98,
                "28": 20,
                "48": [1, 21],
                "4": [2, 47],
                "21": [2, 47],
                "36": [2, 47],
                "40": [2, 47],
                "38": [2, 47],
                "43": [2, 47],
                "23": [2, 47]
            },
            {
                "1": [2, 21],
                "4": [2, 21],
                "36": [2, 21],
                "40": [2, 21],
                "38": [2, 21],
                "43": [2, 21],
                "23": [2, 21],
                "21": [2, 21],
                "24": [2, 21],
                "49": [2, 21],
                "47": [2, 21]
            },
            {
                "33": 99,
                "36": [1, 100],
                "4": [2, 28],
                "1": [2, 28],
                "21": [2, 28],
                "24": [2, 28]
            },
            {
                "4": [2, 31],
                "1": [2, 31],
                "36": [2, 31],
                "21": [2, 31],
                "24": [2, 31]
            },
            {
                "39": [1, 101],
                "35": [1, 102]
            },
            {
                "39": [2, 26],
                "35": [2, 26]
            },
            {
                "24": [2, 68],
                "35": [2, 68]
            },
            {
                "24": [2, 61],
                "35": [2, 61],
                "4": [2, 61],
                "1": [2, 61],
                "36": [2, 61],
                "40": [2, 61],
                "38": [2, 61],
                "21": [2, 61]
            },
            {
                "57": 103,
                "46": 66,
                "49": [1, 44]
            },
            {
                "44": 104,
                "51": 35,
                "52": 36,
                "46": 37,
                "45": 38,
                "37": 39,
                "42": 40,
                "17": [1, 41],
                "53": [1, 42],
                "54": [1, 43],
                "49": [1, 44],
                "50": [1, 45],
                "20": [1, 46],
                "23": [1, 18]
            },
            {
                "21": [1, 105]
            },
            {
                "23": [2, 40],
                "43": [2, 40],
                "38": [2, 40],
                "40": [2, 40],
                "36": [2, 40],
                "4": [2, 40],
                "1": [2, 40],
                "21": [2, 40],
                "24": [2, 40],
                "47": [2, 40],
                "49": [2, 40],
                "48": [2, 40]
            },
            {
                "23": [2, 41],
                "43": [2, 41],
                "38": [2, 41],
                "40": [2, 41],
                "36": [2, 41],
                "4": [2, 41],
                "1": [2, 41],
                "21": [2, 41],
                "24": [2, 41],
                "47": [2, 41],
                "49": [2, 41],
                "48": [2, 41]
            },
            {
                "14": 106,
                "20": [1, 23],
                "23": [2, 43],
                "43": [2, 43],
                "38": [2, 43],
                "40": [2, 43],
                "36": [2, 43],
                "4": [2, 43],
                "1": [2, 43],
                "21": [2, 43],
                "24": [2, 43],
                "47": [2, 43],
                "49": [2, 43]
            },
            {
                "23": [2, 33],
                "43": [2, 33],
                "38": [2, 33],
                "40": [2, 33],
                "36": [2, 33],
                "4": [2, 33],
                "1": [2, 33],
                "20": [2, 33],
                "21": [2, 33],
                "24": [2, 33],
                "47": [2, 33],
                "49": [2, 33]
            },
            {
                "21": [2, 6]
            },
            {
                "1": [2, 19],
                "4": [2, 19],
                "36": [2, 19],
                "40": [2, 19],
                "38": [2, 19],
                "43": [2, 19],
                "23": [2, 19],
                "21": [2, 19],
                "24": [2, 19],
                "49": [2, 19],
                "47": [2, 19]
            },
            {
                "1": [2, 20],
                "4": [2, 20],
                "36": [2, 20],
                "40": [2, 20],
                "38": [2, 20],
                "43": [2, 20],
                "23": [2, 20],
                "21": [2, 20],
                "24": [2, 20],
                "49": [2, 20],
                "47": [2, 20]
            },
            {
                "21": [2, 3]
            },
            {
                "4": [2, 9],
                "21": [2, 9]
            },
            {
                "4": [2, 10],
                "21": [2, 10]
            },
            {
                "1": [2, 24],
                "4": [2, 24],
                "21": [2, 24],
                "24": [2, 24]
            },
            {
                "37": 107,
                "20": [1, 46]
            },
            {
                "4": [2, 29],
                "1": [2, 29],
                "36": [2, 29],
                "40": [2, 29],
                "21": [2, 29],
                "24": [2, 29]
            },
            {
                "9": 108,
                "46": 76,
                "47": [1, 77],
                "49": [1, 44]
            },
            {
                "21": [2, 64],
                "35": [2, 64]
            },
            {
                "21": [2, 62],
                "35": [2, 62]
            },
            {
                "23": [2, 39],
                "43": [2, 39],
                "38": [2, 39],
                "40": [2, 39],
                "36": [2, 39],
                "4": [2, 39],
                "1": [2, 39],
                "21": [2, 39],
                "24": [2, 39],
                "47": [2, 39],
                "49": [2, 39],
                "48": [2, 39]
            },
            {
                "1": [2, 18],
                "4": [2, 18],
                "36": [2, 18],
                "40": [2, 18],
                "38": [2, 18],
                "43": [2, 18],
                "23": [2, 18],
                "21": [2, 18],
                "24": [2, 18],
                "49": [2, 18],
                "47": [2, 18]
            },
            {
                "36": [1, 109]
            },
            {
                "39": [2, 25],
                "35": [2, 25]
            },
            {
                "4": [2, 27],
                "1": [2, 27],
                "21": [2, 27],
                "24": [2, 27]
            }],
            parseError: function parseError(str, hash) {
                throw new Error(str);
            },
            parse: function parse(input) {
                var self = this,
                    stack = [0],
                    vstack = [null],
                    table = this.table,
                    yytext = "",
                    yylineno = 0,
                    yyleng = 0,
                    shifts = 0,
                    reductions = 0;
                this.lexer.setInput(input);
                this.lexer.yy = this.yy;
                var parseError = this.yy.parseError = this.yy.parseError || this.parseError;
 
                function lex() {
                    var token;
                    token = self.lexer.lex() || 1;
                    if (typeof token !== "number") {
                        token = self.symbols_[token];
                    }
                    return token;
                }
                var symbol, state, action, a, r, yyval = {},
                    p, len, ip = 0,
                    newState, expected;
                symbol = lex();
                while (true) {
                    state = stack[stack.length - 1];
                    action = table[state] && table[state][symbol];
                    if (typeof action === "undefined" || !action.length || !action[0]) {
                        expected = [];
                        for (p in table[state]) {
                            if (this.terminals_[p] && p != 1) {
                                expected.push("'" + this.terminals_[p] + "'");
                            }
                        }
                        if (this.lexer.showPosition) {
                            parseError("Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", "), {
                                text: this.lexer.match,
                                token: this.terminals_[symbol],
                                line: this.lexer.yylineno,
                                expected: expected
                            });
                        } else {
                            parseError("Parse error on line " + (yylineno + 1) + ": Unexpected '" + this.terminals_[symbol] + "'", {
                                text: this.lexer.match,
                                token: this.terminals_[symbol],
                                line: this.lexer.yylineno,
                                expected: expected
                            });
                        }
                    }
                    if (action[0] instanceof Array && action.length > 1) {
                        throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
                    }
                    a = action;
                    switch (a[0]) {
                    case 1:
                        shifts++;
                        stack.push(symbol);
                        ++ip;
                        yyleng = this.lexer.yyleng;
                        yytext = this.lexer.yytext;
                        yylineno = this.lexer.yylineno;
                        symbol = lex();
                        vstack.push(null);
                        stack.push(a[1]);
                        break;
                    case 2:
                        reductions++;
                        len = this.productions_[a[1]][1];
                        yyval.$ = vstack[vstack.length - len];
                        r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, a[1], vstack);
                        if (typeof r !== "undefined") {
                            return r;
                        }
                        if (len) {
                            stack = stack.slice(0, -1 * len * 2);
                            vstack = vstack.slice(0, -1 * len);
                        }
                        stack.push(this.productions_[a[1]][0]);
                        vstack.push(yyval.$);
                        newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
                        stack.push(newState);
                        break;
                    case 3:
                        this.reductionCount = reductions;
                        this.shiftCount = shifts;
                        return true;
                    default:
                        ;
                    }
                }
                return true;
            }
        };
        var lexer = (function () {
            var lexer = ({
                EOF: "",
                parseError: function parseError(str, hash) {
                    if (this.yy.parseError) {
                        this.yy.parseError(str, hash);
                    } else {
                        throw new Error(str);
                    }
                },
                setInput: function (input) {
                    this._input = input;
                    this._more = this._less = this.done = false;
                    this.yylineno = this.yyleng = 0;
                    this.yytext = this.matched = this.match = "";
                    return this;
                },
                input: function () {
                    var ch = this._input[0];
                    this.yytext += ch;
                    this.yyleng++;
                    this.match += ch;
                    this.matched += ch;
                    var lines = ch.match(/\n/);
                    if (lines) {
                        this.yylineno++;
                    }
                    this._input = this._input.slice(1);
                    return ch;
                },
                unput: function (ch) {
                    this._input = ch + this._input;
                    return this;
                },
                more: function () {
                    this._more = true;
                    return this;
                },
                pastInput: function () {
                    var past = this.matched.substr(0, this.matched.length - this.match.length);
                    return (past.length > 20 ? "..." : "") + past.substr(-20).replace(/\n/g, "");
                },
                upcomingInput: function () {
                    var next = this.match;
                    if (next.length < 20) {
                        next += this._input.substr(0, 20 - next.length);
                    }
                    return (next.substr(0, 20) + (next.length > 20 ? "..." : "")).replace(/\n/g, "");
                },
                showPosition: function () {
                    var pre = this.pastInput();
                    var c = (new Array(pre.length + 1)).join("-");
                    return pre + this.upcomingInput() + "\n" + c + "^";
                },
                next: function () {
                    if (this.done) {
                        return this.EOF;
                    }
                    if (!this._input) {
                        this.done = true;
                    }
                    var token, match, lines;
                    if (!this._more) {
                        this.yytext = "";
                        this.match = "";
                    }
                    for (var i = 0; i < this.rules.length; i++) {
                        match = this._input.match(this.rules[i]);
                        if (match) {
                            lines = match[0].match(/\n/g);
                            if (lines) {
                                this.yylineno += lines.length;
                            }
                            this.yytext += match[0];
                            this.match += match[0];
                            this.matches = match;
                            this.yyleng = this.yytext.length;
                            this._more = false;
                            this._input = this._input.slice(match[0].length);
                            this.matched += match[0];
                            token = this.performAction.call(this, this.yy, this, i);
                            if (token) {
                                return token;
                            } else {
                                return;
                            }
                        }
                    }
                    if (this._input == this.EOF) {
                        return this.EOF;
                    } else {
                        this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {
                            text: "",
                            token: null,
                            line: this.yylineno
                        });
                    }
                },
                lex: function () {
                    var r = this.next();
                    if (typeof r !== "undefined") {
                        return r;
                    } else {
                        return this.lex();
                    }
                }
            });
            lexer.performAction = function anonymous(yy, yy_) {
                switch (arguments[2]) {
                case 0:
                    break;
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    return 4;
                    break;
                case 4:
                    return 35;
                    break;
                case 5:
                    return 20;
                    break;
                case 6:
                    return 21;
                    break;
                case 7:
                    return 23;
                    break;
                case 8:
                    return 24;
                    break;
                case 9:
                    return 36;
                    break;
                case 10:
                    return 38;
                    break;
                case 11:
                    return 39;
                    break;
                case 12:
                    return 58;
                    break;
                case 13:
                    return 25;
                    break;
                case 14:
                    return 13;
                    break;
                case 15:
                    return 15;
                    break;
                case 16:
                    return 17;
                    break;
                case 17:
                    return 16;
                    break;
                case 18:
                    return 18;
                    break;
                case 19:
                    return 19;
                    break;
                case 20:
                    return 26;
                    break;
                case 21:
                    return 27;
                    break;
                case 22:
                    return 53;
                    break;
                case 23:
                    return 54;
                    break;
                case 24:
                    yy_.yytext = yy_.yytext.substr(1, yy_.yyleng - 2);
                    return 49;
                    break;
                case 25:
                    return 50;
                    break;
                case 26:
                    return 47;
                    break;
                case 27:
                    return 40;
                    break;
                case 28:
                    return 41;
                    break;
                case 29:
                    return 43;
                    break;
                case 30:
                    return 48;
                    break;
                default:
                    ;
                }
            };
            lexer.rules = [/^\s+/, /^\/\/[^\n]*/, /^#[^\n]*/, /^;/, /^,/, /^\{/, /^\}/, /^\[/, /^\]/, /^`/, /^</, /^>/, /^:/, /^object\b/, /^integer\b/, /^number\b/, /^null\b/, /^boolean\b/, /^any\b/, /^array\b/, /^union\b/, /^string\b/, /^true\b/, /^false\b/, /^"(?:\\["bfnrt\/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*"/, /^-?(?:[0-9]|[1-9][0-9]+)(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\b/, /^[A-Za-z_0-9-]+/, /^\?/, /^\*/, /^=/, /^\/(?:[^\/]|\/)*\//];
            return lexer;
        })()
        parser.lexer = lexer;
        return parser;
    })();
    if (typeof require !== 'undefined') {
        exports.parser = parser;
        exports.parse = function () {
            return parser.parse.apply(parser, arguments);
        }
        exports.main = function commonjsMain(args) {
            var cwd = require("file").path(require("file").cwd());
            if (!args[1]) {
                throw new Error("Usage: " + args[0] + " FILE");
            }
            var source = cwd.join(args[1]).read({
                charset: "utf-8"
            });
            this.parse(source);
        }
        if (require.main === module) {
            exports.main(require("system").args);
        }
    }
    if (typeof require !== 'undefined') {
        var scope = exports;
    } else {
        var scope = parser.yy
    }
    scope.NOVALUE = {};
    scope.Type = function () {
        return this.init.apply(this, arguments);
    };
    scope.Type.prototype = {
        init: function (type, range, entries, additional) {
            this.json = {};
            this.json.type = type;
            if (range) {
                this.addRange(range);
            }
            if (entries) {
                this.addEntries(entries);
            }
            if (additional) {
                this.json.additionalProperties = true;
            }
            return this.json;
        },
        addEntries: function (entries) {
            if (this.json.type === "array" && (!(entries instanceof Array) || entries.length > 0)) {
                this.json.items = entries;
            } else if (entries.length) {
                this.json.properties = {};
                for (var i = 0; i < entries.length; i++) {
                    this.json.properties[entries[i][0]] = entries[i][1];
                }
            }
        },
        addRange: function (tuple) {
            var suf = this.json.type === 'array' ? 'Items' : this.json.type === 'string' ? 'Length' : 'imum';
            if (tuple[0] !== null) this.json['min' + suf] = tuple[0];
            if (tuple[1] !== null) this.json['max' + suf] = tuple[1];
        }
    };
    scope.Type.addOptionals = function (type, o) {
        if (o.extras) {
            var prop;
            for (prop in o.extras) if (o.extras.hasOwnProperty(prop)) type[prop] = o.extras[prop];
        }
        if (o.optional) {
            type.optional = true;
        }
        if (o.enums) {
            type["enum"] = o.enums;
        }
        if (o.requires) {
            type.requires = o.requires.length > 1 ? o.requires : o.requires[0];
        }
        if (o.defaultv !== scope.NOVALUE) {
            type["default"] = o.defaultv;
        }
        if (o.pattern) {
            type.pattern = o.pattern;
        }
    };
    if (typeof require !== 'undefined') {
        var parser = require("./orderly/parse").parser;
        parser.yy = require("./orderly/scope");
    }
    var parse = exports.parse = function (input) {
        return parser.parse(input);
    };
    var compile = exports.compile = function (input) {
        return JSON.stringify(parse(input), null, "    ");
    };
    exports.main = function main(args) {
        var fs = require("file"),
            cwd = fs.path(fs.cwd());
        if (!args[1]) {
            throw new Error("Usage: " + args[0] + " FILE [OUTFILE]");
        }
        var orderly = cwd.join(args[1]).read({
            charset: "utf-8"
        }),
            source = compile(orderly),
            stream = cwd.join(args[2] || fs.basename(args[1], ".orderly") + ".jsonschema").open("w");
        stream.print(source).close();
    };
    return exports;
})()
 
</script>
 

json2.asp

<script language="Javascript" runat="server">
 
/*
 
File: json2.asp
 
AXE(ASP Xtreme Evolution) JSON parser based on Douglas Crockford json2.js.
 
This class is the result of Classic ASP JSON topic revisited by Fabio Zendhi 
Nagao (nagaozen). JSON2.ASP is a better option over JSON.ASP because it embraces
the AXE philosophy of real collaboration over the languages. It works under the
original json parser, so this class is strict in the standard rules, plus it 
brings more of the Javascript json feeling to other ASP languages (eg. no more 
oJson.getElement("foo") stuff, just oJson.foo and you get it).
 
License:
 
This file is part of ASP Xtreme Evolution.
Copyright (C) 2007-2010 Fabio Zendhi Nagao
 
ASP Xtreme Evolution is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
ASP Xtreme Evolution is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public License
along with ASP Xtreme Evolution. If not, see <http://www.gnu.org/licenses/>.
 
 
 
 
 
Class: JSON
 
JSON (Javascript Object Notation) is a lightweight data-interchange format. It 
is easy for humans to read and write. It is easy for machines to parse and 
generate. It is based on a subset of the Javascript Programming Language, 
Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is 
completely language independent but uses conventions that are familiar to 
programmers of the C-family of languages, including C, C++, C#, Java, 
Javascript, Perl, Python, and many others. These properties make JSON an ideal 
data-interchange language.
 
Notes:
 
    - Javascript extensions concept inspired by Troy Foster JSON2.ASP work <http://tforster.wik.is/ASP_Classic_Practices_For_The_21st_Century/JSON4ASP>.
    - Javascript JSON parser is the Douglas Crockford json2.js <http://www.JSON.org/json2.js>, without the first line alert(...) and fixing "this.JSON = {};" to "JSON = {};" to make it JScript compatible.
 
About:
 
    - Written by Fabio Zendhi Nagao <http://zend.lojcomm.com.br/> @ August 2010
 
 
 
 
 
Function: parse
 
This method parses a JSON text to produce an object or array. It can throw a SyntaxError exception.
 
Parameters:
 
    (string) - Valid JSON text.
 
Returns:
 
    (mixed) - a Javascript value, usually an object or array.
 
Example:
 
(start code)
 
dim Info : set Info = JSON.parse(join(array( _
    "{", _
    "  ""firstname"": ""Fabio"",", _
    "  ""lastname"": ""長尾"",", _
    "  ""alive"": true,", _
    "  ""age"": 27,", _
    "  ""nickname"": ""nagaozen"",", _
    "  ""fruits"": [", _
    "    ""banana"",", _
    "    ""orange"",", _
    "    ""apple"",", _
    "    ""papaya"",", _
    "    ""pineapple""", _
    "  ],", _
    "  ""complex"": {", _
    "    ""real"": 1,", _
    "    ""imaginary"": 2", _
    "  }", _
    "}" _
)))
 
Response.write(Info.firstname & vbNewline) ' prints Fabio
Response.write(Info.alive & vbNewline) ' prints True
Response.write(Info.age & vbNewline) ' prints 27
Response.write(Info.fruits.get(0) & vbNewline) ' prints banana
Response.write(Info.fruits.get(1) & vbNewline) ' prints orange
Response.write(Info.complex.real & vbNewline) ' prints 1
Response.write(Info.complex.imaginary & vbNewline) ' prints 2
 
' You can also enumerate object properties ...
 
dim key : for each key in Info.keys()
    Response.write( key & vbNewline )
next
 
' which prints:
 
' firstname
' lastname
' alive
' age
' nickname
' fruits
' complex
 
set Info = nothing
 
(end code)
 
 
 
 
 
Function: stringify
 
This method produces a JSON text from a Javascript value.
 
Parameters:
 
    (mixed) - any Javascript value, usually an object or array.
    (mixed) - an optional parameter that determines how object values are stringified for objects. It can be a function or an array of strings.
    (mixed) - an optional parameter that specifies the indentation of nested structures. If it is omitted, the text will be packed without extra whitespace. If it is a number, it will specify the number of spaces to indent at each level. If it is a string (such as '\t' or '&nbsp;'), it contains the characters used to indent at each level.
 
Returns:
 
    (string) - a string that contains the serialized JSON text.
 
Example:
 
(start code)
 
dim Info : set Info = JSON.parse("{""firstname"":""Fabio"", ""lastname"":""長尾""}")
Info.set "alive", true
Info.set "age", 27
Info.set "nickname", "nagaozen"
Info.set "fruits", array("banana","orange","apple","papaya","pineapple")
Info.set "complex", JSON.parse("{""real"":1, ""imaginary"":1}")
 
Response.write( JSON.stringify(Info, null, 2) & vbNewline ) ' prints the text below:
'{
'  "firstname": "Fabio",
'  "lastname": "長尾",
'  "alive": true,
'  "age": 27,
'  "nickname": "nagaozen",
'  "fruits": [
'    "banana",
'    "orange",
'    "apple",
'    "papaya",
'    "pineapple"
'  ],
'  "complex": {
'    "real": 1,
'    "imaginary": 1
'  }
'}
 
set Info = nothing
 
(end code)
 
 
 
 
 
Function: toXML
 
This method produces a XML text from a Javascript value.
 
Parameters:
 
    (mixed) - any Javascript value, usually an object or array.
    (string) - an optional parameter that determines what tag should be used as a container for the output. Defaults to none.
 
Returns:
 
    (string) - a string that contains the serialized XML text.
 
Example:
 
(start code)
 
dim Info : set Info = JSON.parse("{""firstname"":""Fabio"", ""lastname"":""長尾""}")
Info.set "alive", true
Info.set "age", 27
Info.set "nickname", "nagaozen"
Info.set "fruits", array("banana","orange","apple","papaya","pineapple")
Info.set "complex", JSON.parse("{""real"":1, ""imaginary"":1}")
 
Response.write( JSON.toXML(Info) & vbNewline ) ' prints the text below:
'<firstname>Fabio</firstname>
'<lastname>長尾</lastname>
'<alive>true</alive>
'<age>27</age>
'<nickname>nagaozen</nickname>
'<fruits>banana</fruits>
'<fruits>orange</fruits>
'<fruits>apple</fruits>
'<fruits>papaya</fruits>
'<fruits>pineapple</fruits>
'<complex>
'    <real>1</real>
'    <imaginary>1</imaginary>
'</complex>
 
set Info = nothing
 
(end code)
 
*/
 
if(!Object.prototype.get) {
    Object.prototype.get = function(k) {
        return this[k];
    }
}
 
if(!Object.prototype.set) {
    Object.prototype.set = function(k,v) {
        if(typeof(v) == "unknown") {
            try {
                v = (new VBArray(v)).toArray();
            } catch(e) {
                return;
            }
        }
        this[k] = v;
    }
}
 
if(!Object.prototype["delete"]) {
    Object.prototype["delete"] = function(k) {
        delete this[k];
    }
}
 
if(!Object.prototype.keys) {
    Object.prototype.keys = function() {
        var d = new ActiveXObject("Scripting.Dictionary");
        for(var key in this) {
            if(this.hasOwnProperty(key)) {
                d.add(key, null);
            }
        }
        return d.keys();
    }
}
 
if(!String.prototype.sanitize) {
    String.prototype.sanitize = function(a, b) {
        var len = a.length,
            s = this;
        if(len !== b.length) throw new TypeError('Invalid procedure call. Both arrays should have the same size.');
        for(var i = 0; i < len; i++) {
            var re = new RegExp(a[i],'g');
            s = s.replace(re, b[i]);
        }
        return s;
    }
}
 
if(!String.prototype.substitute) {
    String.prototype.substitute = function(object, regexp){
        return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
            if (match.charAt(0) == '\\') return match.slice(1);
            return (object[name] != undefined) ? object[name] : '';
        });
    }
}
 
 
 
 
 
 
 
 
 
 
/*
    http://www.JSON.org/json2.js
    2010-03-20
 
    Public Domain.
 
    NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
 
    See http://www.JSON.org/js.html
 
 
    This code should be minified before deployment.
    See http://javascript.crockford.com/jsmin.html
 
    USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
    NOT CONTROL.
 
 
    This file creates a global JSON object containing two methods: stringify
    and parse.
 
        JSON.stringify(value, replacer, space)
            value       any JavaScript value, usually an object or array.
 
            replacer    an optional parameter that determines how object
                        values are stringified for objects. It can be a
                        function or an array of strings.
 
            space       an optional parameter that specifies the indentation
                        of nested structures. If it is omitted, the text will
                        be packed without extra whitespace. If it is a number,
                        it will specify the number of spaces to indent at each
                        level. If it is a string (such as '\t' or '&nbsp;'),
                        it contains the characters used to indent at each level.
 
            This method produces a JSON text from a JavaScript value.
 
            When an object value is found, if the object contains a toJSON
            method, its toJSON method will be called and the result will be
            stringified. A toJSON method does not serialize: it returns the
            value represented by the name/value pair that should be serialized,
            or undefined if nothing should be serialized. The toJSON method
            will be passed the key associated with the value, and this will be
            bound to the value
 
            For example, this would serialize Dates as ISO strings.
 
                Date.prototype.toJSON = function (key) {
                    function f(n) {
                        // Format integers to have at least two digits.
                        return n < 10 ? '0' + n : n;
                    }
 
                    return this.getUTCFullYear()   + '-' +
                         f(this.getUTCMonth() + 1) + '-' +
                         f(this.getUTCDate())      + 'T' +
                         f(this.getUTCHours())     + ':' +
                         f(this.getUTCMinutes())   + ':' +
                         f(this.getUTCSeconds())   + 'Z';
                };
 
            You can provide an optional replacer method. It will be passed the
            key and value of each member, with this bound to the containing
            object. The value that is returned from your method will be
            serialized. If your method returns undefined, then the member will
            be excluded from the serialization.
 
            If the replacer parameter is an array of strings, then it will be
            used to select the members to be serialized. It filters the results
            such that only members with keys listed in the replacer array are
            stringified.
 
            Values that do not have JSON representations, such as undefined or
            functions, will not be serialized. Such values in objects will be
            dropped; in arrays they will be replaced with null. You can use
            a replacer function to replace those with JSON values.
            JSON.stringify(undefined) returns undefined.
 
            The optional space parameter produces a stringification of the
            value that is filled with line breaks and indentation to make it
            easier to read.
 
            If the space parameter is a non-empty string, then that string will
            be used for indentation. If the space parameter is a number, then
            the indentation will be that many spaces.
 
            Example:
 
            text = JSON.stringify(['e', {pluribus: 'unum'}]);
            // text is '["e",{"pluribus":"unum"}]'
 
 
            text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
            // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
 
            text = JSON.stringify([new Date()], function (key, value) {
                return this[key] instanceof Date ?
                    'Date(' + this[key] + ')' : value;
            });
            // text is '["Date(---current time---)"]'
 
 
        JSON.parse(text, reviver)
            This method parses a JSON text to produce an object or array.
            It can throw a SyntaxError exception.
 
            The optional reviver parameter is a function that can filter and
            transform the results. It receives each of the keys and values,
            and its return value is used instead of the original value.
            If it returns what it received, then the structure is not modified.
            If it returns undefined then the member is deleted.
 
            Example:
 
            // Parse the text. Values that look like ISO date strings will
            // be converted to Date objects.
 
            myData = JSON.parse(text, function (key, value) {
                var a;
                if (typeof value === 'string') {
                    a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
                    if (a) {
                        return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                            +a[5], +a[6]));
                    }
                }
                return value;
            });
 
            myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
                var d;
                if (typeof value === 'string' &&
                        value.slice(0, 5) === 'Date(' &&
                        value.slice(-1) === ')') {
                    d = new Date(value.slice(5, -1));
                    if (d) {
                        return d;
                    }
                }
                return value;
            });
 
 
    This is a reference implementation. You are free to copy, modify, or
    redistribute.
*/
 
/*jslint evil: true, strict: false */
 
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
    call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
    getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
    lastIndex, length, parse, prototype, push, replace, slice, stringify,
    test, toJSON, toString, valueOf
*/
 
 
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
 
if (!this.JSON) {
    JSON = {};
}
 
(function () {
 
    function f(n) {
        // Format integers to have at least two digits.
        return n < 10 ? '0' + n : n;
    }
 
    if (typeof Date.prototype.toJSON !== 'function') {
 
        Date.prototype.toJSON = function (key) {
 
            return isFinite(this.valueOf()) ?
                   this.getUTCFullYear()   + '-' +
                 f(this.getUTCMonth() + 1) + '-' +
                 f(this.getUTCDate())      + 'T' +
                 f(this.getUTCHours())     + ':' +
                 f(this.getUTCMinutes())   + ':' +
                 f(this.getUTCSeconds())   + 'Z' : null;
        };
 
        String.prototype.toJSON =
        Number.prototype.toJSON =
        Boolean.prototype.toJSON = function (key) {
            return this.valueOf();
        };
    }
 
    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        gap,
        indent,
        meta = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        rep;
 
 
    function quote(string) {
 
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.
 
        escapable.lastIndex = 0;
        return escapable.test(string) ?
            '"' + string.replace(escapable, function (a) {
                var c = meta[a];
                return typeof c === 'string' ? c :
                    '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
            }) + '"' :
            '"' + string + '"';
    }
 
 
    function str(key, holder) {
 
// Produce a string from holder[key].
 
        var i,          // The loop counter.
            k,          // The member key.
            v,          // The member value.
            length,
            mind = gap,
            partial,
            value = holder[key];
 
// If the value has a toJSON method, call it to obtain a replacement value.
 
        if (value && typeof value === 'object' &&
                typeof value.toJSON === 'function') {
            value = value.toJSON(key);
        }
 
// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.
 
        if (typeof rep === 'function') {
            value = rep.call(holder, key, value);
        }
 
// What happens next depends on the value's type.
 
        switch (typeof value) {
        case 'string':
            return quote(value);
 
        case 'number':
 
// JSON numbers must be finite. Encode non-finite numbers as null.
 
            return isFinite(value) ? String(value) : 'null';
 
        case 'boolean':
        case 'null':
 
// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.
 
            return String(value);
 
// If the type is 'object', we might be dealing with an object or an array or
// null.
 
        case 'object':
 
// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.
 
            if (!value) {
                return 'null';
            }
 
// Make an array to hold the partial results of stringifying this object value.
 
            gap += indent;
            partial = [];
 
// Is the value an array?
 
            if (Object.prototype.toString.apply(value) === '[object Array]') {
 
// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.
 
                length = value.length;
                for (i = 0; i < length; i += 1) {
                    partial[i] = str(i, value) || 'null';
                }
 
// Join all of the elements together, separated with commas, and wrap them in
// brackets.
 
                v = partial.length === 0 ? '[]' :
                    gap ? '[\n' + gap +
                            partial.join(',\n' + gap) + '\n' +
                                mind + ']' :
                          '[' + partial.join(',') + ']';
                gap = mind;
                return v;
            }
 
// If the replacer is an array, use it to select the members to be stringified.
 
            if (rep && typeof rep === 'object') {
                length = rep.length;
                for (i = 0; i < length; i += 1) {
                    k = rep[i];
                    if (typeof k === 'string') {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            } else {
 
// Otherwise, iterate through all of the keys in the object.
 
                for (k in value) {
                    if (Object.hasOwnProperty.call(value, k)) {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            }
 
// Join all of the member texts together, separated with commas,
// and wrap them in braces.
 
            v = partial.length === 0 ? '{}' :
                gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
                        mind + '}' : '{' + partial.join(',') + '}';
            gap = mind;
            return v;
        }
    }
 
// If the JSON object does not yet have a stringify method, give it one.
 
    if (typeof JSON.stringify !== 'function') {
        JSON.stringify = function (value, replacer, space) {
 
// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.
 
            var i;
            gap = '';
            indent = '';
 
// If the space parameter is a number, make an indent string containing that
// many spaces.
 
            if (typeof space === 'number') {
                for (i = 0; i < space; i += 1) {
                    indent += ' ';
                }
 
// If the space parameter is a string, it will be used as the indent string.
 
            } else if (typeof space === 'string') {
                indent = space;
            }
 
// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.
 
            rep = replacer;
            if (replacer && typeof replacer !== 'function' &&
                    (typeof replacer !== 'object' ||
                     typeof replacer.length !== 'number')) {
                throw new Error('JSON.stringify');
            }
 
// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.
 
            return str('', {'': value});
        };
    }
 
 
// If the JSON object does not yet have a parse method, give it one.
 
    if (typeof JSON.parse !== 'function') {
        JSON.parse = function (text, reviver) {
 
// The parse method takes a text and an optional reviver function, and returns
// a JavaScript value if the text is a valid JSON text.
 
            var j;
 
            function walk(holder, key) {
 
// The walk method is used to recursively walk the resulting structure so
// that modifications can be made.
 
                var k, v, value = holder[key];
                if (value && typeof value === 'object') {
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = walk(value, k);
                            if (v !== undefined) {
                                value[k] = v;
                            } else {
                                delete value[k];
                            }
                        }
                    }
                }
                return reviver.call(holder, key, value);
            }
 
 
// Parsing happens in four stages. In the first stage, we replace certain
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.
 
            text = String(text);
            cx.lastIndex = 0;
            if (cx.test(text)) {
                text = text.replace(cx, function (a) {
                    return '\\u' +
                        ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
                });
            }
 
// In the second stage, we run the text against regular expressions that look
// for non-JSON patterns. We are especially concerned with '()' and 'new'
// because they can cause invocation, and '=' because it can cause mutation.
// But just to be safe, we want to reject all unexpected forms.
 
// We split the second stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
 
            if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
 
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.
 
                j = eval('(' + text + ')');
 
// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.
 
                return typeof reviver === 'function' ?
                    walk({'': j}, '') : j;
            }
 
// If the text is not JSON parseable, then a SyntaxError is thrown.
 
            throw new SyntaxError('JSON.parse');
        };
    }
}());
 
 
 
 
 
 
 
 
 
 
(function(){
 
    function __sanitize(value) {
        return value.sanitize(
            ['&',    '<',   '>',    '\'',    '"'],
            ['&amp;','&lt;','&gt;', '&apos;','&quot;']
        );
    };
 
    function __toXML(o, t) {
        var xml = [];
        switch( typeof o ) {
            case "object":
                if(Object.prototype.toString.apply(o) === '[object Array]') {
                    var a = o;
                    if(a.length === 0) {
                        xml.push("<{tag}/>".substitute({"tag":t}));
                    } else {
                        for(var i = 0, len = a.length; i < len; i++) {
                            xml.push(__toXML(a[i], t));
                        }
                    }
                } else {
                    xml.push("<{tag}".substitute({"tag":t}));
                    var childs = [];
                    for(var p in o) {
                        if(o.hasOwnProperty(p)) {
                            if(p.charAt(0) === "@") xml.push(" {param}='{content}'".substitute({"param":p.substr(1), "content":__sanitize(o[p].toString())}));
                            else childs.push(p);
                        }
                    }
                    if(childs.length === 0) {
                        xml.push("/>");
                    } else {
                        xml.push(">");
                        for(var i = 0, len = childs.length; i < len; i++) {
                            if(p === "#text") { xml.push(__sanitize(o[childs[i]])); }
                            else if(p === "#cdata") { xml.push("<![CDATA[{code}]]>".substitute({"code": o[childs[i]].toString()})); }
                            else if(p.charAt(0) !== "@") { xml.push(__toXML(o[childs[i]], childs[i])); }
                        }
                        xml.push("</{tag}>".substitute({"tag":t}));
                    }
                }
                break;
 
            default:
                var s = o.toString();
                if(s.length === 0) {
                    xml.push("<{tag}/>".substitute({"tag":t}));
                } else {
                    xml.push("<{tag}>{value}</{tag}>".substitute({"tag":t, "value":__sanitize(s)}));
                }
        }
        return xml.join('');
    }
 
    if (typeof JSON.toXML !== 'function') {
        JSON.toXML = function(json, container){
            //container = container || "";
            var xml = [];
            if(container) xml.push("<{tag}>".substitute({"tag":container}));
            for(var p in json) {
                if(json.hasOwnProperty(p)) {
                    xml.push(__toXML(json[p], p));
                }
            }
            if(container) xml.push("</{tag}>".substitute({"tag":container}));
            return xml.join('');
        }
    }
 
})();
 
</script>