ometa JSON { root = value:a @spaces? end -> a, value = object | array | string | number | boolean, object = "{" pair:l ( "," pair:p { p } )*:r "}" -> [l].concat(r).reduce(function (acc, e) { if (e) acc[e[0]] = e[1]; return acc; }, {}) | "{" "}" -> {}, pair = string:s ":" value:a -> [s, a], array = "[" value:l (",", value)*:r "]" -> { r ? [l].concat(r) : [l] } | "[" "]" -> [], string = "\"" <(~'"' character)*>:s "\"" -> s, character = escape | char, escape = '\\' ( '"' | '\'' | '\\' | '/' | 'b' -> '\b' | 'f' -> '\f' | 'n' -> '\n' | 'r' -> '\r' | 't' -> '\t' | 'u' :s -> String.charCodeAt(parseInt(s, 16)) | char ), number = @space? :n -> parseFloat(n), boolean = "true" -> true | "false" -> false | "null" -> null, spaces = /[ \t\f\r\n\v]+/, token = @spaces? /true|false|null|:|"|'|\{|\}|\[|\]|,/:t -> [ t, t ] } JSON.parse = function parse(s) { return this.matchAll(s, 'root'); }; module.exports = JSON;