Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: version-0.1.0
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 74 lines (64 sloc) 1.471 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
use v6;
grammar JSON::Tiny::Grammar {
    rule TOP {
        ^ [
            | <object> {*} #= object
            | <array> {*} #= array
        ]$ };
    rule object { '{' ~ '}' <pairlist> {*} };
    rule pairlist {
        [ <pair>
         [\, [ <pair> | <.fail_trailing> ] ]*
        ]?
        {*}
    };

    rule pair {
        <string> ':' <value> {*}
    };

    rule array {
        '[' ~ ']'
            [ # work around non-existing LTM
                [
                    <value>**1
                    [\, [<value> | <.fail_trailing>] ]*
                ]?
                \s*
            ]
        {*}
    };

    rule value {
        | <string> {*} #= string
        | <number> {*} #= number
        | <object> {*} #= object
        | <array> {*} #= array
        | 'true' {*} #= true
        | 'false' {*} #= false
        | 'null' {*} #= null
    };

    token string {
        \" ~ \" ([
| <str>
| \\ <str_escape>
]*) {*}
};

token str {
<-["\\\t\n]>+
    }

    token str_escape {
        [
         <["\\/bfnrt]>
        | u <xdigit>**4
        ] {*}
    };

    token number {
        \- ?
        [ 0 | <[1..9]> <[0..9]>* ]
        [ \. <[0..9]>+ ]?
        [ <[eE]> [\+|\-]? <[0..9]>+ ]?
        {*}
    }

    regex fail_trailing {
        <fail: 'Expecting value after comma (trailing comma?)'>
    }
}

# vim: ft=perl6
Something went wrong with that request. Please try again.