nashorn/samples/fjson.js
author vlivanov
Mon, 09 May 2016 12:39:41 +0300
changeset 38358 cb99c6d2af1b
parent 29995 ead3020640fc
permissions -rw-r--r--
Merge
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
// Usage: jjs -scripting flexijson.js fjson.js
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    33
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    34
var obj = FlexiJSON.parse(<<EOF
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    35
// this is a comment
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
    foo: 23,
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    38
    bar: [ 34, 454, 54,],
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    39
    // inline comment here
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    40
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    41
    /** multi line
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    42
        comments are fine too! */
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    43
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    44
    # shell style line comment is fine!
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    45
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    46
    regex: /gdfg/i, // regexp literal
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    47
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    48
    str: <<END
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    49
Multiple line strings via nashorn 
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    50
-scripting mode extension as well
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    51
END
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
EOF)
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    54
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    55
print(obj.foo);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    56
print(obj.bar);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    57
print(obj.regex);
ead3020640fc 8078174: Add few FX and parser API samples for nashorn
sundar
parents:
diff changeset
    58
print(obj.str);