nashorn/samples/flexijson.js
author dcubed
Sat, 24 Oct 2015 15:44:08 -0700
changeset 33595 5830c3ae532d
parent 29995 ead3020640fc
permissions -rw-r--r--
8047212: runtime/ParallelClassLoading/bootstrap/random/inner-complex assert(ObjectSynchronizer::verify_objmon_isinpool(inf)) failed: monitor is invalid Summary: Fix race between ObjectMonitor alloc and verification code; teach SA about "static pointer volatile" fields. Reviewed-by: cvarming, dholmes, sspitsyn, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29995
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     1
/*
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     3
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     6
 * are met:
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     7
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    10
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    14
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    18
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    30
 */
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    31
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    32
/*
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    33
 * Hjson - "the Human JSON - A configuration file format that 
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    34
 * caters to humans and helps reduce the errors they make"
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    35
 * See also: http://hjson.org/
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    36
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    37
 * I wanted to see if we can use Nashorn Parser API (jdk9) to support
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    38
 * similar flexible JSON extension with #nashorn. In this FlexiJSON.parse
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    39
 * implementation, Nashorn Parser API is used to validate that the 
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    40
 * extendable flexi JSON is "data only" (i.e., no executable code) and
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    41
 * then 'eval'ed to make an object out of it.
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    42
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    43
 * FlexiJSON allows the following:
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    44
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    45
 *   * single and mutliple line comments anywhere
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    46
 *   * non-quoted property names and values
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    47
 *   * regexp literal values
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    48
 *   * omitting trailing comma
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    49
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    50
 * When nashorn -scripting mode is enabled, FlexiJSON supports these
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    51
 * as well:
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    52
 *
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    53
 *   * shell style # comments
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    54
 *   * multiple line (Unix heredoc style) string values
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    55
 */
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    56
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    57
"use strict";
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    58
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    59
function FlexiJSON() {}
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    60
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    61
// helper to locate Nashorn Parser API classes
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    62
FlexiJSON.treeType = function(name) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    63
    return Java.type("jdk.nashorn.api.tree." + name);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    64
}
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    65
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    66
// Nashorn Parser API classes used
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    67
FlexiJSON.ArrayLiteral = FlexiJSON.treeType("ArrayLiteralTree");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    68
FlexiJSON.ExpressionStatement = FlexiJSON.treeType("ExpressionStatementTree");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    69
FlexiJSON.ObjectLiteral = FlexiJSON.treeType("ObjectLiteralTree");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    70
FlexiJSON.RegExpLiteral = FlexiJSON.treeType("RegExpLiteralTree");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    71
FlexiJSON.Literal = FlexiJSON.treeType("LiteralTree");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    72
FlexiJSON.Parser = FlexiJSON.treeType("Parser");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    73
FlexiJSON.SimpleTreeVisitor = FlexiJSON.treeType("SimpleTreeVisitorES5_1");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    74
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    75
// FlexiJSON.parse API
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    76
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    77
FlexiJSON.parse = function(str) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    78
    var parser = (typeof $OPTIONS == "undefined")? 
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    79
        FlexiJSON.Parser.create() :
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    80
        FlexiJSON.Parser.create("-scripting");
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    81
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    82
    // force the string to be an expression by putting it inside (, )
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    83
    str = "(" + str + ")";
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    84
    var ast = parser.parse("<flexijsondoc>", str, null);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    85
    // Should not happen. parse would have thrown syntax error
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    86
    if (!ast) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    87
        return undefined;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    88
    }
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    89
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    90
    // allowed 'literal' values in flexi JSON
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    91
    function isLiteral(node) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    92
        return node instanceof FlexiJSON.ArrayLiteral ||
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    93
            node instanceof FlexiJSON.Literal ||
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    94
            node instanceof FlexiJSON.ObjectLiteral ||
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    95
            node instanceof FlexiJSON.RegExpLiteral;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    96
    }
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    97
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    98
    var visitor;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    99
    ast.accept(visitor = new (Java.extend(FlexiJSON.SimpleTreeVisitor)) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   100
         lineMap: null,
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   101
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   102
         throwError: function(msg, node) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   103
             if (this.lineMap) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   104
                 var pos = node.startPosition;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   105
                 var line = this.lineMap.getLineNumber(pos);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   106
                 var column = this.lineMap.getColumnNumber(pos);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   107
                 // we introduced extra '(' at start. So, adjust column number
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   108
                 msg = msg + " @ " + line + ":" + (column - 1);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   109
             }
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   110
             throw new TypeError(msg);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   111
         },
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   112
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   113
         visitLiteral: function(node, extra) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   114
             print(node.value);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   115
         },
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   116
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   117
         visitExpressionStatement: function(node, extra) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   118
             var expr = node.expression;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   119
             if (isLiteral(expr)) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   120
                 expr.accept(visitor, extra);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   121
             } else {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   122
                 this.throwError("only literals can occur", expr);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   123
             }
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   124
         },
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   125
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   126
         visitArrayLiteral: function(node, extra) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   127
             for each (var elem in node.elements) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   128
                 if (isLiteral(elem)) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   129
                     elem.accept(visitor, extra);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   130
                 } else {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   131
                     this.throwError("only literal array element value allowed", elem);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   132
                 }
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   133
             }
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   134
         },
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   135
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   136
         visitObjectLiteral: function(node, extra) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   137
             for each (var prop in node.properties) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   138
                 if (prop.getter != null || prop.setter != null) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   139
                     this.throwError("getter/setter property not allowed", node);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   140
                 }
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   141
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   142
                 var value = prop.value;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   143
                 if (isLiteral(value)) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   144
                     value.accept(visitor, extra);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   145
                 } else {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   146
                     this.throwError("only literal property value allowed", value);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   147
                 }
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   148
             }
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   149
         },
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   150
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   151
         visitCompilationUnit: function(node, extra) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   152
             this.lineMap = node.lineMap;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   153
             var elements = node.sourceElements;
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   154
             if (elements.length > 1) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   155
                 this.throwError("more than one top level expression", node.sourceElements[1]);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   156
             } 
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   157
             var stat = node.sourceElements[0];
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   158
             if (! (stat instanceof FlexiJSON.ExpressionStatement)) {
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   159
                 this.throwError("only one top level expresion allowed", stat);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   160
             }
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   161
             stat.accept(visitor, extra);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   162
         },
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   163
    }, null);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   164
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   165
    // safe to eval given string as flexi JSON!
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   166
    return eval(str);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
   167
}