├── .eslintrc ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── benchmark └── benchmark.js ├── bin └── cli.js ├── bower.json ├── dist ├── parser.js ├── uson.min.js └── uson.pack.js ├── examples └── usonrc.js ├── index.js ├── package-lock.json ├── package.json ├── src └── uson.pegjs ├── test ├── cli.js ├── compliance.js ├── compliance │ ├── basic.json │ └── types.json ├── fixtures │ ├── json-pass1.json │ └── usonrc.js └── index.js └── tools ├── test.js ├── testfile.uson └── typing.js /.eslintrc: -------------------------------------------------------------------------------- 1 | env: 2 | browser: true 3 | node: true 4 | 5 | rules: 6 | no-new-object: 2 7 | quote-props: 2 8 | no-array-constructor: 2 9 | quotes: [2, "single"] 10 | indent: [2, 2] 11 | no-multi-str: 2 12 | no-multi-spaces: 2 13 | no-shadow-restricted-names: 2 14 | dot-notation: 2 15 | block-scoped-var: 2 16 | vars-on-top: 2 17 | no-unused-vars: 2 18 | eqeqeq: 2 19 | use-isnan: 2 20 | no-eq-null: 2 21 | // brace-style: 2 22 | spaced-comment: 2 23 | valid-jsdoc: 2 24 | space-infix-ops: 2 25 | eol-last: 2 26 | padded-blocks: [2, "never"] 27 | space-before-blocks: 2 28 | comma-dangle: [2, "never"] 29 | comma-style: 2 30 | semi: [2, always] 31 | semi-spacing: 2 32 | no-extra-boolean-cast: 2 33 | space-before-function-paren: [2, "never"] 34 | no-spaced-func: 2 35 | no-extra-parens: 2 36 | one-var: [2, "never"] 37 | camelcase: 2 38 | new-cap: 2 39 | consistent-this: [1, "_this"] 40 | //func-names: 2 41 | key-spacing: 2 42 | no-dupe-keys: 2 43 | strict: 1 44 | no-process-exit: 0 45 | no-underscore-dangle: 0 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 12 4 | - 11 5 | - 10 6 | - 9 7 | - 8 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | This project adheres to [Semantic Versioning](http://semver.org/). 4 | 5 | ## [Unreleased] 6 | 7 | ## [0.3.2] 8 | ### Added 9 | - [cli] Option `-f, --form` for output to Query string. 10 | 11 | ## [0.3.1] 12 | ### Fixed 13 | - Fix unescaped strings and problems with ending `}`. 14 | 15 | ### Changed 16 | - Allow more characters to use in Type name, now is possible: `a-zA-Z0-9_-`. 17 | 18 | ### Added 19 | - Tests for Type casting and custom types. 20 | 21 | ## [0.3.0] 22 | ### Added 23 | - Type casting with `!` symbol. 24 | - Possibility to define custom types. 25 | - [lib] Add third argument to `parse()` - object with custom datatypes (default = `{}`). 26 | - [cli] Output options `--hex` and `--base64`. 27 | - [cli] Introducing `.usonrc.js` configuration file, which is automatically loaded on cli startup. 28 | - [cli] Option `-u, --usonrc` for specify `.usonrc.js` file. 29 | 30 | ## [0.2.1] 31 | ### Added 32 | - More tests. 33 | 34 | ### Changed 35 | - Extend unescaped string characters. 36 | - Stylistic update of grammar and docs. 37 | 38 | ## [0.2.0] 39 | ### Added 40 | - New `json` mode with JSON mixed root types compatibility. 41 | 42 | ### Changed 43 | - Refactored PEGjs grammar. Now its based on JSON version. 44 | - Most logic moved to PEGjs grammar. 45 | - Fixed comments parsing. 46 | 47 | ### Removed 48 | - [cli] Packages for MsgPack and YAML is now optional. 49 | 50 | ## [0.1.3] 51 | ### Added 52 | - Comments syntax `#`. 53 | - Use JSHint linter with "JavasScript Style Guide" config (see [https://github.com/airbnb/javascript](https://github.com/airbnb/javascript)). 54 | - [cli] New command-line I/O parameters: `-i, --input` and `--output`. 55 | - [cli] MessagePack output via `-m, --msgpack` 56 | - [browser] Minification now use Uglify `--mange` parameter (better compression). 57 | - More documentation. 58 | 59 | ### Changed 60 | - Possibility of quoted keys and use single-quote. 61 | 62 | ## [0.1.2] 63 | ### Added 64 | - Stream support for cli. 65 | - Basic benchmarks. 66 | - More documentation. 67 | 68 | ### Changed 69 | - Replace lodash.assign with ES6 object-assign polyfill. 70 | 71 | ## [0.1.1] - 2015-04-06 72 | ### Added 73 | - Browser version generated by Browserify and minimized with Uglify-JS2. 74 | - Add Bower package. 75 | - Add CHANGELOG.md. 76 | 77 | ### Changed 78 | - Grammar and interpreter optimalizations. 79 | 80 | ## 0.1.0 - 2014-04-05 81 | - Initial release. 82 | 83 | [Unreleased]: https://github.com/burningtree/uson/compare/0.3.2...master 84 | [0.3.2]: https://github.com/burningtree/uson/compare/0.3.1...0.3.2 85 | [0.3.1]: https://github.com/burningtree/uson/compare/0.3.0...0.3.1 86 | [0.3.0]: https://github.com/burningtree/uson/compare/0.2.1...0.3.0 87 | [0.2.1]: https://github.com/burningtree/uson/compare/0.2.0...0.2.1 88 | [0.2.0]: https://github.com/burningtree/uson/compare/0.1.3...0.2.0 89 | [0.1.3]: https://github.com/burningtree/uson/compare/0.1.2...0.1.3 90 | [0.1.2]: https://github.com/burningtree/uson/compare/0.1.1...0.1.2 91 | [0.1.1]: https://github.com/burningtree/uson/compare/0.1.0...0.1.1 92 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jan Stránský 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NODE = node 2 | NPM = npm 3 | PEGJS = node_modules/.bin/pegjs 4 | BROWSERIFY = node_modules/.bin/browserify 5 | UGLIFY = node_modules/.bin/uglifyjs 6 | LINTER = node_modules/.bin/eslint 7 | MOCHA = node_modules/.bin/mocha 8 | 9 | all: build browser 10 | 11 | install: 12 | $(NPM) install 13 | 14 | build: 15 | @make peg lint test-silent 16 | 17 | browser: 18 | @make pack minify 19 | 20 | peg: src/uson.pegjs 21 | $(PEGJS) -O speed -o dist/parser.js $< 22 | 23 | pack: dist/uson.pack.js 24 | $(BROWSERIFY) --standalone USON -o $< index.js 25 | 26 | minify: dist/uson.pack.js 27 | $(UGLIFY) -m -o dist/uson.min.js $< 28 | 29 | bench: benchmark/benchmark.js 30 | $(NODE) $< 31 | 32 | lint: 33 | $(LINTER) index.js bin/cli.js 34 | 35 | test: test/* 36 | $(MOCHA) 37 | 38 | test-silent: 39 | $(MOCHA) -R dot 40 | 41 | help: 42 | @echo "" 43 | @echo " Available commands:" 44 | @echo " all install build browser peg pack minify" 45 | @echo " bench lint test-silent" 46 | @echo "" 47 | 48 | .PHONY: all 49 | 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # μson (uson) 2 | 3 | [![Build Status](https://travis-ci.org/burningtree/uson.svg?branch=master)](https://travis-ci.org/burningtree/uson) [![Dependency Status](https://david-dm.org/burningtree/uson.svg)](https://david-dm.org/burningtree/uson) [![npm](https://img.shields.io/npm/v/uson.svg)](https://www.npmjs.com/package/uson) 4 | 5 | A compact human-readable data serialization format specially designed for shell. 6 | 7 | This format is certainly not intended to replace the classical JSON format, but brings different syntax, for use in environments with specific requirements. 8 | 9 | Main advantage should be in better writability (mostly in the command line), because use less expressive syntax. The purpose is not to create a format that is as small as possible in term of byte size. 10 | 11 | This is initial implementation written in Javascript and node.js. Grammar is written in [PEG](http://en.wikipedia.org/wiki/Parsing_expression_grammar) and parser is generated by [peg.js](http://pegjs.org/). For more info see [Grammar](#grammar). 12 | 13 | * [μson Overview](#%CE%BCson-overview) 14 | * [Node.js module](#nodejs-module) 15 | * [Browser usage](#browser-usage) 16 | * [Command-line tool (CLI)](#command-line-tool-cli) 17 | 18 | ## μson Overview 19 | 20 | * [Introduction](#introduction) 21 | * [Principles](#principles) 22 | * [Output modes](#output-modes) 23 | * [Example](#example) 24 | * [Basic usage](#basic-usage) 25 | * [Standard types](#standard-types) 26 | * [Arrays](#arrays) 27 | * [Objects](#objects) 28 | * [Nested objects](#nested-objects) 29 | * [Type casting](#type-casting) 30 | * [Custom types](#custom-types) 31 | * [Comments](#comments) 32 | * [Grammar](#grammar) 33 | 34 | ### Introduction 35 | 36 | #### Principles 37 | 38 | * Superset of JSON (every JSON is valid μson). 39 | * Whitespace is not significant. 40 | * String quoting `"` is optional. 41 | * In Array or Object, comma `,` can be replaced by whitespace ` `. 42 | * Assignation with colon `:` can be repeated to create nested objects. (see [Nested objects](#nested-objects)). 43 | * You can use own types, casting is done by `!` character. (see [Type casting](#type-casting)). 44 | 45 | #### Output modes 46 | 47 | There are three output modes: 48 | * `array` (default) - Output as array. 49 | * `object` - Output as combined object. Suitable for use in the command line. 50 | * `json` - Output first mixed type. 100% compatible with JSON. 51 | 52 | ### Example 53 | 54 | ``` 55 | endpoint:id:wikipedia pages:[Malta Prague "New York"] 56 | ``` 57 | 58 | Result in JSON (`array` mode): 59 | ```json 60 | [ 61 | { 62 | "endpoint": { 63 | "id": "wikipedia" 64 | } 65 | }, 66 | { 67 | "pages": [ 68 | "Malta", 69 | "Prague", 70 | "New York" 71 | ] 72 | } 73 | ] 74 | ``` 75 | 76 | or in YAML (`array` mode): 77 | ```yaml 78 | - endpoint: 79 | id: wikipedia 80 | - pages: 81 | - Malta 82 | - Prague 83 | - New York 84 | ``` 85 | 86 | and `object` mode result: 87 | ```json 88 | { 89 | "endpoint": { 90 | "id": "wikipedia" 91 | }, 92 | "pages": [ 93 | "Malta", 94 | "Prague", 95 | "New York" 96 | ] 97 | } 98 | ``` 99 | 100 | ### Basic usage 101 | 102 | ``` 103 | expr1 expr2 expr3 .. 104 | ``` 105 | 106 | Supported types: 107 | * false 108 | * null 109 | * true 110 | * array 111 | * object 112 | * number 113 | * string 114 | 115 | Optional: 116 | * regexp TODO 117 | * function TODO 118 | 119 | #### Standard types 120 | 121 | ``` 122 | number:12.05 text:Banana quotedText:"John Devilseed" empty:null good:true 123 | ``` 124 | 125 | Output in `object` mode: 126 | ```json 127 | { 128 | "number": 12.05, 129 | "text": "Banana", 130 | "quotedText": "John Devilseed", 131 | "empty": null, 132 | "good": true 133 | } 134 | ``` 135 | 136 | #### Arrays 137 | 138 | ``` 139 | simple:[1 2 3] texts:[Malta Budapest "New York"] objects:[{id:1}] 140 | ``` 141 | 142 | Output in `object` mode: 143 | ```json 144 | { 145 | "simple": [ 146 | 1, 147 | 2, 148 | 3 149 | ], 150 | "texts": [ 151 | "Malta", 152 | "Budapest", 153 | "New York" 154 | ], 155 | "objects": [ 156 | { 157 | "id": 1 158 | } 159 | ] 160 | } 161 | ``` 162 | 163 | #### Objects 164 | 165 | ``` 166 | obj:{name:John} {nested:[{id:42} value:"Nagano"]} 167 | ``` 168 | 169 | Output in `object` mode: 170 | ```json 171 | { 172 | "obj": { 173 | "name": "John" 174 | }, 175 | "nested": [ 176 | { 177 | "id": 42 178 | }, 179 | { 180 | "value": "Nagano" 181 | } 182 | ] 183 | } 184 | ``` 185 | 186 | #### Nested objects 187 | 188 | You can use standard colon notation for expand objects: 189 | ``` 190 | :(|(:(| .. ))) 191 | ``` 192 | 193 | For example: 194 | ``` 195 | cities:eu:hu:budapest:Budapest 196 | ``` 197 | 198 | become: 199 | ```json 200 | [ 201 | { 202 | "cities": { 203 | "eu": { 204 | "hu": { 205 | "budapest": "Budapest" 206 | } 207 | } 208 | } 209 | } 210 | ] 211 | ``` 212 | 213 | #### Type casting 214 | 215 | If you want to return a value in specific type, you can use this syntax: 216 | ``` 217 | ! 218 | ``` 219 | 220 | For example, this input: 221 | ``` 222 | str!42 223 | ``` 224 | 225 | produce this output: 226 | ``` 227 | ["42"] 228 | ``` 229 | 230 | You can use casting repeatedly: 231 | ``` 232 | str!int!12.42 233 | ``` 234 | 235 | output: 236 | ``` 237 | ["12"] 238 | ``` 239 | 240 | This could be useful especially if you define your [own types](#custom-types). 241 | 242 | ##### Core casting types 243 | 244 | **Scalars:** 245 | * `str` - string 246 | * `int` - integer 247 | * `float` - float 248 | * `null` - null 249 | * `bool` - boolean 250 | * `date` - date & time (ISO 8601 formatting) 251 | 252 | #### Custom types 253 | 254 | If you use library, it's easy to add support for your own types - just pass object with types as third argument to parse(). See [Defining own types](#defining-own-types). 255 | 256 | For CLI you can create `.usonrc.js` file in your home directory `~/`, in which you can define your own types. See [Configuration](#configuration). 257 | 258 | #### Comments 259 | 260 | Comments beginning with `#` and terminates on end of line. 261 | 262 | ``` 263 | array:[1 2 3] # this is comment 264 | ``` 265 | 266 | Output: 267 | ```json 268 | { 269 | "array": [ 270 | 1, 271 | 2, 272 | 3 273 | ] 274 | } 275 | ``` 276 | 277 | ### Grammar 278 | 279 | Basic grammar is adopted from JSON: 280 | 281 | ``` 282 | begin_array = ws "[" ws 283 | begin_object = ws "{" ws 284 | end_array = ws "]" ws 285 | end_object = ws "}" ws 286 | name_separator = ws ":" ws 287 | value_separator = ws [ ,]* ws 288 | comment_start = "#" 289 | ws_char = [ \t\n\r] 290 | ``` 291 | 292 | For more info see [uson.pegjs](src/uson.pegjs) file. 293 | 294 | [Visualization of uson grammar](http://dundalek.com/GrammKit/#https://raw.githubusercontent.com/burningtree/uson/master/src/uson.pegjs). 295 | 296 | ## Node.js module 297 | 298 | * [Compatibility](#compatibility) 299 | * [Installation](#installation) 300 | * [Usage](#usage) 301 | * [Defining own types](#defining-own-types) 302 | 303 | ### Compatibility 304 | 305 | * node.js 0.10+ 306 | * [io.js](https://iojs.org) v1.0.4+ 307 | 308 | ### Installation 309 | 310 | ``` 311 | $ npm install uson 312 | ``` 313 | 314 | ### Usage 315 | 316 | API is almost same as JSON API: 317 | * `USON.parse(str, mode="object", customTypes={})` 318 | * `USON.stringify(obj, replacer=null, level=2)` - in development 319 | 320 | ```javascript 321 | var USON = require('uson'); 322 | console.log(USON.parse('a b c')); 323 | ``` 324 | Output: 325 | ```javascript 326 | [ 'a', 'b', 'c' ] 327 | ``` 328 | 329 | ### Defining own types 330 | 331 | ```javascript 332 | var USON = require('uson'); 333 | var types = { 334 | welcome: function(value) { 335 | return("Hello " + value + "!"); 336 | } 337 | }; 338 | console.log(USON.parse('welcome!john', null, types)); 339 | ``` 340 | Output: 341 | ```javascript 342 | [ 'Hello john!' ] 343 | ``` 344 | 345 | ## Browser usage 346 | 347 | ``` 348 | $ bower install uson 349 | ``` 350 | 351 | ### Usage 352 | 353 | ```html 354 | 355 | 359 | ``` 360 | 361 | ## Command-line tool (CLI) 362 | 363 | * [Installation](#installation-1) 364 | * [Usage](#usage-2) 365 | * [Example](#example-1) 366 | * [Options](#options) 367 | * [Result format (optional)](#result-format-optional) 368 | * [Streams support (pipe)](#streams-support-pipe) 369 | * [Complete usage](#complete-usage) 370 | 371 | 372 | ### Installation 373 | 374 | You can install node.js CLI utility via npm: 375 | ``` 376 | $ npm install -g uson 377 | ``` 378 | 379 | ### Usage 380 | 381 | ``` 382 | $ uson [options] [expression] 383 | ``` 384 | 385 | ### Example 386 | 387 | ``` 388 | $ uson 'user:john age:42' 389 | ``` 390 | 391 | Return: 392 | ```json 393 | [{"user":"john"},{"age":42}] 394 | ``` 395 | 396 | ### Options 397 | 398 | For `object` mode use option `-o, --object`. 399 | 400 | For `json` mode use option `-j, --json`. 401 | 402 | If you want prettyfied output, use option `-p, --pretty`. 403 | 404 | #### Result format 405 | 406 | You can use this output formats: 407 | - JSON (default): `-j, --json` 408 | - [Query string](http://en.wikipedia.org/wiki/Query_string): `-f, --form` (optional) 409 | - [YAML](http://yaml.org): `-y, --yaml` (optional) 410 | - [MessagePack](http://msgpack.org/): `-m, --msgpack` (optional) 411 | 412 | For example, this returns YAML in Object mode: 413 | ``` 414 | $ uson -yo 'endpoint:id:wikipedia' 415 | ``` 416 | 417 | Return: 418 | ```yaml 419 | endpoint: 420 | id: wikipedia 421 | ``` 422 | 423 | ### Configuration 424 | 425 | #### `.usonrc.js` file 426 | 427 | You can create `.usonrc.js` file in your home directory `~/` which may contain your configuration and which is automatically loaded when cli started. Currently it is only possible to define custom data types. 428 | 429 | RC file is normal Javascript (Node.js) script. Output must be stored in `module.exports` variable. 430 | 431 | ##### Example `.usonrc.js` 432 | 433 | ```javascript 434 | var chance = require('chance')(); 435 | 436 | module.exports = { 437 | types: { 438 | g: function(val) { 439 | var args = []; 440 | var cmd = null; 441 | if(typeof val == "object") { 442 | cmd = Object.keys(val)[0]; 443 | args = val[cmd]; 444 | } else { 445 | cmd = val; 446 | } 447 | return chance[cmd] ? chance[cmd](args) : null; 448 | }, 449 | js: function(js) { 450 | return eval(js); 451 | }, 452 | 'hello': function(val) { 453 | return 'Hello '+ val; 454 | } 455 | } 456 | } 457 | ``` 458 | 459 | With this example RC file you can generate random values (with excellent [Chance](http://chancejs.com) library), execute Javascript code or simple say hello: 460 | 461 | ``` 462 | $ uson -op 'calc:js!"36+64" name:g!name ip:g!ip welcome:hello!Mark' 463 | ``` 464 | 465 | And this is result in `object` mode: 466 | 467 | ```json 468 | { 469 | "calc": 100, 470 | "name": "Jeffrey Mendez", 471 | "ip": "237.63.92.106", 472 | "welcome": "Hello Mark" 473 | } 474 | ``` 475 | 476 | ### Streams support (pipe) 477 | 478 | If you dont specify any input or options then input is taken from standard input (stdin). This can be used for "piping" results: 479 | 480 | ``` 481 | $ echo "a b c:[a:42]" | uson | jq .[2].c[0].a 482 | ``` 483 | Result: 484 | 485 | ```json 486 | 42 487 | ``` 488 | 489 | ### Complete usage 490 | 491 | ``` 492 | $ uson --h 493 | 494 | Usage: uson [options] [expression] 495 | 496 | μson (uson) is a shorthand for JSON 497 | 498 | Options: 499 | 500 | -h, --help output usage information 501 | -V, --version output the version number 502 | -o, --object "object" mode 503 | -j, --json "json" mode 504 | -i, --input Load data from file 505 | --output Write output to file 506 | -p, --pretty Pretty print output (only JSON) 507 | -f, --form Return output in form query-string 508 | -y, --yaml Return output in YAML (optional) 509 | -m, --msgpack Return output in msgpack (optional) 510 | -u, --usonrc Use instead of any .usonrc.js 511 | --hex Output in hex encoding 512 | --base64 Output in base64 encoding 513 | 514 | ``` 515 | 516 | ## NPM package stats 517 | [![NPM](https://nodei.co/npm/uson.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/uson/) 518 | 519 | ## Inspiration 520 | Inspired by python CLI utility [jarg](https://github.com/jdp/jarg) by Justin Poliey ([@jdp](https://github.com/jdp)). 521 | 522 | ## Author 523 | Jan Stránský <jan.stransky@arnal.cz> 524 | 525 | ## Licence 526 | MIT 527 | 528 | -------------------------------------------------------------------------------- /benchmark/benchmark.js: -------------------------------------------------------------------------------- 1 | var USON = require('../'); 2 | var Benchmark = require('benchmark'); 3 | var suite = new Benchmark.Suite(); 4 | var fs = require('fs'); 5 | var path = require('path'); 6 | var yaml = require('js-yaml'); 7 | var msgpack = require('msgpack'); 8 | 9 | var jsonFile = fs.readFileSync(path.resolve(__dirname, '../test/fixtures/json-pass1.json')).toString(); 10 | var packageJson = fs.readFileSync(path.resolve(__dirname, '../package.json')).toString(); 11 | var packageObject = JSON.parse(packageJson); 12 | var packageYaml = yaml.dump(packageObject); 13 | var packagePack = msgpack.pack(packageObject); 14 | 15 | suite.add('Super nested', function() { 16 | USON.parse('a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z'); 17 | }); 18 | 19 | suite.add('Parsing package.json (default JSON.stringify()', function() { 20 | JSON.parse(packageJson); 21 | }); 22 | 23 | suite.add('Parsing package.json (YAML)', function() { 24 | yaml.load(packageYaml); 25 | }); 26 | 27 | suite.add('Parsing package.json (msgpack)', function() { 28 | msgpack.unpack(packagePack); 29 | }); 30 | 31 | suite.add('Parsing package.json (uson)', function() { 32 | USON.parse(packageJson); 33 | }); 34 | 35 | suite.add('JSON benchmark', function() { 36 | USON.parse(jsonFile); 37 | }); 38 | 39 | suite.add('Parser only', function() { 40 | USON.parser.parse('"hello"'); 41 | }); 42 | 43 | suite.add('Basic quoted', function() { 44 | USON.parse('"hello"'); 45 | }); 46 | 47 | suite.add('Basic', function() { 48 | USON.parse('a'); 49 | }); 50 | 51 | suite.add('Nested', function() { 52 | USON.parse('a:b:c:d:e:f'); 53 | }); 54 | 55 | suite.on('cycle', function(event) { 56 | console.log(String(event.target)); 57 | }); 58 | 59 | suite.on('complete', function() { 60 | console.log('Fastest is ' + this.filter('fastest').pluck('name')); 61 | }); 62 | 63 | suite.run({ async: true }); 64 | -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | var fs = require('fs'); 5 | var path = require('path'); 6 | var uson = require('../'); 7 | var program = require('commander'); 8 | var pInfo = require('../package.json'); 9 | 10 | var RCFILE = '.usonrc.js'; 11 | 12 | program 13 | .version(pInfo.version) 14 | .description(pInfo.description) 15 | .usage('[options] [expression]') 16 | .option('-o, --object', '"object" mode') 17 | .option('-j, --json', '"json" mode') 18 | .option('-i, --input ', 'Load data from file') 19 | .option(' --output ', 'Write output to file') 20 | .option('-f, --form', 'Return output in form query-string (optional)') 21 | .option('-y, --yaml', 'Return output in YAML (optional)') 22 | .option('-m, --msgpack', 'Return output in msgpack (optional)') 23 | .option('-p, --pretty', 'Pretty print output (only JSON output)') 24 | .option('-u, --usonrc ', 'Use instead of any .usonrc.js') 25 | .option(' --hex', 'Output in hex encoding') 26 | .option(' --base64', 'Output in base64 encoding'); 27 | 28 | function Runtime(cli) { 29 | this.program = cli; 30 | this.availablePlugins = { 31 | 'yaml': 'js-yaml', 32 | 'msgpack': 'msgpack', 33 | 'form': 'qs' 34 | }; 35 | this.plugins = this.loadPlugins() || {}; 36 | this.rc = this.loadRc() || {}; 37 | } 38 | 39 | Runtime.prototype.error = function(str) { 40 | console.log('Error: %s', str); 41 | process.exit(1); 42 | }; 43 | 44 | Runtime.prototype.loadPlugins = function() { 45 | var _this = this; 46 | var plugins = {}; 47 | var config = this.availablePlugins; 48 | Object.keys(config).forEach(function(k) { 49 | if(_this.program[k]) { 50 | try { plugins[k] = require(config[k]); } 51 | catch (e) { 52 | _this.error('Cannot load package: ' + config[k] + ' (' + k + ' mode)\n' + 53 | 'Installation instruction: npm install -g ' + config[k]); 54 | } 55 | } 56 | }); 57 | return plugins; 58 | }; 59 | 60 | Runtime.prototype.loadRc = function() { 61 | var fn = null; 62 | var home = process.env[ 63 | process.platform === 'win32' ? 'USERPROFILE' : 'HOME' 64 | ]; 65 | if(this.program.usonrc) { 66 | fn = path.resolve(this.program.usonrc); 67 | if(fs.existsSync(fn)) { 68 | return require(fn); 69 | } 70 | return this.error('rc file not exists: ' + this.program.usonrc); 71 | } 72 | fn = path.resolve(home, RCFILE); 73 | if(fs.existsSync(fn)) { 74 | return require(fn); 75 | } 76 | }; 77 | 78 | Runtime.prototype.parse = function(input) { 79 | var mode = this.program.object ? 80 | 'object' : this.program.json ? 'json' : false; 81 | 82 | var output = uson.parse(input, mode, this.rc.types); 83 | var space = this.program.pretty ? 2 : false; 84 | 85 | if(this.program.msgpack) { 86 | return this.plugins.msgpack.pack(output); 87 | } 88 | if(this.program.yaml) { 89 | return this.plugins.yaml.dump(output); 90 | } 91 | if(this.program.form) { 92 | return this.plugins.form.stringify(output); 93 | } 94 | return JSON.stringify(output, null, space) + '\n'; 95 | }; 96 | 97 | 98 | Runtime.prototype.listenStdin = function() { 99 | var _this = this; 100 | process.stdin.on('data', function(buf) { 101 | var str = buf.toString().trim(); 102 | if(!str) { return; } 103 | _this.process(str); 104 | }); 105 | process.stdin.on('end', function() { 106 | process.exit(); 107 | }); 108 | }; 109 | 110 | Runtime.prototype.writeData = function(data) { 111 | if(this.program.output) { 112 | if(fs.existsSync(this.program.output)) { 113 | return this.error('File exists: ' + this.program.output + ', exiting ..'); 114 | } 115 | fs.writeFileSync(this.program.output, data); 116 | console.log('File saved: ' + this.program.output); 117 | return true; 118 | } 119 | if(this.program.hex) { 120 | data = new Buffer(data).toString('hex') + '\n'; 121 | } else if(this.program.base64) { 122 | data = new Buffer(data).toString('base64') + '\n'; 123 | } 124 | process.stdout.write(data); 125 | }; 126 | 127 | Runtime.prototype.process = function(data) { 128 | this.writeData(this.parse(data)); 129 | }; 130 | 131 | (function runProgram(cli) { 132 | var runtime = new Runtime(cli); 133 | var data; 134 | 135 | if(program.input) { 136 | if(!fs.existsSync(program.input)) { 137 | runtime.error('File not exists: ' + program.input); 138 | } 139 | data = fs.readFileSync(program.input).toString(); 140 | runtime.process(data); 141 | } 142 | 143 | else if(program.args.length < 1) { 144 | runtime.listenStdin(); 145 | } else { 146 | runtime.process(program.args.join(' ')); 147 | } 148 | })(program.parse(process.argv)); 149 | 150 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uson", 3 | "main": "dist/uson.min.js", 4 | "version": "0.3.2", 5 | "homepage": "https://github.com/burningtree/uson", 6 | "authors": [ 7 | "Jan Stránský " 8 | ], 9 | "description": "μson (uson) is a shorthand for JSON", 10 | "keywords": [ 11 | "serialization", 12 | "json", 13 | "yaml" 14 | ], 15 | "license": "MIT", 16 | "ignore": [ 17 | "**/.*", 18 | "node_modules", 19 | "bower_components", 20 | "test", 21 | "tests", 22 | "bin" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /dist/parser.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Generated by PEG.js 0.10.0. 3 | * 4 | * http://pegjs.org/ 5 | */ 6 | 7 | "use strict"; 8 | 9 | function peg$subclass(child, parent) { 10 | function ctor() { this.constructor = child; } 11 | ctor.prototype = parent.prototype; 12 | child.prototype = new ctor(); 13 | } 14 | 15 | function peg$SyntaxError(message, expected, found, location) { 16 | this.message = message; 17 | this.expected = expected; 18 | this.found = found; 19 | this.location = location; 20 | this.name = "SyntaxError"; 21 | 22 | if (typeof Error.captureStackTrace === "function") { 23 | Error.captureStackTrace(this, peg$SyntaxError); 24 | } 25 | } 26 | 27 | peg$subclass(peg$SyntaxError, Error); 28 | 29 | peg$SyntaxError.buildMessage = function(expected, found) { 30 | var DESCRIBE_EXPECTATION_FNS = { 31 | literal: function(expectation) { 32 | return "\"" + literalEscape(expectation.text) + "\""; 33 | }, 34 | 35 | "class": function(expectation) { 36 | var escapedParts = "", 37 | i; 38 | 39 | for (i = 0; i < expectation.parts.length; i++) { 40 | escapedParts += expectation.parts[i] instanceof Array 41 | ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) 42 | : classEscape(expectation.parts[i]); 43 | } 44 | 45 | return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; 46 | }, 47 | 48 | any: function(expectation) { 49 | return "any character"; 50 | }, 51 | 52 | end: function(expectation) { 53 | return "end of input"; 54 | }, 55 | 56 | other: function(expectation) { 57 | return expectation.description; 58 | } 59 | }; 60 | 61 | function hex(ch) { 62 | return ch.charCodeAt(0).toString(16).toUpperCase(); 63 | } 64 | 65 | function literalEscape(s) { 66 | return s 67 | .replace(/\\/g, '\\\\') 68 | .replace(/"/g, '\\"') 69 | .replace(/\0/g, '\\0') 70 | .replace(/\t/g, '\\t') 71 | .replace(/\n/g, '\\n') 72 | .replace(/\r/g, '\\r') 73 | .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) 74 | .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); 75 | } 76 | 77 | function classEscape(s) { 78 | return s 79 | .replace(/\\/g, '\\\\') 80 | .replace(/\]/g, '\\]') 81 | .replace(/\^/g, '\\^') 82 | .replace(/-/g, '\\-') 83 | .replace(/\0/g, '\\0') 84 | .replace(/\t/g, '\\t') 85 | .replace(/\n/g, '\\n') 86 | .replace(/\r/g, '\\r') 87 | .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) 88 | .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); 89 | } 90 | 91 | function describeExpectation(expectation) { 92 | return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); 93 | } 94 | 95 | function describeExpected(expected) { 96 | var descriptions = new Array(expected.length), 97 | i, j; 98 | 99 | for (i = 0; i < expected.length; i++) { 100 | descriptions[i] = describeExpectation(expected[i]); 101 | } 102 | 103 | descriptions.sort(); 104 | 105 | if (descriptions.length > 0) { 106 | for (i = 1, j = 1; i < descriptions.length; i++) { 107 | if (descriptions[i - 1] !== descriptions[i]) { 108 | descriptions[j] = descriptions[i]; 109 | j++; 110 | } 111 | } 112 | descriptions.length = j; 113 | } 114 | 115 | switch (descriptions.length) { 116 | case 1: 117 | return descriptions[0]; 118 | 119 | case 2: 120 | return descriptions[0] + " or " + descriptions[1]; 121 | 122 | default: 123 | return descriptions.slice(0, -1).join(", ") 124 | + ", or " 125 | + descriptions[descriptions.length - 1]; 126 | } 127 | } 128 | 129 | function describeFound(found) { 130 | return found ? "\"" + literalEscape(found) + "\"" : "end of input"; 131 | } 132 | 133 | return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; 134 | }; 135 | 136 | function peg$parse(input, options) { 137 | options = options !== void 0 ? options : {}; 138 | 139 | var peg$FAILED = {}, 140 | 141 | peg$startRuleFunctions = { uson_text: peg$parseuson_text }, 142 | peg$startRuleFunction = peg$parseuson_text, 143 | 144 | peg$c0 = function(head, tail) { 145 | if(head==null && text()!=="null"){ return [] }; 146 | return [head].concat(tail); 147 | }, 148 | peg$c1 = function(v) {return v}, 149 | peg$c2 = "[", 150 | peg$c3 = peg$literalExpectation("[", false), 151 | peg$c4 = "{", 152 | peg$c5 = peg$literalExpectation("{", false), 153 | peg$c6 = "]", 154 | peg$c7 = peg$literalExpectation("]", false), 155 | peg$c8 = "}", 156 | peg$c9 = peg$literalExpectation("}", false), 157 | peg$c10 = ":", 158 | peg$c11 = peg$literalExpectation(":", false), 159 | peg$c12 = /^[ ,]/, 160 | peg$c13 = peg$classExpectation([" ", ","], false, false), 161 | peg$c14 = "#", 162 | peg$c15 = peg$literalExpectation("#", false), 163 | peg$c16 = "!", 164 | peg$c17 = peg$literalExpectation("!", false), 165 | peg$c18 = /^[ \t\n\r]/, 166 | peg$c19 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false), 167 | peg$c20 = peg$otherExpectation("whitespace"), 168 | peg$c21 = "false", 169 | peg$c22 = peg$literalExpectation("false", false), 170 | peg$c23 = function() { return false; }, 171 | peg$c24 = "null", 172 | peg$c25 = peg$literalExpectation("null", false), 173 | peg$c26 = function() { return null; }, 174 | peg$c27 = "true", 175 | peg$c28 = peg$literalExpectation("true", false), 176 | peg$c29 = function() { return true; }, 177 | peg$c30 = function(first, m) { return m; }, 178 | peg$c31 = function(first, rest) { 179 | var result = {}, i; 180 | result[first.name] = first.value; 181 | for (i = 0; i < rest.length; i++) { 182 | result[rest[i].name] = rest[i].value; 183 | } 184 | return result; 185 | }, 186 | peg$c32 = function(members) { return members !== null ? members: {}; }, 187 | peg$c33 = function(name, value) { 188 | return { name: name, value: value }; 189 | }, 190 | peg$c34 = function(first, v) { return v; }, 191 | peg$c35 = function(first, rest) { return [first].concat(rest); }, 192 | peg$c36 = function(values) { return values !== null ? values : []; }, 193 | peg$c37 = peg$otherExpectation("number"), 194 | peg$c38 = function() { return parseFloat(text()); }, 195 | peg$c39 = ".", 196 | peg$c40 = peg$literalExpectation(".", false), 197 | peg$c41 = /^[1-9]/, 198 | peg$c42 = peg$classExpectation([["1", "9"]], false, false), 199 | peg$c43 = /^[eE]/, 200 | peg$c44 = peg$classExpectation(["e", "E"], false, false), 201 | peg$c45 = "-", 202 | peg$c46 = peg$literalExpectation("-", false), 203 | peg$c47 = "+", 204 | peg$c48 = peg$literalExpectation("+", false), 205 | peg$c49 = "0", 206 | peg$c50 = peg$literalExpectation("0", false), 207 | peg$c51 = peg$otherExpectation("string"), 208 | peg$c52 = function(v) { 209 | var res = v.join(""); 210 | return (res.match(/^[0-9\.]+$/) ? Number(res) : res); 211 | }, 212 | peg$c53 = "'", 213 | peg$c54 = peg$literalExpectation("'", false), 214 | peg$c55 = function(v) { return v.join(""); }, 215 | peg$c56 = "\"", 216 | peg$c57 = peg$literalExpectation("\"", false), 217 | peg$c58 = "\\", 218 | peg$c59 = peg$literalExpectation("\\", false), 219 | peg$c60 = "/", 220 | peg$c61 = peg$literalExpectation("/", false), 221 | peg$c62 = "b", 222 | peg$c63 = peg$literalExpectation("b", false), 223 | peg$c64 = function() { return "\b"; }, 224 | peg$c65 = "f", 225 | peg$c66 = peg$literalExpectation("f", false), 226 | peg$c67 = function() { return "\f"; }, 227 | peg$c68 = "n", 228 | peg$c69 = peg$literalExpectation("n", false), 229 | peg$c70 = function() { return "\n"; }, 230 | peg$c71 = "r", 231 | peg$c72 = peg$literalExpectation("r", false), 232 | peg$c73 = function() { return "\r"; }, 233 | peg$c74 = "t", 234 | peg$c75 = peg$literalExpectation("t", false), 235 | peg$c76 = function() { return "\t"; }, 236 | peg$c77 = "u", 237 | peg$c78 = peg$literalExpectation("u", false), 238 | peg$c79 = function(digits) { 239 | return String.fromCharCode(parseInt(digits, 16)); 240 | }, 241 | peg$c80 = function(sequence) { return sequence; }, 242 | peg$c81 = /^[!$-+\--9;-Z\^-z|~-\u10FFFF]/, 243 | peg$c82 = peg$classExpectation(["!", ["$", "+"], ["-", "9"], [";", "Z"], ["^", "z"], "|", ["~", "\u10FF"], "F", "F"], false, false), 244 | peg$c83 = /^[ -!#-[\]-\u10FFFF]/, 245 | peg$c84 = peg$classExpectation([[" ", "!"], ["#", "["], ["]", "\u10FF"], "F", "F"], false, false), 246 | peg$c85 = /^[ -&(-[\]-\u10FFFF]/, 247 | peg$c86 = peg$classExpectation([[" ", "&"], ["(", "["], ["]", "\u10FF"], "F", "F"], false, false), 248 | peg$c87 = function(m) {var obj={}; obj[m.name] = m.value; return obj}, 249 | peg$c88 = /^[a-zA-Z0-9_\-]/, 250 | peg$c89 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_", "-"], false, false), 251 | peg$c90 = function(name, value) { 252 | var jname = name.join(''); 253 | if(options.type && options.type[jname]) { 254 | return options.type[jname](value, jname); 255 | } 256 | return value; 257 | }, 258 | peg$c91 = /^[^\n\r\u2028\u2029]/, 259 | peg$c92 = peg$classExpectation(["\n", "\r", "\u2028", "\u2029"], true, false), 260 | peg$c93 = /^[0-9]/, 261 | peg$c94 = peg$classExpectation([["0", "9"]], false, false), 262 | peg$c95 = /^[0-9a-f]/i, 263 | peg$c96 = peg$classExpectation([["0", "9"], ["a", "f"]], false, true), 264 | 265 | peg$currPos = 0, 266 | peg$savedPos = 0, 267 | peg$posDetailsCache = [{ line: 1, column: 1 }], 268 | peg$maxFailPos = 0, 269 | peg$maxFailExpected = [], 270 | peg$silentFails = 0, 271 | 272 | peg$result; 273 | 274 | if ("startRule" in options) { 275 | if (!(options.startRule in peg$startRuleFunctions)) { 276 | throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); 277 | } 278 | 279 | peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; 280 | } 281 | 282 | function text() { 283 | return input.substring(peg$savedPos, peg$currPos); 284 | } 285 | 286 | function location() { 287 | return peg$computeLocation(peg$savedPos, peg$currPos); 288 | } 289 | 290 | function expected(description, location) { 291 | location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) 292 | 293 | throw peg$buildStructuredError( 294 | [peg$otherExpectation(description)], 295 | input.substring(peg$savedPos, peg$currPos), 296 | location 297 | ); 298 | } 299 | 300 | function error(message, location) { 301 | location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) 302 | 303 | throw peg$buildSimpleError(message, location); 304 | } 305 | 306 | function peg$literalExpectation(text, ignoreCase) { 307 | return { type: "literal", text: text, ignoreCase: ignoreCase }; 308 | } 309 | 310 | function peg$classExpectation(parts, inverted, ignoreCase) { 311 | return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; 312 | } 313 | 314 | function peg$anyExpectation() { 315 | return { type: "any" }; 316 | } 317 | 318 | function peg$endExpectation() { 319 | return { type: "end" }; 320 | } 321 | 322 | function peg$otherExpectation(description) { 323 | return { type: "other", description: description }; 324 | } 325 | 326 | function peg$computePosDetails(pos) { 327 | var details = peg$posDetailsCache[pos], p; 328 | 329 | if (details) { 330 | return details; 331 | } else { 332 | p = pos - 1; 333 | while (!peg$posDetailsCache[p]) { 334 | p--; 335 | } 336 | 337 | details = peg$posDetailsCache[p]; 338 | details = { 339 | line: details.line, 340 | column: details.column 341 | }; 342 | 343 | while (p < pos) { 344 | if (input.charCodeAt(p) === 10) { 345 | details.line++; 346 | details.column = 1; 347 | } else { 348 | details.column++; 349 | } 350 | 351 | p++; 352 | } 353 | 354 | peg$posDetailsCache[pos] = details; 355 | return details; 356 | } 357 | } 358 | 359 | function peg$computeLocation(startPos, endPos) { 360 | var startPosDetails = peg$computePosDetails(startPos), 361 | endPosDetails = peg$computePosDetails(endPos); 362 | 363 | return { 364 | start: { 365 | offset: startPos, 366 | line: startPosDetails.line, 367 | column: startPosDetails.column 368 | }, 369 | end: { 370 | offset: endPos, 371 | line: endPosDetails.line, 372 | column: endPosDetails.column 373 | } 374 | }; 375 | } 376 | 377 | function peg$fail(expected) { 378 | if (peg$currPos < peg$maxFailPos) { return; } 379 | 380 | if (peg$currPos > peg$maxFailPos) { 381 | peg$maxFailPos = peg$currPos; 382 | peg$maxFailExpected = []; 383 | } 384 | 385 | peg$maxFailExpected.push(expected); 386 | } 387 | 388 | function peg$buildSimpleError(message, location) { 389 | return new peg$SyntaxError(message, null, null, location); 390 | } 391 | 392 | function peg$buildStructuredError(expected, found, location) { 393 | return new peg$SyntaxError( 394 | peg$SyntaxError.buildMessage(expected, found), 395 | expected, 396 | found, 397 | location 398 | ); 399 | } 400 | 401 | function peg$parseuson_text() { 402 | var s0, s1, s2, s3, s4; 403 | 404 | s0 = peg$currPos; 405 | s1 = peg$parseexpr(); 406 | if (s1 === peg$FAILED) { 407 | s1 = null; 408 | } 409 | if (s1 !== peg$FAILED) { 410 | s2 = peg$parsews(); 411 | if (s2 !== peg$FAILED) { 412 | s3 = []; 413 | s4 = peg$parseexpr(); 414 | while (s4 !== peg$FAILED) { 415 | s3.push(s4); 416 | s4 = peg$parseexpr(); 417 | } 418 | if (s3 !== peg$FAILED) { 419 | peg$savedPos = s0; 420 | s1 = peg$c0(s1, s3); 421 | s0 = s1; 422 | } else { 423 | peg$currPos = s0; 424 | s0 = peg$FAILED; 425 | } 426 | } else { 427 | peg$currPos = s0; 428 | s0 = peg$FAILED; 429 | } 430 | } else { 431 | peg$currPos = s0; 432 | s0 = peg$FAILED; 433 | } 434 | 435 | return s0; 436 | } 437 | 438 | function peg$parseexpr() { 439 | var s0, s1, s2, s3; 440 | 441 | s0 = peg$currPos; 442 | s1 = peg$parsews(); 443 | if (s1 !== peg$FAILED) { 444 | s2 = peg$parsevalue(); 445 | if (s2 !== peg$FAILED) { 446 | s3 = peg$parsews(); 447 | if (s3 !== peg$FAILED) { 448 | peg$savedPos = s0; 449 | s1 = peg$c1(s2); 450 | s0 = s1; 451 | } else { 452 | peg$currPos = s0; 453 | s0 = peg$FAILED; 454 | } 455 | } else { 456 | peg$currPos = s0; 457 | s0 = peg$FAILED; 458 | } 459 | } else { 460 | peg$currPos = s0; 461 | s0 = peg$FAILED; 462 | } 463 | 464 | return s0; 465 | } 466 | 467 | function peg$parsebegin_array() { 468 | var s0, s1, s2, s3; 469 | 470 | s0 = peg$currPos; 471 | s1 = peg$parsews(); 472 | if (s1 !== peg$FAILED) { 473 | if (input.charCodeAt(peg$currPos) === 91) { 474 | s2 = peg$c2; 475 | peg$currPos++; 476 | } else { 477 | s2 = peg$FAILED; 478 | if (peg$silentFails === 0) { peg$fail(peg$c3); } 479 | } 480 | if (s2 !== peg$FAILED) { 481 | s3 = peg$parsews(); 482 | if (s3 !== peg$FAILED) { 483 | s1 = [s1, s2, s3]; 484 | s0 = s1; 485 | } else { 486 | peg$currPos = s0; 487 | s0 = peg$FAILED; 488 | } 489 | } else { 490 | peg$currPos = s0; 491 | s0 = peg$FAILED; 492 | } 493 | } else { 494 | peg$currPos = s0; 495 | s0 = peg$FAILED; 496 | } 497 | 498 | return s0; 499 | } 500 | 501 | function peg$parsebegin_object() { 502 | var s0, s1, s2, s3; 503 | 504 | s0 = peg$currPos; 505 | s1 = peg$parsews(); 506 | if (s1 !== peg$FAILED) { 507 | if (input.charCodeAt(peg$currPos) === 123) { 508 | s2 = peg$c4; 509 | peg$currPos++; 510 | } else { 511 | s2 = peg$FAILED; 512 | if (peg$silentFails === 0) { peg$fail(peg$c5); } 513 | } 514 | if (s2 !== peg$FAILED) { 515 | s3 = peg$parsews(); 516 | if (s3 !== peg$FAILED) { 517 | s1 = [s1, s2, s3]; 518 | s0 = s1; 519 | } else { 520 | peg$currPos = s0; 521 | s0 = peg$FAILED; 522 | } 523 | } else { 524 | peg$currPos = s0; 525 | s0 = peg$FAILED; 526 | } 527 | } else { 528 | peg$currPos = s0; 529 | s0 = peg$FAILED; 530 | } 531 | 532 | return s0; 533 | } 534 | 535 | function peg$parseend_array() { 536 | var s0, s1, s2, s3; 537 | 538 | s0 = peg$currPos; 539 | s1 = peg$parsews(); 540 | if (s1 !== peg$FAILED) { 541 | if (input.charCodeAt(peg$currPos) === 93) { 542 | s2 = peg$c6; 543 | peg$currPos++; 544 | } else { 545 | s2 = peg$FAILED; 546 | if (peg$silentFails === 0) { peg$fail(peg$c7); } 547 | } 548 | if (s2 !== peg$FAILED) { 549 | s3 = peg$parsews(); 550 | if (s3 !== peg$FAILED) { 551 | s1 = [s1, s2, s3]; 552 | s0 = s1; 553 | } else { 554 | peg$currPos = s0; 555 | s0 = peg$FAILED; 556 | } 557 | } else { 558 | peg$currPos = s0; 559 | s0 = peg$FAILED; 560 | } 561 | } else { 562 | peg$currPos = s0; 563 | s0 = peg$FAILED; 564 | } 565 | 566 | return s0; 567 | } 568 | 569 | function peg$parseend_object() { 570 | var s0, s1, s2, s3; 571 | 572 | s0 = peg$currPos; 573 | s1 = peg$parsews(); 574 | if (s1 !== peg$FAILED) { 575 | if (input.charCodeAt(peg$currPos) === 125) { 576 | s2 = peg$c8; 577 | peg$currPos++; 578 | } else { 579 | s2 = peg$FAILED; 580 | if (peg$silentFails === 0) { peg$fail(peg$c9); } 581 | } 582 | if (s2 !== peg$FAILED) { 583 | s3 = peg$parsews(); 584 | if (s3 !== peg$FAILED) { 585 | s1 = [s1, s2, s3]; 586 | s0 = s1; 587 | } else { 588 | peg$currPos = s0; 589 | s0 = peg$FAILED; 590 | } 591 | } else { 592 | peg$currPos = s0; 593 | s0 = peg$FAILED; 594 | } 595 | } else { 596 | peg$currPos = s0; 597 | s0 = peg$FAILED; 598 | } 599 | 600 | return s0; 601 | } 602 | 603 | function peg$parsename_separator() { 604 | var s0, s1, s2, s3; 605 | 606 | s0 = peg$currPos; 607 | s1 = peg$parsews(); 608 | if (s1 !== peg$FAILED) { 609 | if (input.charCodeAt(peg$currPos) === 58) { 610 | s2 = peg$c10; 611 | peg$currPos++; 612 | } else { 613 | s2 = peg$FAILED; 614 | if (peg$silentFails === 0) { peg$fail(peg$c11); } 615 | } 616 | if (s2 !== peg$FAILED) { 617 | s3 = peg$parsews(); 618 | if (s3 !== peg$FAILED) { 619 | s1 = [s1, s2, s3]; 620 | s0 = s1; 621 | } else { 622 | peg$currPos = s0; 623 | s0 = peg$FAILED; 624 | } 625 | } else { 626 | peg$currPos = s0; 627 | s0 = peg$FAILED; 628 | } 629 | } else { 630 | peg$currPos = s0; 631 | s0 = peg$FAILED; 632 | } 633 | 634 | return s0; 635 | } 636 | 637 | function peg$parsevalue_separator() { 638 | var s0, s1, s2, s3; 639 | 640 | s0 = peg$currPos; 641 | s1 = peg$parsews(); 642 | if (s1 !== peg$FAILED) { 643 | s2 = []; 644 | if (peg$c12.test(input.charAt(peg$currPos))) { 645 | s3 = input.charAt(peg$currPos); 646 | peg$currPos++; 647 | } else { 648 | s3 = peg$FAILED; 649 | if (peg$silentFails === 0) { peg$fail(peg$c13); } 650 | } 651 | while (s3 !== peg$FAILED) { 652 | s2.push(s3); 653 | if (peg$c12.test(input.charAt(peg$currPos))) { 654 | s3 = input.charAt(peg$currPos); 655 | peg$currPos++; 656 | } else { 657 | s3 = peg$FAILED; 658 | if (peg$silentFails === 0) { peg$fail(peg$c13); } 659 | } 660 | } 661 | if (s2 !== peg$FAILED) { 662 | s3 = peg$parsews(); 663 | if (s3 !== peg$FAILED) { 664 | s1 = [s1, s2, s3]; 665 | s0 = s1; 666 | } else { 667 | peg$currPos = s0; 668 | s0 = peg$FAILED; 669 | } 670 | } else { 671 | peg$currPos = s0; 672 | s0 = peg$FAILED; 673 | } 674 | } else { 675 | peg$currPos = s0; 676 | s0 = peg$FAILED; 677 | } 678 | 679 | return s0; 680 | } 681 | 682 | function peg$parsecomment_start() { 683 | var s0; 684 | 685 | if (input.charCodeAt(peg$currPos) === 35) { 686 | s0 = peg$c14; 687 | peg$currPos++; 688 | } else { 689 | s0 = peg$FAILED; 690 | if (peg$silentFails === 0) { peg$fail(peg$c15); } 691 | } 692 | 693 | return s0; 694 | } 695 | 696 | function peg$parsetyped_start() { 697 | var s0, s1, s2, s3; 698 | 699 | s0 = peg$currPos; 700 | s1 = peg$parsews(); 701 | if (s1 !== peg$FAILED) { 702 | if (input.charCodeAt(peg$currPos) === 33) { 703 | s2 = peg$c16; 704 | peg$currPos++; 705 | } else { 706 | s2 = peg$FAILED; 707 | if (peg$silentFails === 0) { peg$fail(peg$c17); } 708 | } 709 | if (s2 !== peg$FAILED) { 710 | s3 = peg$parsews(); 711 | if (s3 !== peg$FAILED) { 712 | s1 = [s1, s2, s3]; 713 | s0 = s1; 714 | } else { 715 | peg$currPos = s0; 716 | s0 = peg$FAILED; 717 | } 718 | } else { 719 | peg$currPos = s0; 720 | s0 = peg$FAILED; 721 | } 722 | } else { 723 | peg$currPos = s0; 724 | s0 = peg$FAILED; 725 | } 726 | 727 | return s0; 728 | } 729 | 730 | function peg$parsews_char() { 731 | var s0; 732 | 733 | if (peg$c18.test(input.charAt(peg$currPos))) { 734 | s0 = input.charAt(peg$currPos); 735 | peg$currPos++; 736 | } else { 737 | s0 = peg$FAILED; 738 | if (peg$silentFails === 0) { peg$fail(peg$c19); } 739 | } 740 | 741 | return s0; 742 | } 743 | 744 | function peg$parsews() { 745 | var s0, s1, s2; 746 | 747 | peg$silentFails++; 748 | s0 = peg$currPos; 749 | s1 = []; 750 | s2 = peg$parsews_char(); 751 | while (s2 !== peg$FAILED) { 752 | s1.push(s2); 753 | s2 = peg$parsews_char(); 754 | } 755 | if (s1 !== peg$FAILED) { 756 | s2 = peg$parsecomment(); 757 | if (s2 === peg$FAILED) { 758 | s2 = null; 759 | } 760 | if (s2 !== peg$FAILED) { 761 | s1 = [s1, s2]; 762 | s0 = s1; 763 | } else { 764 | peg$currPos = s0; 765 | s0 = peg$FAILED; 766 | } 767 | } else { 768 | peg$currPos = s0; 769 | s0 = peg$FAILED; 770 | } 771 | peg$silentFails--; 772 | if (s0 === peg$FAILED) { 773 | s1 = peg$FAILED; 774 | if (peg$silentFails === 0) { peg$fail(peg$c20); } 775 | } 776 | 777 | return s0; 778 | } 779 | 780 | function peg$parsevalue() { 781 | var s0; 782 | 783 | s0 = peg$parsetyped(); 784 | if (s0 === peg$FAILED) { 785 | s0 = peg$parsefalse(); 786 | if (s0 === peg$FAILED) { 787 | s0 = peg$parsenull(); 788 | if (s0 === peg$FAILED) { 789 | s0 = peg$parsetrue(); 790 | if (s0 === peg$FAILED) { 791 | s0 = peg$parseassign(); 792 | if (s0 === peg$FAILED) { 793 | s0 = peg$parseobject(); 794 | if (s0 === peg$FAILED) { 795 | s0 = peg$parsearray(); 796 | if (s0 === peg$FAILED) { 797 | s0 = peg$parsestring(); 798 | if (s0 === peg$FAILED) { 799 | s0 = peg$parsenumber(); 800 | } 801 | } 802 | } 803 | } 804 | } 805 | } 806 | } 807 | } 808 | 809 | return s0; 810 | } 811 | 812 | function peg$parsefalse() { 813 | var s0, s1; 814 | 815 | s0 = peg$currPos; 816 | if (input.substr(peg$currPos, 5) === peg$c21) { 817 | s1 = peg$c21; 818 | peg$currPos += 5; 819 | } else { 820 | s1 = peg$FAILED; 821 | if (peg$silentFails === 0) { peg$fail(peg$c22); } 822 | } 823 | if (s1 !== peg$FAILED) { 824 | peg$savedPos = s0; 825 | s1 = peg$c23(); 826 | } 827 | s0 = s1; 828 | 829 | return s0; 830 | } 831 | 832 | function peg$parsenull() { 833 | var s0, s1; 834 | 835 | s0 = peg$currPos; 836 | if (input.substr(peg$currPos, 4) === peg$c24) { 837 | s1 = peg$c24; 838 | peg$currPos += 4; 839 | } else { 840 | s1 = peg$FAILED; 841 | if (peg$silentFails === 0) { peg$fail(peg$c25); } 842 | } 843 | if (s1 !== peg$FAILED) { 844 | peg$savedPos = s0; 845 | s1 = peg$c26(); 846 | } 847 | s0 = s1; 848 | 849 | return s0; 850 | } 851 | 852 | function peg$parsetrue() { 853 | var s0, s1; 854 | 855 | s0 = peg$currPos; 856 | if (input.substr(peg$currPos, 4) === peg$c27) { 857 | s1 = peg$c27; 858 | peg$currPos += 4; 859 | } else { 860 | s1 = peg$FAILED; 861 | if (peg$silentFails === 0) { peg$fail(peg$c28); } 862 | } 863 | if (s1 !== peg$FAILED) { 864 | peg$savedPos = s0; 865 | s1 = peg$c29(); 866 | } 867 | s0 = s1; 868 | 869 | return s0; 870 | } 871 | 872 | function peg$parseobject() { 873 | var s0, s1, s2, s3, s4, s5, s6, s7; 874 | 875 | s0 = peg$currPos; 876 | s1 = peg$parsebegin_object(); 877 | if (s1 !== peg$FAILED) { 878 | s2 = peg$currPos; 879 | s3 = peg$parsemember(); 880 | if (s3 !== peg$FAILED) { 881 | s4 = []; 882 | s5 = peg$currPos; 883 | s6 = peg$parsevalue_separator(); 884 | if (s6 !== peg$FAILED) { 885 | s7 = peg$parsemember(); 886 | if (s7 !== peg$FAILED) { 887 | peg$savedPos = s5; 888 | s6 = peg$c30(s3, s7); 889 | s5 = s6; 890 | } else { 891 | peg$currPos = s5; 892 | s5 = peg$FAILED; 893 | } 894 | } else { 895 | peg$currPos = s5; 896 | s5 = peg$FAILED; 897 | } 898 | while (s5 !== peg$FAILED) { 899 | s4.push(s5); 900 | s5 = peg$currPos; 901 | s6 = peg$parsevalue_separator(); 902 | if (s6 !== peg$FAILED) { 903 | s7 = peg$parsemember(); 904 | if (s7 !== peg$FAILED) { 905 | peg$savedPos = s5; 906 | s6 = peg$c30(s3, s7); 907 | s5 = s6; 908 | } else { 909 | peg$currPos = s5; 910 | s5 = peg$FAILED; 911 | } 912 | } else { 913 | peg$currPos = s5; 914 | s5 = peg$FAILED; 915 | } 916 | } 917 | if (s4 !== peg$FAILED) { 918 | peg$savedPos = s2; 919 | s3 = peg$c31(s3, s4); 920 | s2 = s3; 921 | } else { 922 | peg$currPos = s2; 923 | s2 = peg$FAILED; 924 | } 925 | } else { 926 | peg$currPos = s2; 927 | s2 = peg$FAILED; 928 | } 929 | if (s2 === peg$FAILED) { 930 | s2 = null; 931 | } 932 | if (s2 !== peg$FAILED) { 933 | s3 = peg$parseend_object(); 934 | if (s3 !== peg$FAILED) { 935 | peg$savedPos = s0; 936 | s1 = peg$c32(s2); 937 | s0 = s1; 938 | } else { 939 | peg$currPos = s0; 940 | s0 = peg$FAILED; 941 | } 942 | } else { 943 | peg$currPos = s0; 944 | s0 = peg$FAILED; 945 | } 946 | } else { 947 | peg$currPos = s0; 948 | s0 = peg$FAILED; 949 | } 950 | 951 | return s0; 952 | } 953 | 954 | function peg$parsemember() { 955 | var s0, s1, s2, s3; 956 | 957 | s0 = peg$currPos; 958 | s1 = peg$parsestring(); 959 | if (s1 !== peg$FAILED) { 960 | s2 = peg$parsename_separator(); 961 | if (s2 !== peg$FAILED) { 962 | s3 = peg$parseexpr(); 963 | if (s3 !== peg$FAILED) { 964 | peg$savedPos = s0; 965 | s1 = peg$c33(s1, s3); 966 | s0 = s1; 967 | } else { 968 | peg$currPos = s0; 969 | s0 = peg$FAILED; 970 | } 971 | } else { 972 | peg$currPos = s0; 973 | s0 = peg$FAILED; 974 | } 975 | } else { 976 | peg$currPos = s0; 977 | s0 = peg$FAILED; 978 | } 979 | 980 | return s0; 981 | } 982 | 983 | function peg$parsearray() { 984 | var s0, s1, s2, s3, s4, s5, s6, s7; 985 | 986 | s0 = peg$currPos; 987 | s1 = peg$parsebegin_array(); 988 | if (s1 !== peg$FAILED) { 989 | s2 = peg$currPos; 990 | s3 = peg$parseexpr(); 991 | if (s3 !== peg$FAILED) { 992 | s4 = []; 993 | s5 = peg$currPos; 994 | s6 = peg$parsevalue_separator(); 995 | if (s6 === peg$FAILED) { 996 | s6 = null; 997 | } 998 | if (s6 !== peg$FAILED) { 999 | s7 = peg$parseexpr(); 1000 | if (s7 !== peg$FAILED) { 1001 | peg$savedPos = s5; 1002 | s6 = peg$c34(s3, s7); 1003 | s5 = s6; 1004 | } else { 1005 | peg$currPos = s5; 1006 | s5 = peg$FAILED; 1007 | } 1008 | } else { 1009 | peg$currPos = s5; 1010 | s5 = peg$FAILED; 1011 | } 1012 | while (s5 !== peg$FAILED) { 1013 | s4.push(s5); 1014 | s5 = peg$currPos; 1015 | s6 = peg$parsevalue_separator(); 1016 | if (s6 === peg$FAILED) { 1017 | s6 = null; 1018 | } 1019 | if (s6 !== peg$FAILED) { 1020 | s7 = peg$parseexpr(); 1021 | if (s7 !== peg$FAILED) { 1022 | peg$savedPos = s5; 1023 | s6 = peg$c34(s3, s7); 1024 | s5 = s6; 1025 | } else { 1026 | peg$currPos = s5; 1027 | s5 = peg$FAILED; 1028 | } 1029 | } else { 1030 | peg$currPos = s5; 1031 | s5 = peg$FAILED; 1032 | } 1033 | } 1034 | if (s4 !== peg$FAILED) { 1035 | peg$savedPos = s2; 1036 | s3 = peg$c35(s3, s4); 1037 | s2 = s3; 1038 | } else { 1039 | peg$currPos = s2; 1040 | s2 = peg$FAILED; 1041 | } 1042 | } else { 1043 | peg$currPos = s2; 1044 | s2 = peg$FAILED; 1045 | } 1046 | if (s2 === peg$FAILED) { 1047 | s2 = null; 1048 | } 1049 | if (s2 !== peg$FAILED) { 1050 | s3 = peg$parseend_array(); 1051 | if (s3 !== peg$FAILED) { 1052 | peg$savedPos = s0; 1053 | s1 = peg$c36(s2); 1054 | s0 = s1; 1055 | } else { 1056 | peg$currPos = s0; 1057 | s0 = peg$FAILED; 1058 | } 1059 | } else { 1060 | peg$currPos = s0; 1061 | s0 = peg$FAILED; 1062 | } 1063 | } else { 1064 | peg$currPos = s0; 1065 | s0 = peg$FAILED; 1066 | } 1067 | 1068 | return s0; 1069 | } 1070 | 1071 | function peg$parsenumber() { 1072 | var s0, s1, s2, s3, s4; 1073 | 1074 | peg$silentFails++; 1075 | s0 = peg$currPos; 1076 | s1 = peg$parseminus(); 1077 | if (s1 === peg$FAILED) { 1078 | s1 = null; 1079 | } 1080 | if (s1 !== peg$FAILED) { 1081 | s2 = peg$parseint(); 1082 | if (s2 !== peg$FAILED) { 1083 | s3 = peg$parsefrac(); 1084 | if (s3 === peg$FAILED) { 1085 | s3 = null; 1086 | } 1087 | if (s3 !== peg$FAILED) { 1088 | s4 = peg$parseexp(); 1089 | if (s4 === peg$FAILED) { 1090 | s4 = null; 1091 | } 1092 | if (s4 !== peg$FAILED) { 1093 | peg$savedPos = s0; 1094 | s1 = peg$c38(); 1095 | s0 = s1; 1096 | } else { 1097 | peg$currPos = s0; 1098 | s0 = peg$FAILED; 1099 | } 1100 | } else { 1101 | peg$currPos = s0; 1102 | s0 = peg$FAILED; 1103 | } 1104 | } else { 1105 | peg$currPos = s0; 1106 | s0 = peg$FAILED; 1107 | } 1108 | } else { 1109 | peg$currPos = s0; 1110 | s0 = peg$FAILED; 1111 | } 1112 | peg$silentFails--; 1113 | if (s0 === peg$FAILED) { 1114 | s1 = peg$FAILED; 1115 | if (peg$silentFails === 0) { peg$fail(peg$c37); } 1116 | } 1117 | 1118 | return s0; 1119 | } 1120 | 1121 | function peg$parsedecimal_point() { 1122 | var s0; 1123 | 1124 | if (input.charCodeAt(peg$currPos) === 46) { 1125 | s0 = peg$c39; 1126 | peg$currPos++; 1127 | } else { 1128 | s0 = peg$FAILED; 1129 | if (peg$silentFails === 0) { peg$fail(peg$c40); } 1130 | } 1131 | 1132 | return s0; 1133 | } 1134 | 1135 | function peg$parsedigit1_9() { 1136 | var s0; 1137 | 1138 | if (peg$c41.test(input.charAt(peg$currPos))) { 1139 | s0 = input.charAt(peg$currPos); 1140 | peg$currPos++; 1141 | } else { 1142 | s0 = peg$FAILED; 1143 | if (peg$silentFails === 0) { peg$fail(peg$c42); } 1144 | } 1145 | 1146 | return s0; 1147 | } 1148 | 1149 | function peg$parsee() { 1150 | var s0; 1151 | 1152 | if (peg$c43.test(input.charAt(peg$currPos))) { 1153 | s0 = input.charAt(peg$currPos); 1154 | peg$currPos++; 1155 | } else { 1156 | s0 = peg$FAILED; 1157 | if (peg$silentFails === 0) { peg$fail(peg$c44); } 1158 | } 1159 | 1160 | return s0; 1161 | } 1162 | 1163 | function peg$parseexp() { 1164 | var s0, s1, s2, s3, s4; 1165 | 1166 | s0 = peg$currPos; 1167 | s1 = peg$parsee(); 1168 | if (s1 !== peg$FAILED) { 1169 | s2 = peg$parseminus(); 1170 | if (s2 === peg$FAILED) { 1171 | s2 = peg$parseplus(); 1172 | } 1173 | if (s2 === peg$FAILED) { 1174 | s2 = null; 1175 | } 1176 | if (s2 !== peg$FAILED) { 1177 | s3 = []; 1178 | s4 = peg$parseDIGIT(); 1179 | if (s4 !== peg$FAILED) { 1180 | while (s4 !== peg$FAILED) { 1181 | s3.push(s4); 1182 | s4 = peg$parseDIGIT(); 1183 | } 1184 | } else { 1185 | s3 = peg$FAILED; 1186 | } 1187 | if (s3 !== peg$FAILED) { 1188 | s1 = [s1, s2, s3]; 1189 | s0 = s1; 1190 | } else { 1191 | peg$currPos = s0; 1192 | s0 = peg$FAILED; 1193 | } 1194 | } else { 1195 | peg$currPos = s0; 1196 | s0 = peg$FAILED; 1197 | } 1198 | } else { 1199 | peg$currPos = s0; 1200 | s0 = peg$FAILED; 1201 | } 1202 | 1203 | return s0; 1204 | } 1205 | 1206 | function peg$parsefrac() { 1207 | var s0, s1, s2, s3; 1208 | 1209 | s0 = peg$currPos; 1210 | s1 = peg$parsedecimal_point(); 1211 | if (s1 !== peg$FAILED) { 1212 | s2 = []; 1213 | s3 = peg$parseDIGIT(); 1214 | if (s3 !== peg$FAILED) { 1215 | while (s3 !== peg$FAILED) { 1216 | s2.push(s3); 1217 | s3 = peg$parseDIGIT(); 1218 | } 1219 | } else { 1220 | s2 = peg$FAILED; 1221 | } 1222 | if (s2 !== peg$FAILED) { 1223 | s1 = [s1, s2]; 1224 | s0 = s1; 1225 | } else { 1226 | peg$currPos = s0; 1227 | s0 = peg$FAILED; 1228 | } 1229 | } else { 1230 | peg$currPos = s0; 1231 | s0 = peg$FAILED; 1232 | } 1233 | 1234 | return s0; 1235 | } 1236 | 1237 | function peg$parseint() { 1238 | var s0, s1, s2, s3; 1239 | 1240 | s0 = peg$parsezero(); 1241 | if (s0 === peg$FAILED) { 1242 | s0 = peg$currPos; 1243 | s1 = peg$parsedigit1_9(); 1244 | if (s1 !== peg$FAILED) { 1245 | s2 = []; 1246 | s3 = peg$parseDIGIT(); 1247 | while (s3 !== peg$FAILED) { 1248 | s2.push(s3); 1249 | s3 = peg$parseDIGIT(); 1250 | } 1251 | if (s2 !== peg$FAILED) { 1252 | s1 = [s1, s2]; 1253 | s0 = s1; 1254 | } else { 1255 | peg$currPos = s0; 1256 | s0 = peg$FAILED; 1257 | } 1258 | } else { 1259 | peg$currPos = s0; 1260 | s0 = peg$FAILED; 1261 | } 1262 | } 1263 | 1264 | return s0; 1265 | } 1266 | 1267 | function peg$parseminus() { 1268 | var s0; 1269 | 1270 | if (input.charCodeAt(peg$currPos) === 45) { 1271 | s0 = peg$c45; 1272 | peg$currPos++; 1273 | } else { 1274 | s0 = peg$FAILED; 1275 | if (peg$silentFails === 0) { peg$fail(peg$c46); } 1276 | } 1277 | 1278 | return s0; 1279 | } 1280 | 1281 | function peg$parseplus() { 1282 | var s0; 1283 | 1284 | if (input.charCodeAt(peg$currPos) === 43) { 1285 | s0 = peg$c47; 1286 | peg$currPos++; 1287 | } else { 1288 | s0 = peg$FAILED; 1289 | if (peg$silentFails === 0) { peg$fail(peg$c48); } 1290 | } 1291 | 1292 | return s0; 1293 | } 1294 | 1295 | function peg$parsezero() { 1296 | var s0; 1297 | 1298 | if (input.charCodeAt(peg$currPos) === 48) { 1299 | s0 = peg$c49; 1300 | peg$currPos++; 1301 | } else { 1302 | s0 = peg$FAILED; 1303 | if (peg$silentFails === 0) { peg$fail(peg$c50); } 1304 | } 1305 | 1306 | return s0; 1307 | } 1308 | 1309 | function peg$parsestring() { 1310 | var s0, s1; 1311 | 1312 | peg$silentFails++; 1313 | s0 = peg$parsedouble_quoted_string(); 1314 | if (s0 === peg$FAILED) { 1315 | s0 = peg$parsesingle_quoted_string(); 1316 | if (s0 === peg$FAILED) { 1317 | s0 = peg$parseunquoted_string(); 1318 | } 1319 | } 1320 | peg$silentFails--; 1321 | if (s0 === peg$FAILED) { 1322 | s1 = peg$FAILED; 1323 | if (peg$silentFails === 0) { peg$fail(peg$c51); } 1324 | } 1325 | 1326 | return s0; 1327 | } 1328 | 1329 | function peg$parseunquoted_string() { 1330 | var s0, s1, s2; 1331 | 1332 | s0 = peg$currPos; 1333 | s1 = []; 1334 | s2 = peg$parsesimple_char(); 1335 | if (s2 !== peg$FAILED) { 1336 | while (s2 !== peg$FAILED) { 1337 | s1.push(s2); 1338 | s2 = peg$parsesimple_char(); 1339 | } 1340 | } else { 1341 | s1 = peg$FAILED; 1342 | } 1343 | if (s1 !== peg$FAILED) { 1344 | peg$savedPos = s0; 1345 | s1 = peg$c52(s1); 1346 | } 1347 | s0 = s1; 1348 | 1349 | return s0; 1350 | } 1351 | 1352 | function peg$parsesingle_quoted_string() { 1353 | var s0, s1, s2, s3; 1354 | 1355 | s0 = peg$currPos; 1356 | if (input.charCodeAt(peg$currPos) === 39) { 1357 | s1 = peg$c53; 1358 | peg$currPos++; 1359 | } else { 1360 | s1 = peg$FAILED; 1361 | if (peg$silentFails === 0) { peg$fail(peg$c54); } 1362 | } 1363 | if (s1 !== peg$FAILED) { 1364 | s2 = []; 1365 | s3 = peg$parsechar_single_quoted(); 1366 | while (s3 !== peg$FAILED) { 1367 | s2.push(s3); 1368 | s3 = peg$parsechar_single_quoted(); 1369 | } 1370 | if (s2 !== peg$FAILED) { 1371 | if (input.charCodeAt(peg$currPos) === 39) { 1372 | s3 = peg$c53; 1373 | peg$currPos++; 1374 | } else { 1375 | s3 = peg$FAILED; 1376 | if (peg$silentFails === 0) { peg$fail(peg$c54); } 1377 | } 1378 | if (s3 !== peg$FAILED) { 1379 | peg$savedPos = s0; 1380 | s1 = peg$c55(s2); 1381 | s0 = s1; 1382 | } else { 1383 | peg$currPos = s0; 1384 | s0 = peg$FAILED; 1385 | } 1386 | } else { 1387 | peg$currPos = s0; 1388 | s0 = peg$FAILED; 1389 | } 1390 | } else { 1391 | peg$currPos = s0; 1392 | s0 = peg$FAILED; 1393 | } 1394 | 1395 | return s0; 1396 | } 1397 | 1398 | function peg$parsedouble_quoted_string() { 1399 | var s0, s1, s2, s3; 1400 | 1401 | s0 = peg$currPos; 1402 | if (input.charCodeAt(peg$currPos) === 34) { 1403 | s1 = peg$c56; 1404 | peg$currPos++; 1405 | } else { 1406 | s1 = peg$FAILED; 1407 | if (peg$silentFails === 0) { peg$fail(peg$c57); } 1408 | } 1409 | if (s1 !== peg$FAILED) { 1410 | s2 = []; 1411 | s3 = peg$parsechar_double_quoted(); 1412 | while (s3 !== peg$FAILED) { 1413 | s2.push(s3); 1414 | s3 = peg$parsechar_double_quoted(); 1415 | } 1416 | if (s2 !== peg$FAILED) { 1417 | if (input.charCodeAt(peg$currPos) === 34) { 1418 | s3 = peg$c56; 1419 | peg$currPos++; 1420 | } else { 1421 | s3 = peg$FAILED; 1422 | if (peg$silentFails === 0) { peg$fail(peg$c57); } 1423 | } 1424 | if (s3 !== peg$FAILED) { 1425 | peg$savedPos = s0; 1426 | s1 = peg$c55(s2); 1427 | s0 = s1; 1428 | } else { 1429 | peg$currPos = s0; 1430 | s0 = peg$FAILED; 1431 | } 1432 | } else { 1433 | peg$currPos = s0; 1434 | s0 = peg$FAILED; 1435 | } 1436 | } else { 1437 | peg$currPos = s0; 1438 | s0 = peg$FAILED; 1439 | } 1440 | 1441 | return s0; 1442 | } 1443 | 1444 | function peg$parsesimple_char() { 1445 | var s0; 1446 | 1447 | s0 = peg$parseunescaped_simple(); 1448 | if (s0 === peg$FAILED) { 1449 | s0 = peg$parseescaped_char(); 1450 | } 1451 | 1452 | return s0; 1453 | } 1454 | 1455 | function peg$parsechar_single_quoted() { 1456 | var s0; 1457 | 1458 | s0 = peg$parseunescaped_single_quote(); 1459 | if (s0 === peg$FAILED) { 1460 | s0 = peg$parseescaped_char(); 1461 | } 1462 | 1463 | return s0; 1464 | } 1465 | 1466 | function peg$parsechar_double_quoted() { 1467 | var s0; 1468 | 1469 | s0 = peg$parseunescaped_double_quote(); 1470 | if (s0 === peg$FAILED) { 1471 | s0 = peg$parseescaped_char(); 1472 | } 1473 | 1474 | return s0; 1475 | } 1476 | 1477 | function peg$parseescaped_char() { 1478 | var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; 1479 | 1480 | s0 = peg$currPos; 1481 | s1 = peg$parseescape(); 1482 | if (s1 !== peg$FAILED) { 1483 | if (input.charCodeAt(peg$currPos) === 34) { 1484 | s2 = peg$c56; 1485 | peg$currPos++; 1486 | } else { 1487 | s2 = peg$FAILED; 1488 | if (peg$silentFails === 0) { peg$fail(peg$c57); } 1489 | } 1490 | if (s2 === peg$FAILED) { 1491 | if (input.charCodeAt(peg$currPos) === 39) { 1492 | s2 = peg$c53; 1493 | peg$currPos++; 1494 | } else { 1495 | s2 = peg$FAILED; 1496 | if (peg$silentFails === 0) { peg$fail(peg$c54); } 1497 | } 1498 | if (s2 === peg$FAILED) { 1499 | if (input.charCodeAt(peg$currPos) === 92) { 1500 | s2 = peg$c58; 1501 | peg$currPos++; 1502 | } else { 1503 | s2 = peg$FAILED; 1504 | if (peg$silentFails === 0) { peg$fail(peg$c59); } 1505 | } 1506 | if (s2 === peg$FAILED) { 1507 | if (input.charCodeAt(peg$currPos) === 47) { 1508 | s2 = peg$c60; 1509 | peg$currPos++; 1510 | } else { 1511 | s2 = peg$FAILED; 1512 | if (peg$silentFails === 0) { peg$fail(peg$c61); } 1513 | } 1514 | if (s2 === peg$FAILED) { 1515 | if (input.charCodeAt(peg$currPos) === 35) { 1516 | s2 = peg$c14; 1517 | peg$currPos++; 1518 | } else { 1519 | s2 = peg$FAILED; 1520 | if (peg$silentFails === 0) { peg$fail(peg$c15); } 1521 | } 1522 | if (s2 === peg$FAILED) { 1523 | s2 = peg$currPos; 1524 | if (input.charCodeAt(peg$currPos) === 98) { 1525 | s3 = peg$c62; 1526 | peg$currPos++; 1527 | } else { 1528 | s3 = peg$FAILED; 1529 | if (peg$silentFails === 0) { peg$fail(peg$c63); } 1530 | } 1531 | if (s3 !== peg$FAILED) { 1532 | peg$savedPos = s2; 1533 | s3 = peg$c64(); 1534 | } 1535 | s2 = s3; 1536 | if (s2 === peg$FAILED) { 1537 | s2 = peg$currPos; 1538 | if (input.charCodeAt(peg$currPos) === 102) { 1539 | s3 = peg$c65; 1540 | peg$currPos++; 1541 | } else { 1542 | s3 = peg$FAILED; 1543 | if (peg$silentFails === 0) { peg$fail(peg$c66); } 1544 | } 1545 | if (s3 !== peg$FAILED) { 1546 | peg$savedPos = s2; 1547 | s3 = peg$c67(); 1548 | } 1549 | s2 = s3; 1550 | if (s2 === peg$FAILED) { 1551 | s2 = peg$currPos; 1552 | if (input.charCodeAt(peg$currPos) === 110) { 1553 | s3 = peg$c68; 1554 | peg$currPos++; 1555 | } else { 1556 | s3 = peg$FAILED; 1557 | if (peg$silentFails === 0) { peg$fail(peg$c69); } 1558 | } 1559 | if (s3 !== peg$FAILED) { 1560 | peg$savedPos = s2; 1561 | s3 = peg$c70(); 1562 | } 1563 | s2 = s3; 1564 | if (s2 === peg$FAILED) { 1565 | s2 = peg$currPos; 1566 | if (input.charCodeAt(peg$currPos) === 114) { 1567 | s3 = peg$c71; 1568 | peg$currPos++; 1569 | } else { 1570 | s3 = peg$FAILED; 1571 | if (peg$silentFails === 0) { peg$fail(peg$c72); } 1572 | } 1573 | if (s3 !== peg$FAILED) { 1574 | peg$savedPos = s2; 1575 | s3 = peg$c73(); 1576 | } 1577 | s2 = s3; 1578 | if (s2 === peg$FAILED) { 1579 | s2 = peg$currPos; 1580 | if (input.charCodeAt(peg$currPos) === 116) { 1581 | s3 = peg$c74; 1582 | peg$currPos++; 1583 | } else { 1584 | s3 = peg$FAILED; 1585 | if (peg$silentFails === 0) { peg$fail(peg$c75); } 1586 | } 1587 | if (s3 !== peg$FAILED) { 1588 | peg$savedPos = s2; 1589 | s3 = peg$c76(); 1590 | } 1591 | s2 = s3; 1592 | if (s2 === peg$FAILED) { 1593 | s2 = peg$currPos; 1594 | if (input.charCodeAt(peg$currPos) === 117) { 1595 | s3 = peg$c77; 1596 | peg$currPos++; 1597 | } else { 1598 | s3 = peg$FAILED; 1599 | if (peg$silentFails === 0) { peg$fail(peg$c78); } 1600 | } 1601 | if (s3 !== peg$FAILED) { 1602 | s4 = peg$currPos; 1603 | s5 = peg$currPos; 1604 | s6 = peg$parseHEXDIG(); 1605 | if (s6 !== peg$FAILED) { 1606 | s7 = peg$parseHEXDIG(); 1607 | if (s7 !== peg$FAILED) { 1608 | s8 = peg$parseHEXDIG(); 1609 | if (s8 !== peg$FAILED) { 1610 | s9 = peg$parseHEXDIG(); 1611 | if (s9 !== peg$FAILED) { 1612 | s6 = [s6, s7, s8, s9]; 1613 | s5 = s6; 1614 | } else { 1615 | peg$currPos = s5; 1616 | s5 = peg$FAILED; 1617 | } 1618 | } else { 1619 | peg$currPos = s5; 1620 | s5 = peg$FAILED; 1621 | } 1622 | } else { 1623 | peg$currPos = s5; 1624 | s5 = peg$FAILED; 1625 | } 1626 | } else { 1627 | peg$currPos = s5; 1628 | s5 = peg$FAILED; 1629 | } 1630 | if (s5 !== peg$FAILED) { 1631 | s4 = input.substring(s4, peg$currPos); 1632 | } else { 1633 | s4 = s5; 1634 | } 1635 | if (s4 !== peg$FAILED) { 1636 | peg$savedPos = s2; 1637 | s3 = peg$c79(s4); 1638 | s2 = s3; 1639 | } else { 1640 | peg$currPos = s2; 1641 | s2 = peg$FAILED; 1642 | } 1643 | } else { 1644 | peg$currPos = s2; 1645 | s2 = peg$FAILED; 1646 | } 1647 | } 1648 | } 1649 | } 1650 | } 1651 | } 1652 | } 1653 | } 1654 | } 1655 | } 1656 | } 1657 | if (s2 !== peg$FAILED) { 1658 | peg$savedPos = s0; 1659 | s1 = peg$c80(s2); 1660 | s0 = s1; 1661 | } else { 1662 | peg$currPos = s0; 1663 | s0 = peg$FAILED; 1664 | } 1665 | } else { 1666 | peg$currPos = s0; 1667 | s0 = peg$FAILED; 1668 | } 1669 | 1670 | return s0; 1671 | } 1672 | 1673 | function peg$parseescape() { 1674 | var s0; 1675 | 1676 | if (input.charCodeAt(peg$currPos) === 92) { 1677 | s0 = peg$c58; 1678 | peg$currPos++; 1679 | } else { 1680 | s0 = peg$FAILED; 1681 | if (peg$silentFails === 0) { peg$fail(peg$c59); } 1682 | } 1683 | 1684 | return s0; 1685 | } 1686 | 1687 | function peg$parseunescaped_simple() { 1688 | var s0; 1689 | 1690 | if (peg$c81.test(input.charAt(peg$currPos))) { 1691 | s0 = input.charAt(peg$currPos); 1692 | peg$currPos++; 1693 | } else { 1694 | s0 = peg$FAILED; 1695 | if (peg$silentFails === 0) { peg$fail(peg$c82); } 1696 | } 1697 | 1698 | return s0; 1699 | } 1700 | 1701 | function peg$parseunescaped_double_quote() { 1702 | var s0; 1703 | 1704 | if (peg$c83.test(input.charAt(peg$currPos))) { 1705 | s0 = input.charAt(peg$currPos); 1706 | peg$currPos++; 1707 | } else { 1708 | s0 = peg$FAILED; 1709 | if (peg$silentFails === 0) { peg$fail(peg$c84); } 1710 | } 1711 | 1712 | return s0; 1713 | } 1714 | 1715 | function peg$parseunescaped_single_quote() { 1716 | var s0; 1717 | 1718 | if (peg$c85.test(input.charAt(peg$currPos))) { 1719 | s0 = input.charAt(peg$currPos); 1720 | peg$currPos++; 1721 | } else { 1722 | s0 = peg$FAILED; 1723 | if (peg$silentFails === 0) { peg$fail(peg$c86); } 1724 | } 1725 | 1726 | return s0; 1727 | } 1728 | 1729 | function peg$parseassign() { 1730 | var s0, s1; 1731 | 1732 | s0 = peg$currPos; 1733 | s1 = peg$parsemember(); 1734 | if (s1 !== peg$FAILED) { 1735 | peg$savedPos = s0; 1736 | s1 = peg$c87(s1); 1737 | } 1738 | s0 = s1; 1739 | 1740 | return s0; 1741 | } 1742 | 1743 | function peg$parsetyped() { 1744 | var s0, s1, s2, s3; 1745 | 1746 | s0 = peg$currPos; 1747 | s1 = []; 1748 | if (peg$c88.test(input.charAt(peg$currPos))) { 1749 | s2 = input.charAt(peg$currPos); 1750 | peg$currPos++; 1751 | } else { 1752 | s2 = peg$FAILED; 1753 | if (peg$silentFails === 0) { peg$fail(peg$c89); } 1754 | } 1755 | if (s2 !== peg$FAILED) { 1756 | while (s2 !== peg$FAILED) { 1757 | s1.push(s2); 1758 | if (peg$c88.test(input.charAt(peg$currPos))) { 1759 | s2 = input.charAt(peg$currPos); 1760 | peg$currPos++; 1761 | } else { 1762 | s2 = peg$FAILED; 1763 | if (peg$silentFails === 0) { peg$fail(peg$c89); } 1764 | } 1765 | } 1766 | } else { 1767 | s1 = peg$FAILED; 1768 | } 1769 | if (s1 !== peg$FAILED) { 1770 | s2 = peg$parsetyped_start(); 1771 | if (s2 !== peg$FAILED) { 1772 | s3 = peg$parseexpr(); 1773 | if (s3 !== peg$FAILED) { 1774 | peg$savedPos = s0; 1775 | s1 = peg$c90(s1, s3); 1776 | s0 = s1; 1777 | } else { 1778 | peg$currPos = s0; 1779 | s0 = peg$FAILED; 1780 | } 1781 | } else { 1782 | peg$currPos = s0; 1783 | s0 = peg$FAILED; 1784 | } 1785 | } else { 1786 | peg$currPos = s0; 1787 | s0 = peg$FAILED; 1788 | } 1789 | 1790 | return s0; 1791 | } 1792 | 1793 | function peg$parsecomment() { 1794 | var s0, s1, s2, s3; 1795 | 1796 | s0 = peg$currPos; 1797 | s1 = peg$parsecomment_start(); 1798 | if (s1 !== peg$FAILED) { 1799 | s2 = []; 1800 | if (peg$c91.test(input.charAt(peg$currPos))) { 1801 | s3 = input.charAt(peg$currPos); 1802 | peg$currPos++; 1803 | } else { 1804 | s3 = peg$FAILED; 1805 | if (peg$silentFails === 0) { peg$fail(peg$c92); } 1806 | } 1807 | while (s3 !== peg$FAILED) { 1808 | s2.push(s3); 1809 | if (peg$c91.test(input.charAt(peg$currPos))) { 1810 | s3 = input.charAt(peg$currPos); 1811 | peg$currPos++; 1812 | } else { 1813 | s3 = peg$FAILED; 1814 | if (peg$silentFails === 0) { peg$fail(peg$c92); } 1815 | } 1816 | } 1817 | if (s2 !== peg$FAILED) { 1818 | s1 = [s1, s2]; 1819 | s0 = s1; 1820 | } else { 1821 | peg$currPos = s0; 1822 | s0 = peg$FAILED; 1823 | } 1824 | } else { 1825 | peg$currPos = s0; 1826 | s0 = peg$FAILED; 1827 | } 1828 | 1829 | return s0; 1830 | } 1831 | 1832 | function peg$parseDIGIT() { 1833 | var s0; 1834 | 1835 | if (peg$c93.test(input.charAt(peg$currPos))) { 1836 | s0 = input.charAt(peg$currPos); 1837 | peg$currPos++; 1838 | } else { 1839 | s0 = peg$FAILED; 1840 | if (peg$silentFails === 0) { peg$fail(peg$c94); } 1841 | } 1842 | 1843 | return s0; 1844 | } 1845 | 1846 | function peg$parseHEXDIG() { 1847 | var s0; 1848 | 1849 | if (peg$c95.test(input.charAt(peg$currPos))) { 1850 | s0 = input.charAt(peg$currPos); 1851 | peg$currPos++; 1852 | } else { 1853 | s0 = peg$FAILED; 1854 | if (peg$silentFails === 0) { peg$fail(peg$c96); } 1855 | } 1856 | 1857 | return s0; 1858 | } 1859 | 1860 | peg$result = peg$startRuleFunction(); 1861 | 1862 | if (peg$result !== peg$FAILED && peg$currPos === input.length) { 1863 | return peg$result; 1864 | } else { 1865 | if (peg$result !== peg$FAILED && peg$currPos < input.length) { 1866 | peg$fail(peg$endExpectation()); 1867 | } 1868 | 1869 | throw peg$buildStructuredError( 1870 | peg$maxFailExpected, 1871 | peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, 1872 | peg$maxFailPos < input.length 1873 | ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) 1874 | : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) 1875 | ); 1876 | } 1877 | } 1878 | 1879 | module.exports = { 1880 | SyntaxError: peg$SyntaxError, 1881 | parse: peg$parse 1882 | }; 1883 | -------------------------------------------------------------------------------- /dist/uson.min.js: -------------------------------------------------------------------------------- 1 | (function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var r;if(typeof window!=="undefined"){r=window}else if(typeof global!=="undefined"){r=global}else if(typeof self!=="undefined"){r=self}else{r=this}r.USON=e()}})(function(){var e,r,t;return function(){function o(f,u,l){function s(t,e){if(!u[t]){if(!f[t]){var r="function"==typeof require&&require;if(!e&&r)return r(t,!0);if(a)return a(t,!0);var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}var i=u[t]={exports:{}};f[t][0].call(i.exports,function(e){var r=f[t][1][e];return s(r||e)},i,i.exports,o,f,u,l)}return u[t].exports}for(var a="function"==typeof require&&require,e=0;e0){for(t=1,n=1;tWe){We=Ke;Xe=[]}Xe.push(e)}function pr(e,r){return new lt(e,null,null,r)}function vr(e,r,t){return new lt(lt.buildMessage(e,r),e,r,t)}function dr(){var e,r,t,n,i;e=Ke;r=gr();if(r===c){r=null}if(r!==c){t=Or();if(t!==c){n=[];i=gr();while(i!==c){n.push(i);i=gr()}if(n!==c){Qe=e;r=f(r,n);e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function gr(){var e,r,t,n;e=Ke;r=Or();if(r!==c){t=Sr();if(t!==c){n=Or();if(n!==c){Qe=e;r=i(t);e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function Ar(){var e,r,t,n;e=Ke;r=Or();if(r!==c){if(o.charCodeAt(Ke)===91){t=u;Ke++}else{t=c;if(Ye===0){hr(l)}}if(t!==c){n=Or();if(n!==c){r=[r,t,n];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function br(){var e,r,t,n;e=Ke;r=Or();if(r!==c){if(o.charCodeAt(Ke)===123){t=s;Ke++}else{t=c;if(Ye===0){hr(a)}}if(t!==c){n=Or();if(n!==c){r=[r,t,n];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function yr(){var e,r,t,n;e=Ke;r=Or();if(r!==c){if(o.charCodeAt(Ke)===93){t=h;Ke++}else{t=c;if(Ye===0){hr(p)}}if(t!==c){n=Or();if(n!==c){r=[r,t,n];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function wr(){var e,r,t,n;e=Ke;r=Or();if(r!==c){if(o.charCodeAt(Ke)===125){t=v;Ke++}else{t=c;if(Ye===0){hr(d)}}if(t!==c){n=Or();if(n!==c){r=[r,t,n];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function Cr(){var e,r,t,n;e=Ke;r=Or();if(r!==c){if(o.charCodeAt(Ke)===58){t=g;Ke++}else{t=c;if(Ye===0){hr(A)}}if(t!==c){n=Or();if(n!==c){r=[r,t,n];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function mr(){var e,r,t,n;e=Ke;r=Or();if(r!==c){t=[];if(b.test(o.charAt(Ke))){n=o.charAt(Ke);Ke++}else{n=c;if(Ye===0){hr(y)}}while(n!==c){t.push(n);if(b.test(o.charAt(Ke))){n=o.charAt(Ke);Ke++}else{n=c;if(Ye===0){hr(y)}}}if(t!==c){n=Or();if(n!==c){r=[r,t,n];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function jr(){var e;if(o.charCodeAt(Ke)===35){e=w;Ke++}else{e=c;if(Ye===0){hr(C)}}return e}function xr(){var e,r,t,n;e=Ke;r=Or();if(r!==c){if(o.charCodeAt(Ke)===33){t=m;Ke++}else{t=c;if(Ye===0){hr(j)}}if(t!==c){n=Or();if(n!==c){r=[r,t,n];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function Fr(){var e;if(t.test(o.charAt(Ke))){e=o.charAt(Ke);Ke++}else{e=c;if(Ye===0){hr(x)}}return e}function Or(){var e,r,t;Ye++;e=Ke;r=[];t=Fr();while(t!==c){r.push(t);t=Fr()}if(r!==c){t=it();if(t===c){t=null}if(t!==c){r=[r,t];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}Ye--;if(e===c){r=c;if(Ye===0){hr(F)}}return e}function Sr(){var e;e=nt();if(e===c){e=Er();if(e===c){e=Nr();if(e===c){e=qr();if(e===c){e=tt();if(e===c){e=_r();if(e===c){e=zr();if(e===c){e=Lr();if(e===c){e=Pr()}}}}}}}}return e}function Er(){var e,r;e=Ke;if(o.substr(Ke,5)===O){r=O;Ke+=5}else{r=c;if(Ye===0){hr(S)}}if(r!==c){Qe=e;r=E()}e=r;return e}function Nr(){var e,r;e=Ke;if(o.substr(Ke,4)===N){r=N;Ke+=4}else{r=c;if(Ye===0){hr(q)}}if(r!==c){Qe=e;r=_()}e=r;return e}function qr(){var e,r;e=Ke;if(o.substr(Ke,4)===k){r=k;Ke+=4}else{r=c;if(Ye===0){hr(z)}}if(r!==c){Qe=e;r=P()}e=r;return e}function _r(){var e,r,t,n,i,f,u,l;e=Ke;r=br();if(r!==c){t=Ke;n=kr();if(n!==c){i=[];f=Ke;u=mr();if(u!==c){l=kr();if(l!==c){Qe=f;u=R(n,l);f=u}else{Ke=f;f=c}}else{Ke=f;f=c}while(f!==c){i.push(f);f=Ke;u=mr();if(u!==c){l=kr();if(l!==c){Qe=f;u=R(n,l);f=u}else{Ke=f;f=c}}else{Ke=f;f=c}}if(i!==c){Qe=t;n=T(n,i);t=n}else{Ke=t;t=c}}else{Ke=t;t=c}if(t===c){t=null}if(t!==c){n=wr();if(n!==c){Qe=e;r=U(t);e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function kr(){var e,r,t,n;e=Ke;r=Lr();if(r!==c){t=Cr();if(t!==c){n=gr();if(n!==c){Qe=e;r=Z(r,n);e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function zr(){var e,r,t,n,i,f,u,l;e=Ke;r=Ar();if(r!==c){t=Ke;n=gr();if(n!==c){i=[];f=Ke;u=mr();if(u===c){u=null}if(u!==c){l=gr();if(l!==c){Qe=f;u=D(n,l);f=u}else{Ke=f;f=c}}else{Ke=f;f=c}while(f!==c){i.push(f);f=Ke;u=mr();if(u===c){u=null}if(u!==c){l=gr();if(l!==c){Qe=f;u=D(n,l);f=u}else{Ke=f;f=c}}else{Ke=f;f=c}}if(i!==c){Qe=t;n=I(n,i);t=n}else{Ke=t;t=c}}else{Ke=t;t=c}if(t===c){t=null}if(t!==c){n=yr();if(n!==c){Qe=e;r=M(t);e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function Pr(){var e,r,t,n,i;Ye++;e=Ke;r=Mr();if(r===c){r=null}if(r!==c){t=Ir();if(t!==c){n=Dr();if(n===c){n=null}if(n!==c){i=Zr();if(i===c){i=null}if(i!==c){Qe=e;r=J();e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}Ye--;if(e===c){r=c;if(Ye===0){hr($)}}return e}function Rr(){var e;if(o.charCodeAt(Ke)===46){e=L;Ke++}else{e=c;if(Ye===0){hr(B)}}return e}function Tr(){var e;if(G.test(o.charAt(Ke))){e=o.charAt(Ke);Ke++}else{e=c;if(Ye===0){hr(H)}}return e}function Ur(){var e;if(K.test(o.charAt(Ke))){e=o.charAt(Ke);Ke++}else{e=c;if(Ye===0){hr(Q)}}return e}function Zr(){var e,r,t,n,i;e=Ke;r=Ur();if(r!==c){t=Mr();if(t===c){t=$r()}if(t===c){t=null}if(t!==c){n=[];i=ft();if(i!==c){while(i!==c){n.push(i);i=ft()}}else{n=c}if(n!==c){r=[r,t,n];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function Dr(){var e,r,t,n;e=Ke;r=Rr();if(r!==c){t=[];n=ft();if(n!==c){while(n!==c){t.push(n);n=ft()}}else{t=c}if(t!==c){r=[r,t];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function Ir(){var e,r,t,n;e=Jr();if(e===c){e=Ke;r=Tr();if(r!==c){t=[];n=ft();while(n!==c){t.push(n);n=ft()}if(t!==c){r=[r,t];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}return e}function Mr(){var e;if(o.charCodeAt(Ke)===45){e=V;Ke++}else{e=c;if(Ye===0){hr(W)}}return e}function $r(){var e;if(o.charCodeAt(Ke)===43){e=X;Ke++}else{e=c;if(Ye===0){hr(Y)}}return e}function Jr(){var e;if(o.charCodeAt(Ke)===48){e=ee;Ke++}else{e=c;if(Ye===0){hr(re)}}return e}function Lr(){var e,r;Ye++;e=Hr();if(e===c){e=Gr();if(e===c){e=Br()}}Ye--;if(e===c){r=c;if(Ye===0){hr(te)}}return e}function Br(){var e,r,t;e=Ke;r=[];t=Kr();if(t!==c){while(t!==c){r.push(t);t=Kr()}}else{r=c}if(r!==c){Qe=e;r=ne(r)}e=r;return e}function Gr(){var e,r,t,n;e=Ke;if(o.charCodeAt(Ke)===39){r=ie;Ke++}else{r=c;if(Ye===0){hr(fe)}}if(r!==c){t=[];n=Qr();while(n!==c){t.push(n);n=Qr()}if(t!==c){if(o.charCodeAt(Ke)===39){n=ie;Ke++}else{n=c;if(Ye===0){hr(fe)}}if(n!==c){Qe=e;r=ue(t);e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function Hr(){var e,r,t,n;e=Ke;if(o.charCodeAt(Ke)===34){r=le;Ke++}else{r=c;if(Ye===0){hr(se)}}if(r!==c){t=[];n=Vr();while(n!==c){t.push(n);n=Vr()}if(t!==c){if(o.charCodeAt(Ke)===34){n=le;Ke++}else{n=c;if(Ye===0){hr(se)}}if(n!==c){Qe=e;r=ue(t);e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function Kr(){var e;e=Yr();if(e===c){e=Wr()}return e}function Qr(){var e;e=rt();if(e===c){e=Wr()}return e}function Vr(){var e;e=et();if(e===c){e=Wr()}return e}function Wr(){var e,r,t,n,i,f,u,l,s,a;e=Ke;r=Xr();if(r!==c){if(o.charCodeAt(Ke)===34){t=le;Ke++}else{t=c;if(Ye===0){hr(se)}}if(t===c){if(o.charCodeAt(Ke)===39){t=ie;Ke++}else{t=c;if(Ye===0){hr(fe)}}if(t===c){if(o.charCodeAt(Ke)===92){t=ae;Ke++}else{t=c;if(Ye===0){hr(oe)}}if(t===c){if(o.charCodeAt(Ke)===47){t=ce;Ke++}else{t=c;if(Ye===0){hr(he)}}if(t===c){if(o.charCodeAt(Ke)===35){t=w;Ke++}else{t=c;if(Ye===0){hr(C)}}if(t===c){t=Ke;if(o.charCodeAt(Ke)===98){n=pe;Ke++}else{n=c;if(Ye===0){hr(ve)}}if(n!==c){Qe=t;n=de()}t=n;if(t===c){t=Ke;if(o.charCodeAt(Ke)===102){n=ge;Ke++}else{n=c;if(Ye===0){hr(Ae)}}if(n!==c){Qe=t;n=be()}t=n;if(t===c){t=Ke;if(o.charCodeAt(Ke)===110){n=ye;Ke++}else{n=c;if(Ye===0){hr(we)}}if(n!==c){Qe=t;n=Ce()}t=n;if(t===c){t=Ke;if(o.charCodeAt(Ke)===114){n=me;Ke++}else{n=c;if(Ye===0){hr(je)}}if(n!==c){Qe=t;n=xe()}t=n;if(t===c){t=Ke;if(o.charCodeAt(Ke)===116){n=Fe;Ke++}else{n=c;if(Ye===0){hr(Oe)}}if(n!==c){Qe=t;n=Se()}t=n;if(t===c){t=Ke;if(o.charCodeAt(Ke)===117){n=Ee;Ke++}else{n=c;if(Ye===0){hr(Ne)}}if(n!==c){i=Ke;f=Ke;u=ut();if(u!==c){l=ut();if(l!==c){s=ut();if(s!==c){a=ut();if(a!==c){u=[u,l,s,a];f=u}else{Ke=f;f=c}}else{Ke=f;f=c}}else{Ke=f;f=c}}else{Ke=f;f=c}if(f!==c){i=o.substring(i,Ke)}else{i=f}if(i!==c){Qe=t;n=qe(i);t=n}else{Ke=t;t=c}}else{Ke=t;t=c}}}}}}}}}}}if(t!==c){Qe=e;r=_e(t);e=r}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function Xr(){var e;if(o.charCodeAt(Ke)===92){e=ae;Ke++}else{e=c;if(Ye===0){hr(oe)}}return e}function Yr(){var e;if(ke.test(o.charAt(Ke))){e=o.charAt(Ke);Ke++}else{e=c;if(Ye===0){hr(ze)}}return e}function et(){var e;if(Pe.test(o.charAt(Ke))){e=o.charAt(Ke);Ke++}else{e=c;if(Ye===0){hr(Re)}}return e}function rt(){var e;if(Te.test(o.charAt(Ke))){e=o.charAt(Ke);Ke++}else{e=c;if(Ye===0){hr(Ue)}}return e}function tt(){var e,r;e=Ke;r=kr();if(r!==c){Qe=e;r=Ze(r)}e=r;return e}function nt(){var e,r,t,n;e=Ke;r=[];if(De.test(o.charAt(Ke))){t=o.charAt(Ke);Ke++}else{t=c;if(Ye===0){hr(Ie)}}if(t!==c){while(t!==c){r.push(t);if(De.test(o.charAt(Ke))){t=o.charAt(Ke);Ke++}else{t=c;if(Ye===0){hr(Ie)}}}}else{r=c}if(r!==c){t=xr();if(t!==c){n=gr();if(n!==c){Qe=e;r=Me(r,n);e=r}else{Ke=e;e=c}}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function it(){var e,r,t,n;e=Ke;r=jr();if(r!==c){t=[];if($e.test(o.charAt(Ke))){n=o.charAt(Ke);Ke++}else{n=c;if(Ye===0){hr(Je)}}while(n!==c){t.push(n);if($e.test(o.charAt(Ke))){n=o.charAt(Ke);Ke++}else{n=c;if(Ye===0){hr(Je)}}}if(t!==c){r=[r,t];e=r}else{Ke=e;e=c}}else{Ke=e;e=c}return e}function ft(){var e;if(Le.test(o.charAt(Ke))){e=o.charAt(Ke);Ke++}else{e=c;if(Ye===0){hr(Be)}}return e}function ut(){var e;if(Ge.test(o.charAt(Ke))){e=o.charAt(Ke);Ke++}else{e=c;if(Ye===0){hr(He)}}return e}er=r();if(er!==c&&Ke===o.length){return er}else{if(er!==c&&Ke 0) { 107 | for (i = 1, j = 1; i < descriptions.length; i++) { 108 | if (descriptions[i - 1] !== descriptions[i]) { 109 | descriptions[j] = descriptions[i]; 110 | j++; 111 | } 112 | } 113 | descriptions.length = j; 114 | } 115 | 116 | switch (descriptions.length) { 117 | case 1: 118 | return descriptions[0]; 119 | 120 | case 2: 121 | return descriptions[0] + " or " + descriptions[1]; 122 | 123 | default: 124 | return descriptions.slice(0, -1).join(", ") 125 | + ", or " 126 | + descriptions[descriptions.length - 1]; 127 | } 128 | } 129 | 130 | function describeFound(found) { 131 | return found ? "\"" + literalEscape(found) + "\"" : "end of input"; 132 | } 133 | 134 | return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; 135 | }; 136 | 137 | function peg$parse(input, options) { 138 | options = options !== void 0 ? options : {}; 139 | 140 | var peg$FAILED = {}, 141 | 142 | peg$startRuleFunctions = { uson_text: peg$parseuson_text }, 143 | peg$startRuleFunction = peg$parseuson_text, 144 | 145 | peg$c0 = function(head, tail) { 146 | if(head==null && text()!=="null"){ return [] }; 147 | return [head].concat(tail); 148 | }, 149 | peg$c1 = function(v) {return v}, 150 | peg$c2 = "[", 151 | peg$c3 = peg$literalExpectation("[", false), 152 | peg$c4 = "{", 153 | peg$c5 = peg$literalExpectation("{", false), 154 | peg$c6 = "]", 155 | peg$c7 = peg$literalExpectation("]", false), 156 | peg$c8 = "}", 157 | peg$c9 = peg$literalExpectation("}", false), 158 | peg$c10 = ":", 159 | peg$c11 = peg$literalExpectation(":", false), 160 | peg$c12 = /^[ ,]/, 161 | peg$c13 = peg$classExpectation([" ", ","], false, false), 162 | peg$c14 = "#", 163 | peg$c15 = peg$literalExpectation("#", false), 164 | peg$c16 = "!", 165 | peg$c17 = peg$literalExpectation("!", false), 166 | peg$c18 = /^[ \t\n\r]/, 167 | peg$c19 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false), 168 | peg$c20 = peg$otherExpectation("whitespace"), 169 | peg$c21 = "false", 170 | peg$c22 = peg$literalExpectation("false", false), 171 | peg$c23 = function() { return false; }, 172 | peg$c24 = "null", 173 | peg$c25 = peg$literalExpectation("null", false), 174 | peg$c26 = function() { return null; }, 175 | peg$c27 = "true", 176 | peg$c28 = peg$literalExpectation("true", false), 177 | peg$c29 = function() { return true; }, 178 | peg$c30 = function(first, m) { return m; }, 179 | peg$c31 = function(first, rest) { 180 | var result = {}, i; 181 | result[first.name] = first.value; 182 | for (i = 0; i < rest.length; i++) { 183 | result[rest[i].name] = rest[i].value; 184 | } 185 | return result; 186 | }, 187 | peg$c32 = function(members) { return members !== null ? members: {}; }, 188 | peg$c33 = function(name, value) { 189 | return { name: name, value: value }; 190 | }, 191 | peg$c34 = function(first, v) { return v; }, 192 | peg$c35 = function(first, rest) { return [first].concat(rest); }, 193 | peg$c36 = function(values) { return values !== null ? values : []; }, 194 | peg$c37 = peg$otherExpectation("number"), 195 | peg$c38 = function() { return parseFloat(text()); }, 196 | peg$c39 = ".", 197 | peg$c40 = peg$literalExpectation(".", false), 198 | peg$c41 = /^[1-9]/, 199 | peg$c42 = peg$classExpectation([["1", "9"]], false, false), 200 | peg$c43 = /^[eE]/, 201 | peg$c44 = peg$classExpectation(["e", "E"], false, false), 202 | peg$c45 = "-", 203 | peg$c46 = peg$literalExpectation("-", false), 204 | peg$c47 = "+", 205 | peg$c48 = peg$literalExpectation("+", false), 206 | peg$c49 = "0", 207 | peg$c50 = peg$literalExpectation("0", false), 208 | peg$c51 = peg$otherExpectation("string"), 209 | peg$c52 = function(v) { 210 | var res = v.join(""); 211 | return (res.match(/^[0-9\.]+$/) ? Number(res) : res); 212 | }, 213 | peg$c53 = "'", 214 | peg$c54 = peg$literalExpectation("'", false), 215 | peg$c55 = function(v) { return v.join(""); }, 216 | peg$c56 = "\"", 217 | peg$c57 = peg$literalExpectation("\"", false), 218 | peg$c58 = "\\", 219 | peg$c59 = peg$literalExpectation("\\", false), 220 | peg$c60 = "/", 221 | peg$c61 = peg$literalExpectation("/", false), 222 | peg$c62 = "b", 223 | peg$c63 = peg$literalExpectation("b", false), 224 | peg$c64 = function() { return "\b"; }, 225 | peg$c65 = "f", 226 | peg$c66 = peg$literalExpectation("f", false), 227 | peg$c67 = function() { return "\f"; }, 228 | peg$c68 = "n", 229 | peg$c69 = peg$literalExpectation("n", false), 230 | peg$c70 = function() { return "\n"; }, 231 | peg$c71 = "r", 232 | peg$c72 = peg$literalExpectation("r", false), 233 | peg$c73 = function() { return "\r"; }, 234 | peg$c74 = "t", 235 | peg$c75 = peg$literalExpectation("t", false), 236 | peg$c76 = function() { return "\t"; }, 237 | peg$c77 = "u", 238 | peg$c78 = peg$literalExpectation("u", false), 239 | peg$c79 = function(digits) { 240 | return String.fromCharCode(parseInt(digits, 16)); 241 | }, 242 | peg$c80 = function(sequence) { return sequence; }, 243 | peg$c81 = /^[!$-+\--9;-Z\^-z|~-\u10FFFF]/, 244 | peg$c82 = peg$classExpectation(["!", ["$", "+"], ["-", "9"], [";", "Z"], ["^", "z"], "|", ["~", "\u10FF"], "F", "F"], false, false), 245 | peg$c83 = /^[ -!#-[\]-\u10FFFF]/, 246 | peg$c84 = peg$classExpectation([[" ", "!"], ["#", "["], ["]", "\u10FF"], "F", "F"], false, false), 247 | peg$c85 = /^[ -&(-[\]-\u10FFFF]/, 248 | peg$c86 = peg$classExpectation([[" ", "&"], ["(", "["], ["]", "\u10FF"], "F", "F"], false, false), 249 | peg$c87 = function(m) {var obj={}; obj[m.name] = m.value; return obj}, 250 | peg$c88 = /^[a-zA-Z0-9_\-]/, 251 | peg$c89 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_", "-"], false, false), 252 | peg$c90 = function(name, value) { 253 | var jname = name.join(''); 254 | if(options.type && options.type[jname]) { 255 | return options.type[jname](value, jname); 256 | } 257 | return value; 258 | }, 259 | peg$c91 = /^[^\n\r\u2028\u2029]/, 260 | peg$c92 = peg$classExpectation(["\n", "\r", "\u2028", "\u2029"], true, false), 261 | peg$c93 = /^[0-9]/, 262 | peg$c94 = peg$classExpectation([["0", "9"]], false, false), 263 | peg$c95 = /^[0-9a-f]/i, 264 | peg$c96 = peg$classExpectation([["0", "9"], ["a", "f"]], false, true), 265 | 266 | peg$currPos = 0, 267 | peg$savedPos = 0, 268 | peg$posDetailsCache = [{ line: 1, column: 1 }], 269 | peg$maxFailPos = 0, 270 | peg$maxFailExpected = [], 271 | peg$silentFails = 0, 272 | 273 | peg$result; 274 | 275 | if ("startRule" in options) { 276 | if (!(options.startRule in peg$startRuleFunctions)) { 277 | throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); 278 | } 279 | 280 | peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; 281 | } 282 | 283 | function text() { 284 | return input.substring(peg$savedPos, peg$currPos); 285 | } 286 | 287 | function location() { 288 | return peg$computeLocation(peg$savedPos, peg$currPos); 289 | } 290 | 291 | function expected(description, location) { 292 | location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) 293 | 294 | throw peg$buildStructuredError( 295 | [peg$otherExpectation(description)], 296 | input.substring(peg$savedPos, peg$currPos), 297 | location 298 | ); 299 | } 300 | 301 | function error(message, location) { 302 | location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) 303 | 304 | throw peg$buildSimpleError(message, location); 305 | } 306 | 307 | function peg$literalExpectation(text, ignoreCase) { 308 | return { type: "literal", text: text, ignoreCase: ignoreCase }; 309 | } 310 | 311 | function peg$classExpectation(parts, inverted, ignoreCase) { 312 | return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; 313 | } 314 | 315 | function peg$anyExpectation() { 316 | return { type: "any" }; 317 | } 318 | 319 | function peg$endExpectation() { 320 | return { type: "end" }; 321 | } 322 | 323 | function peg$otherExpectation(description) { 324 | return { type: "other", description: description }; 325 | } 326 | 327 | function peg$computePosDetails(pos) { 328 | var details = peg$posDetailsCache[pos], p; 329 | 330 | if (details) { 331 | return details; 332 | } else { 333 | p = pos - 1; 334 | while (!peg$posDetailsCache[p]) { 335 | p--; 336 | } 337 | 338 | details = peg$posDetailsCache[p]; 339 | details = { 340 | line: details.line, 341 | column: details.column 342 | }; 343 | 344 | while (p < pos) { 345 | if (input.charCodeAt(p) === 10) { 346 | details.line++; 347 | details.column = 1; 348 | } else { 349 | details.column++; 350 | } 351 | 352 | p++; 353 | } 354 | 355 | peg$posDetailsCache[pos] = details; 356 | return details; 357 | } 358 | } 359 | 360 | function peg$computeLocation(startPos, endPos) { 361 | var startPosDetails = peg$computePosDetails(startPos), 362 | endPosDetails = peg$computePosDetails(endPos); 363 | 364 | return { 365 | start: { 366 | offset: startPos, 367 | line: startPosDetails.line, 368 | column: startPosDetails.column 369 | }, 370 | end: { 371 | offset: endPos, 372 | line: endPosDetails.line, 373 | column: endPosDetails.column 374 | } 375 | }; 376 | } 377 | 378 | function peg$fail(expected) { 379 | if (peg$currPos < peg$maxFailPos) { return; } 380 | 381 | if (peg$currPos > peg$maxFailPos) { 382 | peg$maxFailPos = peg$currPos; 383 | peg$maxFailExpected = []; 384 | } 385 | 386 | peg$maxFailExpected.push(expected); 387 | } 388 | 389 | function peg$buildSimpleError(message, location) { 390 | return new peg$SyntaxError(message, null, null, location); 391 | } 392 | 393 | function peg$buildStructuredError(expected, found, location) { 394 | return new peg$SyntaxError( 395 | peg$SyntaxError.buildMessage(expected, found), 396 | expected, 397 | found, 398 | location 399 | ); 400 | } 401 | 402 | function peg$parseuson_text() { 403 | var s0, s1, s2, s3, s4; 404 | 405 | s0 = peg$currPos; 406 | s1 = peg$parseexpr(); 407 | if (s1 === peg$FAILED) { 408 | s1 = null; 409 | } 410 | if (s1 !== peg$FAILED) { 411 | s2 = peg$parsews(); 412 | if (s2 !== peg$FAILED) { 413 | s3 = []; 414 | s4 = peg$parseexpr(); 415 | while (s4 !== peg$FAILED) { 416 | s3.push(s4); 417 | s4 = peg$parseexpr(); 418 | } 419 | if (s3 !== peg$FAILED) { 420 | peg$savedPos = s0; 421 | s1 = peg$c0(s1, s3); 422 | s0 = s1; 423 | } else { 424 | peg$currPos = s0; 425 | s0 = peg$FAILED; 426 | } 427 | } else { 428 | peg$currPos = s0; 429 | s0 = peg$FAILED; 430 | } 431 | } else { 432 | peg$currPos = s0; 433 | s0 = peg$FAILED; 434 | } 435 | 436 | return s0; 437 | } 438 | 439 | function peg$parseexpr() { 440 | var s0, s1, s2, s3; 441 | 442 | s0 = peg$currPos; 443 | s1 = peg$parsews(); 444 | if (s1 !== peg$FAILED) { 445 | s2 = peg$parsevalue(); 446 | if (s2 !== peg$FAILED) { 447 | s3 = peg$parsews(); 448 | if (s3 !== peg$FAILED) { 449 | peg$savedPos = s0; 450 | s1 = peg$c1(s2); 451 | s0 = s1; 452 | } else { 453 | peg$currPos = s0; 454 | s0 = peg$FAILED; 455 | } 456 | } else { 457 | peg$currPos = s0; 458 | s0 = peg$FAILED; 459 | } 460 | } else { 461 | peg$currPos = s0; 462 | s0 = peg$FAILED; 463 | } 464 | 465 | return s0; 466 | } 467 | 468 | function peg$parsebegin_array() { 469 | var s0, s1, s2, s3; 470 | 471 | s0 = peg$currPos; 472 | s1 = peg$parsews(); 473 | if (s1 !== peg$FAILED) { 474 | if (input.charCodeAt(peg$currPos) === 91) { 475 | s2 = peg$c2; 476 | peg$currPos++; 477 | } else { 478 | s2 = peg$FAILED; 479 | if (peg$silentFails === 0) { peg$fail(peg$c3); } 480 | } 481 | if (s2 !== peg$FAILED) { 482 | s3 = peg$parsews(); 483 | if (s3 !== peg$FAILED) { 484 | s1 = [s1, s2, s3]; 485 | s0 = s1; 486 | } else { 487 | peg$currPos = s0; 488 | s0 = peg$FAILED; 489 | } 490 | } else { 491 | peg$currPos = s0; 492 | s0 = peg$FAILED; 493 | } 494 | } else { 495 | peg$currPos = s0; 496 | s0 = peg$FAILED; 497 | } 498 | 499 | return s0; 500 | } 501 | 502 | function peg$parsebegin_object() { 503 | var s0, s1, s2, s3; 504 | 505 | s0 = peg$currPos; 506 | s1 = peg$parsews(); 507 | if (s1 !== peg$FAILED) { 508 | if (input.charCodeAt(peg$currPos) === 123) { 509 | s2 = peg$c4; 510 | peg$currPos++; 511 | } else { 512 | s2 = peg$FAILED; 513 | if (peg$silentFails === 0) { peg$fail(peg$c5); } 514 | } 515 | if (s2 !== peg$FAILED) { 516 | s3 = peg$parsews(); 517 | if (s3 !== peg$FAILED) { 518 | s1 = [s1, s2, s3]; 519 | s0 = s1; 520 | } else { 521 | peg$currPos = s0; 522 | s0 = peg$FAILED; 523 | } 524 | } else { 525 | peg$currPos = s0; 526 | s0 = peg$FAILED; 527 | } 528 | } else { 529 | peg$currPos = s0; 530 | s0 = peg$FAILED; 531 | } 532 | 533 | return s0; 534 | } 535 | 536 | function peg$parseend_array() { 537 | var s0, s1, s2, s3; 538 | 539 | s0 = peg$currPos; 540 | s1 = peg$parsews(); 541 | if (s1 !== peg$FAILED) { 542 | if (input.charCodeAt(peg$currPos) === 93) { 543 | s2 = peg$c6; 544 | peg$currPos++; 545 | } else { 546 | s2 = peg$FAILED; 547 | if (peg$silentFails === 0) { peg$fail(peg$c7); } 548 | } 549 | if (s2 !== peg$FAILED) { 550 | s3 = peg$parsews(); 551 | if (s3 !== peg$FAILED) { 552 | s1 = [s1, s2, s3]; 553 | s0 = s1; 554 | } else { 555 | peg$currPos = s0; 556 | s0 = peg$FAILED; 557 | } 558 | } else { 559 | peg$currPos = s0; 560 | s0 = peg$FAILED; 561 | } 562 | } else { 563 | peg$currPos = s0; 564 | s0 = peg$FAILED; 565 | } 566 | 567 | return s0; 568 | } 569 | 570 | function peg$parseend_object() { 571 | var s0, s1, s2, s3; 572 | 573 | s0 = peg$currPos; 574 | s1 = peg$parsews(); 575 | if (s1 !== peg$FAILED) { 576 | if (input.charCodeAt(peg$currPos) === 125) { 577 | s2 = peg$c8; 578 | peg$currPos++; 579 | } else { 580 | s2 = peg$FAILED; 581 | if (peg$silentFails === 0) { peg$fail(peg$c9); } 582 | } 583 | if (s2 !== peg$FAILED) { 584 | s3 = peg$parsews(); 585 | if (s3 !== peg$FAILED) { 586 | s1 = [s1, s2, s3]; 587 | s0 = s1; 588 | } else { 589 | peg$currPos = s0; 590 | s0 = peg$FAILED; 591 | } 592 | } else { 593 | peg$currPos = s0; 594 | s0 = peg$FAILED; 595 | } 596 | } else { 597 | peg$currPos = s0; 598 | s0 = peg$FAILED; 599 | } 600 | 601 | return s0; 602 | } 603 | 604 | function peg$parsename_separator() { 605 | var s0, s1, s2, s3; 606 | 607 | s0 = peg$currPos; 608 | s1 = peg$parsews(); 609 | if (s1 !== peg$FAILED) { 610 | if (input.charCodeAt(peg$currPos) === 58) { 611 | s2 = peg$c10; 612 | peg$currPos++; 613 | } else { 614 | s2 = peg$FAILED; 615 | if (peg$silentFails === 0) { peg$fail(peg$c11); } 616 | } 617 | if (s2 !== peg$FAILED) { 618 | s3 = peg$parsews(); 619 | if (s3 !== peg$FAILED) { 620 | s1 = [s1, s2, s3]; 621 | s0 = s1; 622 | } else { 623 | peg$currPos = s0; 624 | s0 = peg$FAILED; 625 | } 626 | } else { 627 | peg$currPos = s0; 628 | s0 = peg$FAILED; 629 | } 630 | } else { 631 | peg$currPos = s0; 632 | s0 = peg$FAILED; 633 | } 634 | 635 | return s0; 636 | } 637 | 638 | function peg$parsevalue_separator() { 639 | var s0, s1, s2, s3; 640 | 641 | s0 = peg$currPos; 642 | s1 = peg$parsews(); 643 | if (s1 !== peg$FAILED) { 644 | s2 = []; 645 | if (peg$c12.test(input.charAt(peg$currPos))) { 646 | s3 = input.charAt(peg$currPos); 647 | peg$currPos++; 648 | } else { 649 | s3 = peg$FAILED; 650 | if (peg$silentFails === 0) { peg$fail(peg$c13); } 651 | } 652 | while (s3 !== peg$FAILED) { 653 | s2.push(s3); 654 | if (peg$c12.test(input.charAt(peg$currPos))) { 655 | s3 = input.charAt(peg$currPos); 656 | peg$currPos++; 657 | } else { 658 | s3 = peg$FAILED; 659 | if (peg$silentFails === 0) { peg$fail(peg$c13); } 660 | } 661 | } 662 | if (s2 !== peg$FAILED) { 663 | s3 = peg$parsews(); 664 | if (s3 !== peg$FAILED) { 665 | s1 = [s1, s2, s3]; 666 | s0 = s1; 667 | } else { 668 | peg$currPos = s0; 669 | s0 = peg$FAILED; 670 | } 671 | } else { 672 | peg$currPos = s0; 673 | s0 = peg$FAILED; 674 | } 675 | } else { 676 | peg$currPos = s0; 677 | s0 = peg$FAILED; 678 | } 679 | 680 | return s0; 681 | } 682 | 683 | function peg$parsecomment_start() { 684 | var s0; 685 | 686 | if (input.charCodeAt(peg$currPos) === 35) { 687 | s0 = peg$c14; 688 | peg$currPos++; 689 | } else { 690 | s0 = peg$FAILED; 691 | if (peg$silentFails === 0) { peg$fail(peg$c15); } 692 | } 693 | 694 | return s0; 695 | } 696 | 697 | function peg$parsetyped_start() { 698 | var s0, s1, s2, s3; 699 | 700 | s0 = peg$currPos; 701 | s1 = peg$parsews(); 702 | if (s1 !== peg$FAILED) { 703 | if (input.charCodeAt(peg$currPos) === 33) { 704 | s2 = peg$c16; 705 | peg$currPos++; 706 | } else { 707 | s2 = peg$FAILED; 708 | if (peg$silentFails === 0) { peg$fail(peg$c17); } 709 | } 710 | if (s2 !== peg$FAILED) { 711 | s3 = peg$parsews(); 712 | if (s3 !== peg$FAILED) { 713 | s1 = [s1, s2, s3]; 714 | s0 = s1; 715 | } else { 716 | peg$currPos = s0; 717 | s0 = peg$FAILED; 718 | } 719 | } else { 720 | peg$currPos = s0; 721 | s0 = peg$FAILED; 722 | } 723 | } else { 724 | peg$currPos = s0; 725 | s0 = peg$FAILED; 726 | } 727 | 728 | return s0; 729 | } 730 | 731 | function peg$parsews_char() { 732 | var s0; 733 | 734 | if (peg$c18.test(input.charAt(peg$currPos))) { 735 | s0 = input.charAt(peg$currPos); 736 | peg$currPos++; 737 | } else { 738 | s0 = peg$FAILED; 739 | if (peg$silentFails === 0) { peg$fail(peg$c19); } 740 | } 741 | 742 | return s0; 743 | } 744 | 745 | function peg$parsews() { 746 | var s0, s1, s2; 747 | 748 | peg$silentFails++; 749 | s0 = peg$currPos; 750 | s1 = []; 751 | s2 = peg$parsews_char(); 752 | while (s2 !== peg$FAILED) { 753 | s1.push(s2); 754 | s2 = peg$parsews_char(); 755 | } 756 | if (s1 !== peg$FAILED) { 757 | s2 = peg$parsecomment(); 758 | if (s2 === peg$FAILED) { 759 | s2 = null; 760 | } 761 | if (s2 !== peg$FAILED) { 762 | s1 = [s1, s2]; 763 | s0 = s1; 764 | } else { 765 | peg$currPos = s0; 766 | s0 = peg$FAILED; 767 | } 768 | } else { 769 | peg$currPos = s0; 770 | s0 = peg$FAILED; 771 | } 772 | peg$silentFails--; 773 | if (s0 === peg$FAILED) { 774 | s1 = peg$FAILED; 775 | if (peg$silentFails === 0) { peg$fail(peg$c20); } 776 | } 777 | 778 | return s0; 779 | } 780 | 781 | function peg$parsevalue() { 782 | var s0; 783 | 784 | s0 = peg$parsetyped(); 785 | if (s0 === peg$FAILED) { 786 | s0 = peg$parsefalse(); 787 | if (s0 === peg$FAILED) { 788 | s0 = peg$parsenull(); 789 | if (s0 === peg$FAILED) { 790 | s0 = peg$parsetrue(); 791 | if (s0 === peg$FAILED) { 792 | s0 = peg$parseassign(); 793 | if (s0 === peg$FAILED) { 794 | s0 = peg$parseobject(); 795 | if (s0 === peg$FAILED) { 796 | s0 = peg$parsearray(); 797 | if (s0 === peg$FAILED) { 798 | s0 = peg$parsestring(); 799 | if (s0 === peg$FAILED) { 800 | s0 = peg$parsenumber(); 801 | } 802 | } 803 | } 804 | } 805 | } 806 | } 807 | } 808 | } 809 | 810 | return s0; 811 | } 812 | 813 | function peg$parsefalse() { 814 | var s0, s1; 815 | 816 | s0 = peg$currPos; 817 | if (input.substr(peg$currPos, 5) === peg$c21) { 818 | s1 = peg$c21; 819 | peg$currPos += 5; 820 | } else { 821 | s1 = peg$FAILED; 822 | if (peg$silentFails === 0) { peg$fail(peg$c22); } 823 | } 824 | if (s1 !== peg$FAILED) { 825 | peg$savedPos = s0; 826 | s1 = peg$c23(); 827 | } 828 | s0 = s1; 829 | 830 | return s0; 831 | } 832 | 833 | function peg$parsenull() { 834 | var s0, s1; 835 | 836 | s0 = peg$currPos; 837 | if (input.substr(peg$currPos, 4) === peg$c24) { 838 | s1 = peg$c24; 839 | peg$currPos += 4; 840 | } else { 841 | s1 = peg$FAILED; 842 | if (peg$silentFails === 0) { peg$fail(peg$c25); } 843 | } 844 | if (s1 !== peg$FAILED) { 845 | peg$savedPos = s0; 846 | s1 = peg$c26(); 847 | } 848 | s0 = s1; 849 | 850 | return s0; 851 | } 852 | 853 | function peg$parsetrue() { 854 | var s0, s1; 855 | 856 | s0 = peg$currPos; 857 | if (input.substr(peg$currPos, 4) === peg$c27) { 858 | s1 = peg$c27; 859 | peg$currPos += 4; 860 | } else { 861 | s1 = peg$FAILED; 862 | if (peg$silentFails === 0) { peg$fail(peg$c28); } 863 | } 864 | if (s1 !== peg$FAILED) { 865 | peg$savedPos = s0; 866 | s1 = peg$c29(); 867 | } 868 | s0 = s1; 869 | 870 | return s0; 871 | } 872 | 873 | function peg$parseobject() { 874 | var s0, s1, s2, s3, s4, s5, s6, s7; 875 | 876 | s0 = peg$currPos; 877 | s1 = peg$parsebegin_object(); 878 | if (s1 !== peg$FAILED) { 879 | s2 = peg$currPos; 880 | s3 = peg$parsemember(); 881 | if (s3 !== peg$FAILED) { 882 | s4 = []; 883 | s5 = peg$currPos; 884 | s6 = peg$parsevalue_separator(); 885 | if (s6 !== peg$FAILED) { 886 | s7 = peg$parsemember(); 887 | if (s7 !== peg$FAILED) { 888 | peg$savedPos = s5; 889 | s6 = peg$c30(s3, s7); 890 | s5 = s6; 891 | } else { 892 | peg$currPos = s5; 893 | s5 = peg$FAILED; 894 | } 895 | } else { 896 | peg$currPos = s5; 897 | s5 = peg$FAILED; 898 | } 899 | while (s5 !== peg$FAILED) { 900 | s4.push(s5); 901 | s5 = peg$currPos; 902 | s6 = peg$parsevalue_separator(); 903 | if (s6 !== peg$FAILED) { 904 | s7 = peg$parsemember(); 905 | if (s7 !== peg$FAILED) { 906 | peg$savedPos = s5; 907 | s6 = peg$c30(s3, s7); 908 | s5 = s6; 909 | } else { 910 | peg$currPos = s5; 911 | s5 = peg$FAILED; 912 | } 913 | } else { 914 | peg$currPos = s5; 915 | s5 = peg$FAILED; 916 | } 917 | } 918 | if (s4 !== peg$FAILED) { 919 | peg$savedPos = s2; 920 | s3 = peg$c31(s3, s4); 921 | s2 = s3; 922 | } else { 923 | peg$currPos = s2; 924 | s2 = peg$FAILED; 925 | } 926 | } else { 927 | peg$currPos = s2; 928 | s2 = peg$FAILED; 929 | } 930 | if (s2 === peg$FAILED) { 931 | s2 = null; 932 | } 933 | if (s2 !== peg$FAILED) { 934 | s3 = peg$parseend_object(); 935 | if (s3 !== peg$FAILED) { 936 | peg$savedPos = s0; 937 | s1 = peg$c32(s2); 938 | s0 = s1; 939 | } else { 940 | peg$currPos = s0; 941 | s0 = peg$FAILED; 942 | } 943 | } else { 944 | peg$currPos = s0; 945 | s0 = peg$FAILED; 946 | } 947 | } else { 948 | peg$currPos = s0; 949 | s0 = peg$FAILED; 950 | } 951 | 952 | return s0; 953 | } 954 | 955 | function peg$parsemember() { 956 | var s0, s1, s2, s3; 957 | 958 | s0 = peg$currPos; 959 | s1 = peg$parsestring(); 960 | if (s1 !== peg$FAILED) { 961 | s2 = peg$parsename_separator(); 962 | if (s2 !== peg$FAILED) { 963 | s3 = peg$parseexpr(); 964 | if (s3 !== peg$FAILED) { 965 | peg$savedPos = s0; 966 | s1 = peg$c33(s1, s3); 967 | s0 = s1; 968 | } else { 969 | peg$currPos = s0; 970 | s0 = peg$FAILED; 971 | } 972 | } else { 973 | peg$currPos = s0; 974 | s0 = peg$FAILED; 975 | } 976 | } else { 977 | peg$currPos = s0; 978 | s0 = peg$FAILED; 979 | } 980 | 981 | return s0; 982 | } 983 | 984 | function peg$parsearray() { 985 | var s0, s1, s2, s3, s4, s5, s6, s7; 986 | 987 | s0 = peg$currPos; 988 | s1 = peg$parsebegin_array(); 989 | if (s1 !== peg$FAILED) { 990 | s2 = peg$currPos; 991 | s3 = peg$parseexpr(); 992 | if (s3 !== peg$FAILED) { 993 | s4 = []; 994 | s5 = peg$currPos; 995 | s6 = peg$parsevalue_separator(); 996 | if (s6 === peg$FAILED) { 997 | s6 = null; 998 | } 999 | if (s6 !== peg$FAILED) { 1000 | s7 = peg$parseexpr(); 1001 | if (s7 !== peg$FAILED) { 1002 | peg$savedPos = s5; 1003 | s6 = peg$c34(s3, s7); 1004 | s5 = s6; 1005 | } else { 1006 | peg$currPos = s5; 1007 | s5 = peg$FAILED; 1008 | } 1009 | } else { 1010 | peg$currPos = s5; 1011 | s5 = peg$FAILED; 1012 | } 1013 | while (s5 !== peg$FAILED) { 1014 | s4.push(s5); 1015 | s5 = peg$currPos; 1016 | s6 = peg$parsevalue_separator(); 1017 | if (s6 === peg$FAILED) { 1018 | s6 = null; 1019 | } 1020 | if (s6 !== peg$FAILED) { 1021 | s7 = peg$parseexpr(); 1022 | if (s7 !== peg$FAILED) { 1023 | peg$savedPos = s5; 1024 | s6 = peg$c34(s3, s7); 1025 | s5 = s6; 1026 | } else { 1027 | peg$currPos = s5; 1028 | s5 = peg$FAILED; 1029 | } 1030 | } else { 1031 | peg$currPos = s5; 1032 | s5 = peg$FAILED; 1033 | } 1034 | } 1035 | if (s4 !== peg$FAILED) { 1036 | peg$savedPos = s2; 1037 | s3 = peg$c35(s3, s4); 1038 | s2 = s3; 1039 | } else { 1040 | peg$currPos = s2; 1041 | s2 = peg$FAILED; 1042 | } 1043 | } else { 1044 | peg$currPos = s2; 1045 | s2 = peg$FAILED; 1046 | } 1047 | if (s2 === peg$FAILED) { 1048 | s2 = null; 1049 | } 1050 | if (s2 !== peg$FAILED) { 1051 | s3 = peg$parseend_array(); 1052 | if (s3 !== peg$FAILED) { 1053 | peg$savedPos = s0; 1054 | s1 = peg$c36(s2); 1055 | s0 = s1; 1056 | } else { 1057 | peg$currPos = s0; 1058 | s0 = peg$FAILED; 1059 | } 1060 | } else { 1061 | peg$currPos = s0; 1062 | s0 = peg$FAILED; 1063 | } 1064 | } else { 1065 | peg$currPos = s0; 1066 | s0 = peg$FAILED; 1067 | } 1068 | 1069 | return s0; 1070 | } 1071 | 1072 | function peg$parsenumber() { 1073 | var s0, s1, s2, s3, s4; 1074 | 1075 | peg$silentFails++; 1076 | s0 = peg$currPos; 1077 | s1 = peg$parseminus(); 1078 | if (s1 === peg$FAILED) { 1079 | s1 = null; 1080 | } 1081 | if (s1 !== peg$FAILED) { 1082 | s2 = peg$parseint(); 1083 | if (s2 !== peg$FAILED) { 1084 | s3 = peg$parsefrac(); 1085 | if (s3 === peg$FAILED) { 1086 | s3 = null; 1087 | } 1088 | if (s3 !== peg$FAILED) { 1089 | s4 = peg$parseexp(); 1090 | if (s4 === peg$FAILED) { 1091 | s4 = null; 1092 | } 1093 | if (s4 !== peg$FAILED) { 1094 | peg$savedPos = s0; 1095 | s1 = peg$c38(); 1096 | s0 = s1; 1097 | } else { 1098 | peg$currPos = s0; 1099 | s0 = peg$FAILED; 1100 | } 1101 | } else { 1102 | peg$currPos = s0; 1103 | s0 = peg$FAILED; 1104 | } 1105 | } else { 1106 | peg$currPos = s0; 1107 | s0 = peg$FAILED; 1108 | } 1109 | } else { 1110 | peg$currPos = s0; 1111 | s0 = peg$FAILED; 1112 | } 1113 | peg$silentFails--; 1114 | if (s0 === peg$FAILED) { 1115 | s1 = peg$FAILED; 1116 | if (peg$silentFails === 0) { peg$fail(peg$c37); } 1117 | } 1118 | 1119 | return s0; 1120 | } 1121 | 1122 | function peg$parsedecimal_point() { 1123 | var s0; 1124 | 1125 | if (input.charCodeAt(peg$currPos) === 46) { 1126 | s0 = peg$c39; 1127 | peg$currPos++; 1128 | } else { 1129 | s0 = peg$FAILED; 1130 | if (peg$silentFails === 0) { peg$fail(peg$c40); } 1131 | } 1132 | 1133 | return s0; 1134 | } 1135 | 1136 | function peg$parsedigit1_9() { 1137 | var s0; 1138 | 1139 | if (peg$c41.test(input.charAt(peg$currPos))) { 1140 | s0 = input.charAt(peg$currPos); 1141 | peg$currPos++; 1142 | } else { 1143 | s0 = peg$FAILED; 1144 | if (peg$silentFails === 0) { peg$fail(peg$c42); } 1145 | } 1146 | 1147 | return s0; 1148 | } 1149 | 1150 | function peg$parsee() { 1151 | var s0; 1152 | 1153 | if (peg$c43.test(input.charAt(peg$currPos))) { 1154 | s0 = input.charAt(peg$currPos); 1155 | peg$currPos++; 1156 | } else { 1157 | s0 = peg$FAILED; 1158 | if (peg$silentFails === 0) { peg$fail(peg$c44); } 1159 | } 1160 | 1161 | return s0; 1162 | } 1163 | 1164 | function peg$parseexp() { 1165 | var s0, s1, s2, s3, s4; 1166 | 1167 | s0 = peg$currPos; 1168 | s1 = peg$parsee(); 1169 | if (s1 !== peg$FAILED) { 1170 | s2 = peg$parseminus(); 1171 | if (s2 === peg$FAILED) { 1172 | s2 = peg$parseplus(); 1173 | } 1174 | if (s2 === peg$FAILED) { 1175 | s2 = null; 1176 | } 1177 | if (s2 !== peg$FAILED) { 1178 | s3 = []; 1179 | s4 = peg$parseDIGIT(); 1180 | if (s4 !== peg$FAILED) { 1181 | while (s4 !== peg$FAILED) { 1182 | s3.push(s4); 1183 | s4 = peg$parseDIGIT(); 1184 | } 1185 | } else { 1186 | s3 = peg$FAILED; 1187 | } 1188 | if (s3 !== peg$FAILED) { 1189 | s1 = [s1, s2, s3]; 1190 | s0 = s1; 1191 | } else { 1192 | peg$currPos = s0; 1193 | s0 = peg$FAILED; 1194 | } 1195 | } else { 1196 | peg$currPos = s0; 1197 | s0 = peg$FAILED; 1198 | } 1199 | } else { 1200 | peg$currPos = s0; 1201 | s0 = peg$FAILED; 1202 | } 1203 | 1204 | return s0; 1205 | } 1206 | 1207 | function peg$parsefrac() { 1208 | var s0, s1, s2, s3; 1209 | 1210 | s0 = peg$currPos; 1211 | s1 = peg$parsedecimal_point(); 1212 | if (s1 !== peg$FAILED) { 1213 | s2 = []; 1214 | s3 = peg$parseDIGIT(); 1215 | if (s3 !== peg$FAILED) { 1216 | while (s3 !== peg$FAILED) { 1217 | s2.push(s3); 1218 | s3 = peg$parseDIGIT(); 1219 | } 1220 | } else { 1221 | s2 = peg$FAILED; 1222 | } 1223 | if (s2 !== peg$FAILED) { 1224 | s1 = [s1, s2]; 1225 | s0 = s1; 1226 | } else { 1227 | peg$currPos = s0; 1228 | s0 = peg$FAILED; 1229 | } 1230 | } else { 1231 | peg$currPos = s0; 1232 | s0 = peg$FAILED; 1233 | } 1234 | 1235 | return s0; 1236 | } 1237 | 1238 | function peg$parseint() { 1239 | var s0, s1, s2, s3; 1240 | 1241 | s0 = peg$parsezero(); 1242 | if (s0 === peg$FAILED) { 1243 | s0 = peg$currPos; 1244 | s1 = peg$parsedigit1_9(); 1245 | if (s1 !== peg$FAILED) { 1246 | s2 = []; 1247 | s3 = peg$parseDIGIT(); 1248 | while (s3 !== peg$FAILED) { 1249 | s2.push(s3); 1250 | s3 = peg$parseDIGIT(); 1251 | } 1252 | if (s2 !== peg$FAILED) { 1253 | s1 = [s1, s2]; 1254 | s0 = s1; 1255 | } else { 1256 | peg$currPos = s0; 1257 | s0 = peg$FAILED; 1258 | } 1259 | } else { 1260 | peg$currPos = s0; 1261 | s0 = peg$FAILED; 1262 | } 1263 | } 1264 | 1265 | return s0; 1266 | } 1267 | 1268 | function peg$parseminus() { 1269 | var s0; 1270 | 1271 | if (input.charCodeAt(peg$currPos) === 45) { 1272 | s0 = peg$c45; 1273 | peg$currPos++; 1274 | } else { 1275 | s0 = peg$FAILED; 1276 | if (peg$silentFails === 0) { peg$fail(peg$c46); } 1277 | } 1278 | 1279 | return s0; 1280 | } 1281 | 1282 | function peg$parseplus() { 1283 | var s0; 1284 | 1285 | if (input.charCodeAt(peg$currPos) === 43) { 1286 | s0 = peg$c47; 1287 | peg$currPos++; 1288 | } else { 1289 | s0 = peg$FAILED; 1290 | if (peg$silentFails === 0) { peg$fail(peg$c48); } 1291 | } 1292 | 1293 | return s0; 1294 | } 1295 | 1296 | function peg$parsezero() { 1297 | var s0; 1298 | 1299 | if (input.charCodeAt(peg$currPos) === 48) { 1300 | s0 = peg$c49; 1301 | peg$currPos++; 1302 | } else { 1303 | s0 = peg$FAILED; 1304 | if (peg$silentFails === 0) { peg$fail(peg$c50); } 1305 | } 1306 | 1307 | return s0; 1308 | } 1309 | 1310 | function peg$parsestring() { 1311 | var s0, s1; 1312 | 1313 | peg$silentFails++; 1314 | s0 = peg$parsedouble_quoted_string(); 1315 | if (s0 === peg$FAILED) { 1316 | s0 = peg$parsesingle_quoted_string(); 1317 | if (s0 === peg$FAILED) { 1318 | s0 = peg$parseunquoted_string(); 1319 | } 1320 | } 1321 | peg$silentFails--; 1322 | if (s0 === peg$FAILED) { 1323 | s1 = peg$FAILED; 1324 | if (peg$silentFails === 0) { peg$fail(peg$c51); } 1325 | } 1326 | 1327 | return s0; 1328 | } 1329 | 1330 | function peg$parseunquoted_string() { 1331 | var s0, s1, s2; 1332 | 1333 | s0 = peg$currPos; 1334 | s1 = []; 1335 | s2 = peg$parsesimple_char(); 1336 | if (s2 !== peg$FAILED) { 1337 | while (s2 !== peg$FAILED) { 1338 | s1.push(s2); 1339 | s2 = peg$parsesimple_char(); 1340 | } 1341 | } else { 1342 | s1 = peg$FAILED; 1343 | } 1344 | if (s1 !== peg$FAILED) { 1345 | peg$savedPos = s0; 1346 | s1 = peg$c52(s1); 1347 | } 1348 | s0 = s1; 1349 | 1350 | return s0; 1351 | } 1352 | 1353 | function peg$parsesingle_quoted_string() { 1354 | var s0, s1, s2, s3; 1355 | 1356 | s0 = peg$currPos; 1357 | if (input.charCodeAt(peg$currPos) === 39) { 1358 | s1 = peg$c53; 1359 | peg$currPos++; 1360 | } else { 1361 | s1 = peg$FAILED; 1362 | if (peg$silentFails === 0) { peg$fail(peg$c54); } 1363 | } 1364 | if (s1 !== peg$FAILED) { 1365 | s2 = []; 1366 | s3 = peg$parsechar_single_quoted(); 1367 | while (s3 !== peg$FAILED) { 1368 | s2.push(s3); 1369 | s3 = peg$parsechar_single_quoted(); 1370 | } 1371 | if (s2 !== peg$FAILED) { 1372 | if (input.charCodeAt(peg$currPos) === 39) { 1373 | s3 = peg$c53; 1374 | peg$currPos++; 1375 | } else { 1376 | s3 = peg$FAILED; 1377 | if (peg$silentFails === 0) { peg$fail(peg$c54); } 1378 | } 1379 | if (s3 !== peg$FAILED) { 1380 | peg$savedPos = s0; 1381 | s1 = peg$c55(s2); 1382 | s0 = s1; 1383 | } else { 1384 | peg$currPos = s0; 1385 | s0 = peg$FAILED; 1386 | } 1387 | } else { 1388 | peg$currPos = s0; 1389 | s0 = peg$FAILED; 1390 | } 1391 | } else { 1392 | peg$currPos = s0; 1393 | s0 = peg$FAILED; 1394 | } 1395 | 1396 | return s0; 1397 | } 1398 | 1399 | function peg$parsedouble_quoted_string() { 1400 | var s0, s1, s2, s3; 1401 | 1402 | s0 = peg$currPos; 1403 | if (input.charCodeAt(peg$currPos) === 34) { 1404 | s1 = peg$c56; 1405 | peg$currPos++; 1406 | } else { 1407 | s1 = peg$FAILED; 1408 | if (peg$silentFails === 0) { peg$fail(peg$c57); } 1409 | } 1410 | if (s1 !== peg$FAILED) { 1411 | s2 = []; 1412 | s3 = peg$parsechar_double_quoted(); 1413 | while (s3 !== peg$FAILED) { 1414 | s2.push(s3); 1415 | s3 = peg$parsechar_double_quoted(); 1416 | } 1417 | if (s2 !== peg$FAILED) { 1418 | if (input.charCodeAt(peg$currPos) === 34) { 1419 | s3 = peg$c56; 1420 | peg$currPos++; 1421 | } else { 1422 | s3 = peg$FAILED; 1423 | if (peg$silentFails === 0) { peg$fail(peg$c57); } 1424 | } 1425 | if (s3 !== peg$FAILED) { 1426 | peg$savedPos = s0; 1427 | s1 = peg$c55(s2); 1428 | s0 = s1; 1429 | } else { 1430 | peg$currPos = s0; 1431 | s0 = peg$FAILED; 1432 | } 1433 | } else { 1434 | peg$currPos = s0; 1435 | s0 = peg$FAILED; 1436 | } 1437 | } else { 1438 | peg$currPos = s0; 1439 | s0 = peg$FAILED; 1440 | } 1441 | 1442 | return s0; 1443 | } 1444 | 1445 | function peg$parsesimple_char() { 1446 | var s0; 1447 | 1448 | s0 = peg$parseunescaped_simple(); 1449 | if (s0 === peg$FAILED) { 1450 | s0 = peg$parseescaped_char(); 1451 | } 1452 | 1453 | return s0; 1454 | } 1455 | 1456 | function peg$parsechar_single_quoted() { 1457 | var s0; 1458 | 1459 | s0 = peg$parseunescaped_single_quote(); 1460 | if (s0 === peg$FAILED) { 1461 | s0 = peg$parseescaped_char(); 1462 | } 1463 | 1464 | return s0; 1465 | } 1466 | 1467 | function peg$parsechar_double_quoted() { 1468 | var s0; 1469 | 1470 | s0 = peg$parseunescaped_double_quote(); 1471 | if (s0 === peg$FAILED) { 1472 | s0 = peg$parseescaped_char(); 1473 | } 1474 | 1475 | return s0; 1476 | } 1477 | 1478 | function peg$parseescaped_char() { 1479 | var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; 1480 | 1481 | s0 = peg$currPos; 1482 | s1 = peg$parseescape(); 1483 | if (s1 !== peg$FAILED) { 1484 | if (input.charCodeAt(peg$currPos) === 34) { 1485 | s2 = peg$c56; 1486 | peg$currPos++; 1487 | } else { 1488 | s2 = peg$FAILED; 1489 | if (peg$silentFails === 0) { peg$fail(peg$c57); } 1490 | } 1491 | if (s2 === peg$FAILED) { 1492 | if (input.charCodeAt(peg$currPos) === 39) { 1493 | s2 = peg$c53; 1494 | peg$currPos++; 1495 | } else { 1496 | s2 = peg$FAILED; 1497 | if (peg$silentFails === 0) { peg$fail(peg$c54); } 1498 | } 1499 | if (s2 === peg$FAILED) { 1500 | if (input.charCodeAt(peg$currPos) === 92) { 1501 | s2 = peg$c58; 1502 | peg$currPos++; 1503 | } else { 1504 | s2 = peg$FAILED; 1505 | if (peg$silentFails === 0) { peg$fail(peg$c59); } 1506 | } 1507 | if (s2 === peg$FAILED) { 1508 | if (input.charCodeAt(peg$currPos) === 47) { 1509 | s2 = peg$c60; 1510 | peg$currPos++; 1511 | } else { 1512 | s2 = peg$FAILED; 1513 | if (peg$silentFails === 0) { peg$fail(peg$c61); } 1514 | } 1515 | if (s2 === peg$FAILED) { 1516 | if (input.charCodeAt(peg$currPos) === 35) { 1517 | s2 = peg$c14; 1518 | peg$currPos++; 1519 | } else { 1520 | s2 = peg$FAILED; 1521 | if (peg$silentFails === 0) { peg$fail(peg$c15); } 1522 | } 1523 | if (s2 === peg$FAILED) { 1524 | s2 = peg$currPos; 1525 | if (input.charCodeAt(peg$currPos) === 98) { 1526 | s3 = peg$c62; 1527 | peg$currPos++; 1528 | } else { 1529 | s3 = peg$FAILED; 1530 | if (peg$silentFails === 0) { peg$fail(peg$c63); } 1531 | } 1532 | if (s3 !== peg$FAILED) { 1533 | peg$savedPos = s2; 1534 | s3 = peg$c64(); 1535 | } 1536 | s2 = s3; 1537 | if (s2 === peg$FAILED) { 1538 | s2 = peg$currPos; 1539 | if (input.charCodeAt(peg$currPos) === 102) { 1540 | s3 = peg$c65; 1541 | peg$currPos++; 1542 | } else { 1543 | s3 = peg$FAILED; 1544 | if (peg$silentFails === 0) { peg$fail(peg$c66); } 1545 | } 1546 | if (s3 !== peg$FAILED) { 1547 | peg$savedPos = s2; 1548 | s3 = peg$c67(); 1549 | } 1550 | s2 = s3; 1551 | if (s2 === peg$FAILED) { 1552 | s2 = peg$currPos; 1553 | if (input.charCodeAt(peg$currPos) === 110) { 1554 | s3 = peg$c68; 1555 | peg$currPos++; 1556 | } else { 1557 | s3 = peg$FAILED; 1558 | if (peg$silentFails === 0) { peg$fail(peg$c69); } 1559 | } 1560 | if (s3 !== peg$FAILED) { 1561 | peg$savedPos = s2; 1562 | s3 = peg$c70(); 1563 | } 1564 | s2 = s3; 1565 | if (s2 === peg$FAILED) { 1566 | s2 = peg$currPos; 1567 | if (input.charCodeAt(peg$currPos) === 114) { 1568 | s3 = peg$c71; 1569 | peg$currPos++; 1570 | } else { 1571 | s3 = peg$FAILED; 1572 | if (peg$silentFails === 0) { peg$fail(peg$c72); } 1573 | } 1574 | if (s3 !== peg$FAILED) { 1575 | peg$savedPos = s2; 1576 | s3 = peg$c73(); 1577 | } 1578 | s2 = s3; 1579 | if (s2 === peg$FAILED) { 1580 | s2 = peg$currPos; 1581 | if (input.charCodeAt(peg$currPos) === 116) { 1582 | s3 = peg$c74; 1583 | peg$currPos++; 1584 | } else { 1585 | s3 = peg$FAILED; 1586 | if (peg$silentFails === 0) { peg$fail(peg$c75); } 1587 | } 1588 | if (s3 !== peg$FAILED) { 1589 | peg$savedPos = s2; 1590 | s3 = peg$c76(); 1591 | } 1592 | s2 = s3; 1593 | if (s2 === peg$FAILED) { 1594 | s2 = peg$currPos; 1595 | if (input.charCodeAt(peg$currPos) === 117) { 1596 | s3 = peg$c77; 1597 | peg$currPos++; 1598 | } else { 1599 | s3 = peg$FAILED; 1600 | if (peg$silentFails === 0) { peg$fail(peg$c78); } 1601 | } 1602 | if (s3 !== peg$FAILED) { 1603 | s4 = peg$currPos; 1604 | s5 = peg$currPos; 1605 | s6 = peg$parseHEXDIG(); 1606 | if (s6 !== peg$FAILED) { 1607 | s7 = peg$parseHEXDIG(); 1608 | if (s7 !== peg$FAILED) { 1609 | s8 = peg$parseHEXDIG(); 1610 | if (s8 !== peg$FAILED) { 1611 | s9 = peg$parseHEXDIG(); 1612 | if (s9 !== peg$FAILED) { 1613 | s6 = [s6, s7, s8, s9]; 1614 | s5 = s6; 1615 | } else { 1616 | peg$currPos = s5; 1617 | s5 = peg$FAILED; 1618 | } 1619 | } else { 1620 | peg$currPos = s5; 1621 | s5 = peg$FAILED; 1622 | } 1623 | } else { 1624 | peg$currPos = s5; 1625 | s5 = peg$FAILED; 1626 | } 1627 | } else { 1628 | peg$currPos = s5; 1629 | s5 = peg$FAILED; 1630 | } 1631 | if (s5 !== peg$FAILED) { 1632 | s4 = input.substring(s4, peg$currPos); 1633 | } else { 1634 | s4 = s5; 1635 | } 1636 | if (s4 !== peg$FAILED) { 1637 | peg$savedPos = s2; 1638 | s3 = peg$c79(s4); 1639 | s2 = s3; 1640 | } else { 1641 | peg$currPos = s2; 1642 | s2 = peg$FAILED; 1643 | } 1644 | } else { 1645 | peg$currPos = s2; 1646 | s2 = peg$FAILED; 1647 | } 1648 | } 1649 | } 1650 | } 1651 | } 1652 | } 1653 | } 1654 | } 1655 | } 1656 | } 1657 | } 1658 | if (s2 !== peg$FAILED) { 1659 | peg$savedPos = s0; 1660 | s1 = peg$c80(s2); 1661 | s0 = s1; 1662 | } else { 1663 | peg$currPos = s0; 1664 | s0 = peg$FAILED; 1665 | } 1666 | } else { 1667 | peg$currPos = s0; 1668 | s0 = peg$FAILED; 1669 | } 1670 | 1671 | return s0; 1672 | } 1673 | 1674 | function peg$parseescape() { 1675 | var s0; 1676 | 1677 | if (input.charCodeAt(peg$currPos) === 92) { 1678 | s0 = peg$c58; 1679 | peg$currPos++; 1680 | } else { 1681 | s0 = peg$FAILED; 1682 | if (peg$silentFails === 0) { peg$fail(peg$c59); } 1683 | } 1684 | 1685 | return s0; 1686 | } 1687 | 1688 | function peg$parseunescaped_simple() { 1689 | var s0; 1690 | 1691 | if (peg$c81.test(input.charAt(peg$currPos))) { 1692 | s0 = input.charAt(peg$currPos); 1693 | peg$currPos++; 1694 | } else { 1695 | s0 = peg$FAILED; 1696 | if (peg$silentFails === 0) { peg$fail(peg$c82); } 1697 | } 1698 | 1699 | return s0; 1700 | } 1701 | 1702 | function peg$parseunescaped_double_quote() { 1703 | var s0; 1704 | 1705 | if (peg$c83.test(input.charAt(peg$currPos))) { 1706 | s0 = input.charAt(peg$currPos); 1707 | peg$currPos++; 1708 | } else { 1709 | s0 = peg$FAILED; 1710 | if (peg$silentFails === 0) { peg$fail(peg$c84); } 1711 | } 1712 | 1713 | return s0; 1714 | } 1715 | 1716 | function peg$parseunescaped_single_quote() { 1717 | var s0; 1718 | 1719 | if (peg$c85.test(input.charAt(peg$currPos))) { 1720 | s0 = input.charAt(peg$currPos); 1721 | peg$currPos++; 1722 | } else { 1723 | s0 = peg$FAILED; 1724 | if (peg$silentFails === 0) { peg$fail(peg$c86); } 1725 | } 1726 | 1727 | return s0; 1728 | } 1729 | 1730 | function peg$parseassign() { 1731 | var s0, s1; 1732 | 1733 | s0 = peg$currPos; 1734 | s1 = peg$parsemember(); 1735 | if (s1 !== peg$FAILED) { 1736 | peg$savedPos = s0; 1737 | s1 = peg$c87(s1); 1738 | } 1739 | s0 = s1; 1740 | 1741 | return s0; 1742 | } 1743 | 1744 | function peg$parsetyped() { 1745 | var s0, s1, s2, s3; 1746 | 1747 | s0 = peg$currPos; 1748 | s1 = []; 1749 | if (peg$c88.test(input.charAt(peg$currPos))) { 1750 | s2 = input.charAt(peg$currPos); 1751 | peg$currPos++; 1752 | } else { 1753 | s2 = peg$FAILED; 1754 | if (peg$silentFails === 0) { peg$fail(peg$c89); } 1755 | } 1756 | if (s2 !== peg$FAILED) { 1757 | while (s2 !== peg$FAILED) { 1758 | s1.push(s2); 1759 | if (peg$c88.test(input.charAt(peg$currPos))) { 1760 | s2 = input.charAt(peg$currPos); 1761 | peg$currPos++; 1762 | } else { 1763 | s2 = peg$FAILED; 1764 | if (peg$silentFails === 0) { peg$fail(peg$c89); } 1765 | } 1766 | } 1767 | } else { 1768 | s1 = peg$FAILED; 1769 | } 1770 | if (s1 !== peg$FAILED) { 1771 | s2 = peg$parsetyped_start(); 1772 | if (s2 !== peg$FAILED) { 1773 | s3 = peg$parseexpr(); 1774 | if (s3 !== peg$FAILED) { 1775 | peg$savedPos = s0; 1776 | s1 = peg$c90(s1, s3); 1777 | s0 = s1; 1778 | } else { 1779 | peg$currPos = s0; 1780 | s0 = peg$FAILED; 1781 | } 1782 | } else { 1783 | peg$currPos = s0; 1784 | s0 = peg$FAILED; 1785 | } 1786 | } else { 1787 | peg$currPos = s0; 1788 | s0 = peg$FAILED; 1789 | } 1790 | 1791 | return s0; 1792 | } 1793 | 1794 | function peg$parsecomment() { 1795 | var s0, s1, s2, s3; 1796 | 1797 | s0 = peg$currPos; 1798 | s1 = peg$parsecomment_start(); 1799 | if (s1 !== peg$FAILED) { 1800 | s2 = []; 1801 | if (peg$c91.test(input.charAt(peg$currPos))) { 1802 | s3 = input.charAt(peg$currPos); 1803 | peg$currPos++; 1804 | } else { 1805 | s3 = peg$FAILED; 1806 | if (peg$silentFails === 0) { peg$fail(peg$c92); } 1807 | } 1808 | while (s3 !== peg$FAILED) { 1809 | s2.push(s3); 1810 | if (peg$c91.test(input.charAt(peg$currPos))) { 1811 | s3 = input.charAt(peg$currPos); 1812 | peg$currPos++; 1813 | } else { 1814 | s3 = peg$FAILED; 1815 | if (peg$silentFails === 0) { peg$fail(peg$c92); } 1816 | } 1817 | } 1818 | if (s2 !== peg$FAILED) { 1819 | s1 = [s1, s2]; 1820 | s0 = s1; 1821 | } else { 1822 | peg$currPos = s0; 1823 | s0 = peg$FAILED; 1824 | } 1825 | } else { 1826 | peg$currPos = s0; 1827 | s0 = peg$FAILED; 1828 | } 1829 | 1830 | return s0; 1831 | } 1832 | 1833 | function peg$parseDIGIT() { 1834 | var s0; 1835 | 1836 | if (peg$c93.test(input.charAt(peg$currPos))) { 1837 | s0 = input.charAt(peg$currPos); 1838 | peg$currPos++; 1839 | } else { 1840 | s0 = peg$FAILED; 1841 | if (peg$silentFails === 0) { peg$fail(peg$c94); } 1842 | } 1843 | 1844 | return s0; 1845 | } 1846 | 1847 | function peg$parseHEXDIG() { 1848 | var s0; 1849 | 1850 | if (peg$c95.test(input.charAt(peg$currPos))) { 1851 | s0 = input.charAt(peg$currPos); 1852 | peg$currPos++; 1853 | } else { 1854 | s0 = peg$FAILED; 1855 | if (peg$silentFails === 0) { peg$fail(peg$c96); } 1856 | } 1857 | 1858 | return s0; 1859 | } 1860 | 1861 | peg$result = peg$startRuleFunction(); 1862 | 1863 | if (peg$result !== peg$FAILED && peg$currPos === input.length) { 1864 | return peg$result; 1865 | } else { 1866 | if (peg$result !== peg$FAILED && peg$currPos < input.length) { 1867 | peg$fail(peg$endExpectation()); 1868 | } 1869 | 1870 | throw peg$buildStructuredError( 1871 | peg$maxFailExpected, 1872 | peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, 1873 | peg$maxFailPos < input.length 1874 | ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) 1875 | : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) 1876 | ); 1877 | } 1878 | } 1879 | 1880 | module.exports = { 1881 | SyntaxError: peg$SyntaxError, 1882 | parse: peg$parse 1883 | }; 1884 | 1885 | },{}],2:[function(require,module,exports){ 1886 | 'use strict'; 1887 | 1888 | var parser = require('./dist/parser'); 1889 | var assign = require('object-assign'); 1890 | var toString = Object.prototype.toString; 1891 | var uson; 1892 | 1893 | var usonTypes = { 1894 | // collection 1895 | 'obj': function(val) { return JSON.parse('{' + val + '}'); }, 1896 | 'arr': function(val) { return JSON.parse('[' + val + ']'); }, 1897 | 1898 | // scalars 1899 | 'str': function(val) { return val.toString(); }, 1900 | 'int': function(val) { return parseInt(val); }, 1901 | 'float': function(val) { return parseFloat(val); }, 1902 | 'null': function() { return null; }, 1903 | 'date': function(val) { return new Date(val); }, 1904 | 'bool': function(val) { return val === 'true' ? true : false; } 1905 | }; 1906 | 1907 | function Interpreter(options) { 1908 | options = options || {}; 1909 | this.mode = options.mode || false; 1910 | } 1911 | 1912 | Interpreter.prototype.process = function(arr) { 1913 | switch(this.mode) { 1914 | case 'object': 1915 | return this.toObject(arr); 1916 | case 'json': 1917 | return arr[0]; 1918 | // default `array` mode 1919 | default: 1920 | return arr; 1921 | } 1922 | }; 1923 | 1924 | Interpreter.prototype.toObject = function(values) { 1925 | var arrcount = 0; 1926 | var obj = {}; 1927 | values.forEach(function(item) { 1928 | var type = toString.call(item); 1929 | if(type === '[object Array]') { 1930 | obj[arrcount] = item; 1931 | arrcount = arrcount + 1; 1932 | } else if(type === '[object Object]') { 1933 | obj = assign(obj, item); 1934 | } else { 1935 | obj[arrcount] = item; 1936 | arrcount = arrcount + 1; 1937 | } 1938 | }); 1939 | return obj; 1940 | }; 1941 | 1942 | uson = { 1943 | 'parse': function(str, mode, types) { 1944 | var arr; 1945 | var interpreter; 1946 | 1947 | // convert to string 1948 | if(toString.call(str) === '[object Object]' && str.toString) { 1949 | str = str.toString(); 1950 | } 1951 | // assign types 1952 | types = assign(usonTypes, types || {}); 1953 | // parse 1954 | arr = parser.parse(str, { 'type': types }); 1955 | // create interpreter 1956 | interpreter = new Interpreter({ 'mode': mode || false }); 1957 | // process 1958 | return interpreter.process(arr); 1959 | }, 1960 | 'stringify': function() { return null; }, 1961 | 'parser': parser 1962 | }; 1963 | 1964 | module.exports = uson; 1965 | 1966 | },{"./dist/parser":1,"object-assign":3}],3:[function(require,module,exports){ 1967 | /* 1968 | object-assign 1969 | (c) Sindre Sorhus 1970 | @license MIT 1971 | */ 1972 | 1973 | 'use strict'; 1974 | /* eslint-disable no-unused-vars */ 1975 | var getOwnPropertySymbols = Object.getOwnPropertySymbols; 1976 | var hasOwnProperty = Object.prototype.hasOwnProperty; 1977 | var propIsEnumerable = Object.prototype.propertyIsEnumerable; 1978 | 1979 | function toObject(val) { 1980 | if (val === null || val === undefined) { 1981 | throw new TypeError('Object.assign cannot be called with null or undefined'); 1982 | } 1983 | 1984 | return Object(val); 1985 | } 1986 | 1987 | function shouldUseNative() { 1988 | try { 1989 | if (!Object.assign) { 1990 | return false; 1991 | } 1992 | 1993 | // Detect buggy property enumeration order in older V8 versions. 1994 | 1995 | // https://bugs.chromium.org/p/v8/issues/detail?id=4118 1996 | var test1 = new String('abc'); // eslint-disable-line no-new-wrappers 1997 | test1[5] = 'de'; 1998 | if (Object.getOwnPropertyNames(test1)[0] === '5') { 1999 | return false; 2000 | } 2001 | 2002 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056 2003 | var test2 = {}; 2004 | for (var i = 0; i < 10; i++) { 2005 | test2['_' + String.fromCharCode(i)] = i; 2006 | } 2007 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) { 2008 | return test2[n]; 2009 | }); 2010 | if (order2.join('') !== '0123456789') { 2011 | return false; 2012 | } 2013 | 2014 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056 2015 | var test3 = {}; 2016 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { 2017 | test3[letter] = letter; 2018 | }); 2019 | if (Object.keys(Object.assign({}, test3)).join('') !== 2020 | 'abcdefghijklmnopqrst') { 2021 | return false; 2022 | } 2023 | 2024 | return true; 2025 | } catch (err) { 2026 | // We don't expect any of the above to throw, but better to be safe. 2027 | return false; 2028 | } 2029 | } 2030 | 2031 | module.exports = shouldUseNative() ? Object.assign : function (target, source) { 2032 | var from; 2033 | var to = toObject(target); 2034 | var symbols; 2035 | 2036 | for (var s = 1; s < arguments.length; s++) { 2037 | from = Object(arguments[s]); 2038 | 2039 | for (var key in from) { 2040 | if (hasOwnProperty.call(from, key)) { 2041 | to[key] = from[key]; 2042 | } 2043 | } 2044 | 2045 | if (getOwnPropertySymbols) { 2046 | symbols = getOwnPropertySymbols(from); 2047 | for (var i = 0; i < symbols.length; i++) { 2048 | if (propIsEnumerable.call(from, symbols[i])) { 2049 | to[symbols[i]] = from[symbols[i]]; 2050 | } 2051 | } 2052 | } 2053 | } 2054 | 2055 | return to; 2056 | }; 2057 | 2058 | },{}]},{},[2])(2) 2059 | }); 2060 | -------------------------------------------------------------------------------- /examples/usonrc.js: -------------------------------------------------------------------------------- 1 | var chance = require('chance')(); 2 | 3 | module.exports = { 4 | types: { 5 | // `g!` , for example: `g!name` 6 | g: function(val) { 7 | var args = []; 8 | var cmd = null; 9 | if(typeof val == "object") { 10 | cmd = Object.keys(val)[0]; 11 | args = val[cmd]; 12 | } else { 13 | cmd = val; 14 | } 15 | return chance[cmd] ? chance[cmd](args) : null; 16 | }, 17 | // `js!` , for example: `js!"4+5"` 18 | js: function(js) { 19 | return eval(js); 20 | }, 21 | // `hello!` 22 | 'hello': function(val) { 23 | return 'Hello '+ val; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var parser = require('./dist/parser'); 4 | var assign = require('object-assign'); 5 | var toString = Object.prototype.toString; 6 | var uson; 7 | 8 | var usonTypes = { 9 | // collection 10 | 'obj': function(val) { return JSON.parse('{' + val + '}'); }, 11 | 'arr': function(val) { return JSON.parse('[' + val + ']'); }, 12 | 13 | // scalars 14 | 'str': function(val) { return val.toString(); }, 15 | 'int': function(val) { return parseInt(val); }, 16 | 'float': function(val) { return parseFloat(val); }, 17 | 'null': function() { return null; }, 18 | 'date': function(val) { return new Date(val); }, 19 | 'bool': function(val) { return val === 'true' ? true : false; } 20 | }; 21 | 22 | function Interpreter(options) { 23 | options = options || {}; 24 | this.mode = options.mode || false; 25 | } 26 | 27 | Interpreter.prototype.process = function(arr) { 28 | switch(this.mode) { 29 | case 'object': 30 | return this.toObject(arr); 31 | case 'json': 32 | return arr[0]; 33 | // default `array` mode 34 | default: 35 | return arr; 36 | } 37 | }; 38 | 39 | Interpreter.prototype.toObject = function(values) { 40 | var arrcount = 0; 41 | var obj = {}; 42 | values.forEach(function(item) { 43 | var type = toString.call(item); 44 | if(type === '[object Array]') { 45 | obj[arrcount] = item; 46 | arrcount = arrcount + 1; 47 | } else if(type === '[object Object]') { 48 | obj = assign(obj, item); 49 | } else { 50 | obj[arrcount] = item; 51 | arrcount = arrcount + 1; 52 | } 53 | }); 54 | return obj; 55 | }; 56 | 57 | uson = { 58 | 'parse': function(str, mode, types) { 59 | var arr; 60 | var interpreter; 61 | 62 | // convert to string 63 | if(toString.call(str) === '[object Object]' && str.toString) { 64 | str = str.toString(); 65 | } 66 | // assign types 67 | types = assign(usonTypes, types || {}); 68 | // parse 69 | arr = parser.parse(str, { 'type': types }); 70 | // create interpreter 71 | interpreter = new Interpreter({ 'mode': mode || false }); 72 | // process 73 | return interpreter.process(arr); 74 | }, 75 | 'stringify': function() { return null; }, 76 | 'parser': parser 77 | }; 78 | 79 | module.exports = uson; 80 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uson", 3 | "version": "0.3.5", 4 | "description": "μson (uson) is a shorthand for JSON", 5 | "main": "index.js", 6 | "bin": { 7 | "uson": "bin/cli.js" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/burningtree/uson.git" 15 | }, 16 | "keywords": [ 17 | "json", 18 | "serialization", 19 | "yaml" 20 | ], 21 | "publishConfig": { 22 | "registry": "https://registry.npmjs.org" 23 | }, 24 | "author": "Jan Stránský ", 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/burningtree/uson/issues" 28 | }, 29 | "homepage": "https://github.com/burningtree/uson", 30 | "dependencies": { 31 | "commander": "^3.0.0", 32 | "object-assign": "^4.1.1" 33 | }, 34 | "devDependencies": { 35 | "benchmark": "^2.1.4", 36 | "browserify": "^16.5.0", 37 | "eslint": "^6.2.2", 38 | "js-yaml": "^3.13.1", 39 | "mocha": "^6.2.0", 40 | "msgpack": "^1.0.2", 41 | "pegjs": "^0.10.0", 42 | "qs": "^6.8.0", 43 | "uglify-js": "^3.6.0" 44 | }, 45 | "spm": { 46 | "main": "dist/uson.min.js" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/uson.pegjs: -------------------------------------------------------------------------------- 1 | /* 2 | * μson Grammar 3 | * ============ 4 | * 5 | * Version: draft-0 6 | * Date: 2015-04-09 7 | * 8 | * Based on the JSON grammar from RFC 7159 [1]. 9 | * 10 | * The original JSON PEG.js grammar was written by 11 | * David Majda (@dmajda) 12 | * 13 | * (c) 2015 Jan Stránský 14 | * μson may be freely distributed or modified under the MIT license. 15 | * 16 | * [1] http://tools.ietf.org/html/rfc7159 17 | * 18 | */ 19 | 20 | /* ----- μson Grammar ----- */ 21 | 22 | uson_text 23 | = head:expr? ws tail:expr* 24 | { 25 | if(head==null && text()!=="null"){ return [] }; 26 | return [head].concat(tail); 27 | } 28 | 29 | expr = ws v:value ws {return v} 30 | 31 | begin_array = ws "[" ws 32 | begin_object = ws "{" ws 33 | end_array = ws "]" ws 34 | end_object = ws "}" ws 35 | name_separator = ws ":" ws 36 | value_separator = ws [ ,]* ws 37 | comment_start = "#" 38 | typed_start = ws "!" ws 39 | ws_char = [ \t\n\r] 40 | 41 | ws "whitespace" = ws_char* comment? 42 | 43 | /* ----- Values ----- */ 44 | 45 | value 46 | = typed 47 | / false 48 | / null 49 | / true 50 | / assign 51 | / object 52 | / array 53 | / string 54 | / number 55 | 56 | false = "false" { return false; } 57 | null = "null" { return null; } 58 | true = "true" { return true; } 59 | 60 | /* ----- Objects ----- */ 61 | 62 | object 63 | = begin_object 64 | members:( 65 | first:member 66 | rest:(value_separator m:member { return m; })* 67 | { 68 | var result = {}, i; 69 | result[first.name] = first.value; 70 | for (i = 0; i < rest.length; i++) { 71 | result[rest[i].name] = rest[i].value; 72 | } 73 | return result; 74 | } 75 | )? 76 | end_object 77 | { return members !== null ? members: {}; } 78 | 79 | member 80 | = name:string name_separator value:expr { 81 | return { name: name, value: value }; 82 | } 83 | 84 | /* ----- Arrays ----- */ 85 | 86 | array 87 | = begin_array 88 | values:( 89 | first:expr 90 | rest:(value_separator? v:expr { return v; })* 91 | { return [first].concat(rest); } 92 | )? 93 | end_array 94 | { return values !== null ? values : []; } 95 | 96 | /* ----- Numbers ----- */ 97 | 98 | number "number" 99 | = minus? int frac? exp? { return parseFloat(text()); } 100 | 101 | decimal_point = "." 102 | digit1_9 = [1-9] 103 | e = [eE] 104 | exp = e (minus / plus)? DIGIT+ 105 | frac = decimal_point DIGIT+ 106 | int = zero / (digit1_9 DIGIT*) 107 | minus = "-" 108 | plus = "+" 109 | zero = "0" 110 | 111 | /* ----- Strings ----- */ 112 | 113 | string "string" 114 | = double_quoted_string 115 | / single_quoted_string 116 | / unquoted_string 117 | 118 | unquoted_string 119 | = v:simple_char+ 120 | { 121 | var res = v.join(""); 122 | return (res.match(/^[0-9\.]+$/) ? Number(res) : res); 123 | } 124 | 125 | single_quoted_string 126 | = "'" v:char_single_quoted* "'" { return v.join(""); } 127 | 128 | double_quoted_string 129 | = '"' v:char_double_quoted* '"' { return v.join(""); } 130 | 131 | simple_char = unescaped_simple / escaped_char 132 | char_single_quoted = unescaped_single_quote / escaped_char 133 | char_double_quoted = unescaped_double_quote / escaped_char 134 | 135 | escaped_char 136 | = escape 137 | sequence:( 138 | '"' 139 | / "'" 140 | / "\\" 141 | / "/" 142 | / "#" 143 | / "b" { return "\b"; } 144 | / "f" { return "\f"; } 145 | / "n" { return "\n"; } 146 | / "r" { return "\r"; } 147 | / "t" { return "\t"; } 148 | / "u" digits:$(HEXDIG HEXDIG HEXDIG HEXDIG) { 149 | return String.fromCharCode(parseInt(digits, 16)); 150 | } 151 | ) 152 | { return sequence; } 153 | 154 | escape = "\\" 155 | unescaped_simple 156 | = [\x21\x24-\x2B\x2D-\x39\x3B-\x5A\x5E-\x7A\x7C\x7E-\u10FFFF] 157 | /* forbidden chars: !"#,:[\]{} */ 158 | 159 | unescaped_double_quote = [\x20-\x21\x23-\x5B\x5D-\u10FFFF] 160 | unescaped_single_quote = [\x20-\x26\x28-\x5B\x5D-\u10FFFF] 161 | 162 | /* ----- Assignations ----- */ 163 | 164 | assign 165 | = m:member {var obj={}; obj[m.name] = m.value; return obj} 166 | 167 | /* ----- Typed literals ----- */ 168 | 169 | typed 170 | = name:[a-zA-Z0-9_\-]+ typed_start value:expr 171 | { 172 | var jname = name.join(''); 173 | if(options.type && options.type[jname]) { 174 | return options.type[jname](value, jname); 175 | } 176 | return value; 177 | } 178 | 179 | /* ----- Comments ----- */ 180 | 181 | comment = comment_start [^\n\r\u2028\u2029]* 182 | 183 | /* ----- Core ABNF Rules ----- */ 184 | 185 | /* See RFC 4234, Appendix B (http://tools.ietf.org/html/rfc4627). */ 186 | DIGIT = [0-9] 187 | HEXDIG = [0-9a-f]i 188 | 189 | -------------------------------------------------------------------------------- /test/cli.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var assert = require('assert'); 5 | var path = require('path'); 6 | 7 | describe('test/cli', function() { 8 | 9 | var nodeBin = 'node ' + path.resolve(__dirname, '..', 'bin/cli.js'); 10 | function bin(query, cb) { 11 | require('child_process').exec(nodeBin + ' ' + query, cb); 12 | } 13 | 14 | it('should work with string', function(done) { 15 | bin('hello', function(err, data) { 16 | assert.deepEqual(data, '[\"hello\"]\n'); 17 | assert.equal(err, null); 18 | done(); 19 | }); 20 | }); 21 | 22 | it('should work with quoted', function(done) { 23 | bin('\\\'blue velvet\\\'', function(err, data) { 24 | assert.deepEqual(data, '["blue velvet"]\n'); 25 | assert.equal(err, null); 26 | done(); 27 | }); 28 | }); 29 | 30 | it('should work with array', function(done) { 31 | bin('hello dolly', function(err, data) { 32 | assert.deepEqual(data, '["hello","dolly"]\n'); 33 | assert.equal(err, null); 34 | done(); 35 | }); 36 | }); 37 | 38 | it('should work in object mode', function(done) { 39 | bin('-o a:1', function(err, data) { 40 | assert.deepEqual(data, '{"a":1}\n'); 41 | assert.equal(err, null); 42 | done(); 43 | }); 44 | }); 45 | 46 | it('should work in json mode', function(done) { 47 | bin('-j a:1 xx', function(err, data) { 48 | assert.deepEqual(data, '{"a":1}\n'); 49 | assert.equal(err, null); 50 | done(); 51 | }); 52 | }); 53 | 54 | it('should work and output to yaml', function(done) { 55 | bin('-y a:1 xx', function(err, data) { 56 | assert.deepEqual(data, '- a: 1\n- xx\n'); 57 | assert.equal(err, null); 58 | done(); 59 | }); 60 | }); 61 | 62 | it('should work and output to hex encoding', function(done) { 63 | bin('--hex a:1 xx', function(err, data) { 64 | assert.deepEqual(data, '5b7b2261223a317d2c227878225d0a\n'); 65 | assert.equal(err, null); 66 | done(); 67 | }); 68 | }); 69 | 70 | it('should work and output to base64 encoding', function(done) { 71 | bin('--base64 a:1 xx', function(err, data) { 72 | assert.deepEqual(data, 'W3siYSI6MX0sInh4Il0K\n'); 73 | assert.equal(err, null); 74 | done(); 75 | }); 76 | }); 77 | 78 | it('should work with input file', function(done) { 79 | var dir = path.resolve(__dirname, '../'); 80 | var file = 'package.json'; 81 | bin('-j -i '+file, function(err, data) { 82 | var good = JSON.parse(fs.readFileSync(path.join(dir, file))); 83 | assert.deepEqual(JSON.parse(data), good); 84 | assert.equal(err, null); 85 | done(); 86 | }); 87 | }); 88 | 89 | it('should work with custom usorc.js file', function(done) { 90 | var file = path.resolve(__dirname, 'fixtures', 'usonrc.js'); 91 | bin('-u '+file+' \'js!"29.66+(37.02/3)"\'', function(err, data) { 92 | assert.deepEqual(JSON.parse(data), [42]); 93 | assert.equal(err, null); 94 | done(); 95 | }); 96 | }); 97 | }); 98 | 99 | -------------------------------------------------------------------------------- /test/compliance.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | var assert = require('assert'); 6 | var USON = require('../'); 7 | 8 | // Compliance tests that aren't supported yet. 9 | var notImplementedYet = []; 10 | 11 | function endsWith(str, suffix) { 12 | return str.indexOf(suffix, str.length - suffix.length) !== -1; 13 | } 14 | 15 | var listing = fs.readdirSync('test/compliance'); 16 | for (var i = 0; i < listing.length; i++) { 17 | var filename = 'test/compliance/' + listing[i]; 18 | if (fs.statSync(filename).isFile() && endsWith(filename, '.json') && 19 | notImplementedYet.indexOf(path.basename(filename)) === -1) { 20 | addTestSuitesFromFile(filename); 21 | } 22 | } 23 | 24 | function addTestSuitesFromFile(filename) { 25 | describe(filename, function() { 26 | var spec = JSON.parse(fs.readFileSync(filename, 'utf-8')); 27 | var modes = [ 'array', 'object', 'json' ]; 28 | var errorMsg; 29 | for (var i = 0; i < spec.length; i++) { 30 | var msg = "suite " + i + " for filename " + filename + " : " + spec[i].name; 31 | describe(msg, function() { 32 | var given = spec[i].given; 33 | var cases = spec[i].cases; 34 | for (var j = 0; j < cases.length; j++) { 35 | var testcase = cases[j]; 36 | for (var k = 0; k < modes.length; k++) { 37 | var mode = modes[k]; 38 | if (testcase.error !== undefined) { 39 | // For now just verify that an error is thrown 40 | // for error tests. 41 | (function(mode, testcase, given) { 42 | it('should throw error for test ' + j, function() { 43 | assert.throws( 44 | function() { 45 | USON.parse(testcase.expression,mode); 46 | }, Error, testcase.expression); 47 | }); 48 | })(mode, testcase, given); 49 | } else { 50 | if(testcase.result[mode]){ 51 | (function(mode, testcase, given, sp) { 52 | var expr = testcase.expression; 53 | if(expr.length > 20){ 54 | expr = expr.substr(0, 20) + ' .. (truncated)'; 55 | } 56 | expr = expr.match('\n') ? expr.split("\n")[0] + ' .. (multiline)' : expr; 57 | it('should pass test ' + j + " expression: " + expr + ' (m:'+mode+')', function() { 58 | assert.deepEqual(USON.parse(testcase.expression,mode), 59 | testcase.result[mode]); 60 | }); 61 | })(mode, testcase, given, spec[i]); 62 | } 63 | } 64 | } 65 | } 66 | }); 67 | } 68 | }); 69 | } 70 | -------------------------------------------------------------------------------- /test/compliance/basic.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name": "empty input", 3 | "cases": [ 4 | { 5 | "expression": "", 6 | "result": { 7 | "array": [], 8 | "object": {} 9 | } 10 | }, 11 | { 12 | "expression": " ", 13 | "result": { 14 | "array": [], 15 | "object": {} 16 | } 17 | }, 18 | { 19 | "expression": "\n ", 20 | "result": { 21 | "array": [], 22 | "object": {} 23 | } 24 | } 25 | ] 26 | },{ 27 | "name": "simple", 28 | "cases": [ 29 | { 30 | "expression": "a b c", 31 | "result": { 32 | "array": [ "a", "b", "c" ], 33 | "object": { "0": "a", "1": "b", "2": "c" } 34 | } 35 | } 36 | ] 37 | },{ 38 | "name": "nested arrays", 39 | "cases": [ 40 | { 41 | "expression": "[a]", 42 | "result": { 43 | "array": [[ "a" ]], 44 | "object": { "0": ["a"] } 45 | } 46 | }, 47 | { 48 | "expression": "[a b c]", 49 | "result": { 50 | "array": [[ "a", "b", "c" ]], 51 | "object": { "0": ["a", "b", "c"] } 52 | } 53 | }, 54 | { 55 | "expression": "[a [[b]] c]", 56 | "result": { 57 | "array": [[ "a",[[ "b" ]], "c" ]], 58 | "object": { "0": ["a", [["b"]], "c"] } 59 | } 60 | } 61 | ] 62 | },{ 63 | "name": "simple objects", 64 | "cases": [ 65 | { 66 | "expression": "a:1 b:2 c:3", 67 | "result": { 68 | "array": [ {"a":1}, {"b":2}, {"c":3} ], 69 | "object": { "a": 1, "b": 2, "c": 3 } 70 | } 71 | }, 72 | { 73 | "expression": "[a:1 b:2 c:3]", 74 | "result": { 75 | "array": [[ {"a":1}, {"b":2}, {"c":3} ]], 76 | "object": { "0": [ {"a":1}, {"b":2}, {"c":3} ] } 77 | } 78 | } 79 | ] 80 | },{ 81 | "name": "nested objects", 82 | "cases": [ 83 | { 84 | "expression": "a:b:c:d:1", 85 | "result": { 86 | "array": [{"a":{"b":{"c":{"d":1}}}}], 87 | "object": {"a":{"b":{"c":{"d":1}}}} 88 | } 89 | }, 90 | { 91 | "expression": "a:b:{c:d:1}", 92 | "result": { 93 | "array": [{"a":{"b":{"c":{"d":1}}}}], 94 | "object": {"a":{"b":{"c":{"d":1}}}} 95 | } 96 | }, 97 | { 98 | "expression": "a:[b:{c:d:1}]", 99 | "result": { 100 | "array": [{"a":[{"b":{"c":{"d":1}}}]}], 101 | "object": {"a":[{"b":{"c":{"d":1}}}]} 102 | } 103 | } 104 | ] 105 | },{ 106 | "name": "type casting", 107 | "cases": [ 108 | { 109 | "expression": "str!42", 110 | "result": { 111 | "array": [ "42" ], 112 | "object": { "0": "42" } 113 | } 114 | }, 115 | { 116 | "expression": "int!str!42", 117 | "result": { 118 | "array": [ 42 ], 119 | "object": { "0": 42 } 120 | } 121 | }, 122 | { 123 | "expression": "str!int!str!42", 124 | "result": { 125 | "array": [ "42" ], 126 | "object": { "0": "42" } 127 | } 128 | }, 129 | { 130 | "expression": "x:{test:str!42 multi:bool!str!true}", 131 | "result": { 132 | "array": [ { "x": { "test": "42", "multi": true }} ], 133 | "object": { "x": { "test": "42", "multi": true }} 134 | } 135 | }, 136 | { 137 | "expression": "str![1 2 3]", 138 | "result": { 139 | "array": [ "1,2,3" ], 140 | "object": { "0": "1,2,3" } 141 | } 142 | }, 143 | { 144 | "expression": "nonexists!42", 145 | "result": { 146 | "array": [ "42" ], 147 | "object": { "0": "42" } 148 | } 149 | }, 150 | { 151 | "expression": "A_b3-!42", 152 | "result": { 153 | "array": [ "42" ], 154 | "object": { "0": "42" } 155 | } 156 | } 157 | ] 158 | },{ 159 | "name": "more advanced examples", 160 | "cases": [ 161 | { 162 | "expression": "number:12.05 text:Banana quotedText:\"John Devilseed\" empty:null good:true", 163 | "result": { 164 | "array": [{"number":12.05},{"text":"Banana"},{"quotedText":"John Devilseed"},{"empty":null},{"good":true}], 165 | "object": {"number":12.05,"text":"Banana","quotedText":"John Devilseed","empty":null,"good":true} 166 | } 167 | } 168 | ] 169 | }] 170 | -------------------------------------------------------------------------------- /test/compliance/types.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "name": "number", 3 | "cases": [ 4 | { 5 | "expression": "1", 6 | "result": { 7 | "array": [ 1 ] , 8 | "object": { "0": 1 }, 9 | "json": 1 10 | } 11 | }, 12 | { 13 | "expression": "42.42", 14 | "result": { 15 | "array": [ 42.42 ] , 16 | "object": { "0": 42.42 }, 17 | "json": 42.42 18 | } 19 | }, 20 | { 21 | "expression": "-50.43", 22 | "result": { 23 | "array": [ -50.43 ] , 24 | "object": { "0": -50.43 }, 25 | "json": -50.43 26 | } 27 | }, 28 | { 29 | "expression": "1000000.0001", 30 | "result": { 31 | "array": [ 1000000.0001 ], 32 | "object": { "0": 1000000.0001 }, 33 | "json": 1000000.0001 34 | } 35 | }, 36 | { 37 | "expression": "10e5", 38 | "result": { 39 | "array": [ 10e5 ], 40 | "object": { "0": 10e5 }, 41 | "json": 10e5 42 | } 43 | }, 44 | { 45 | "expression": "float!\"42.42\"", 46 | "result": { 47 | "array": [ 42.42 ] , 48 | "object": { "0": 42.42 }, 49 | "json": 42.42 50 | } 51 | } 52 | ] 53 | },{ 54 | "name": "string", 55 | "cases": [ 56 | { 57 | "expression": "abc", 58 | "result": { 59 | "array": [ "abc" ] , 60 | "object": { "0": "abc" }, 61 | "json": "abc" 62 | } 63 | }, 64 | { 65 | "expression": "1ab", 66 | "result": { 67 | "array": [ "1ab" ] , 68 | "object": { "0": "1ab" }, 69 | "json": "1ab" 70 | } 71 | }, 72 | { 73 | "expression": "abc def", 74 | "result": { 75 | "array": [ "abc", "def" ] , 76 | "object": { "0": "abc", "1": "def" }, 77 | "json": "abc" 78 | } 79 | }, 80 | { 81 | "expression": "\"abc\"", 82 | "result": { 83 | "array": [ "abc" ] , 84 | "object": { "0": "abc" } 85 | } 86 | }, 87 | { 88 | "expression": "\"abc def\"", 89 | "result": { 90 | "array": [ "abc def" ] , 91 | "object": { "0": "abc def" } 92 | } 93 | }, 94 | { 95 | "expression": "\"abc \\\"ok def\"", 96 | "result": { 97 | "array": [ "abc \"ok def" ] , 98 | "object": { "0": "abc \"ok def" } 99 | } 100 | }, 101 | { 102 | "expression": "'abc'", 103 | "result": { 104 | "array": [ "abc" ] , 105 | "object": { "0": "abc" } 106 | } 107 | }, 108 | { 109 | "expression": "'abc def'", 110 | "result": { 111 | "array": [ "abc def" ] , 112 | "object": { "0": "abc def" } 113 | } 114 | }, 115 | { 116 | "expression": "'abc \\'42 def'", 117 | "result": { 118 | "array": [ "abc '42 def" ] , 119 | "object": { "0": "abc '42 def" } 120 | } 121 | }, 122 | { 123 | "expression": "str!\"abc def\"", 124 | "result": { 125 | "array": [ "abc def" ] , 126 | "object": { "0": "abc def" }, 127 | "json": "abc def" 128 | } 129 | } 130 | ] 131 | },{ 132 | "name": "null", 133 | "cases": [ 134 | { 135 | "expression": "null", 136 | "result": { 137 | "array": [ null ] , 138 | "object": { "0": null }, 139 | "json": null 140 | } 141 | }, 142 | { 143 | "expression": "x:null!xx", 144 | "result": { 145 | "array": [ { "x": null } ] , 146 | "object": { "x": null }, 147 | "json": { "x": null } 148 | } 149 | } 150 | ] 151 | },{ 152 | "name": "true", 153 | "cases": [ 154 | { 155 | "expression": "true", 156 | "result": { 157 | "array": [ true ] , 158 | "object": { "0": true }, 159 | "json": true 160 | } 161 | }, 162 | { 163 | "expression": "bool!\"true\"", 164 | "result": { 165 | "array": [ true ] , 166 | "object": { "0": true }, 167 | "json": true 168 | } 169 | } 170 | ] 171 | },{ 172 | "name": "false", 173 | "cases": [ 174 | { 175 | "expression": "false", 176 | "result": { 177 | "array": [ false ] , 178 | "object": { "0": false }, 179 | "json": false 180 | } 181 | }, 182 | { 183 | "expression": "bool!\"false\"", 184 | "result": { 185 | "array": [ false ] , 186 | "object": { "0": false }, 187 | "json": false 188 | } 189 | } 190 | ] 191 | },{ 192 | "name": "array", 193 | "cases": [ 194 | { 195 | "expression": "[a]", 196 | "result": { 197 | "array": [["a"]], 198 | "object": { "0": ["a"] }, 199 | "json": ["a"] 200 | } 201 | }, 202 | { 203 | "expression": "[1 2 3]", 204 | "result": { 205 | "array": [[ 1, 2, 3 ]], 206 | "object": { "0": [ 1, 2, 3 ] } 207 | } 208 | }, 209 | { 210 | "expression": "[1, 2, 3]", 211 | "result": { 212 | "array": [[ 1, 2, 3 ]], 213 | "object": { "0": [ 1, 2, 3 ] } 214 | } 215 | }, 216 | { 217 | "expression": "[1 2,3 ]", 218 | "result": { 219 | "array": [[ 1, 2, 3 ]], 220 | "object": { "0": [ 1, 2, 3 ] } 221 | } 222 | }, 223 | { 224 | "expression": "arr!\"1,2,3\"", 225 | "result": { 226 | "array": [[ 1, 2, 3 ]], 227 | "object": { "0": [ 1, 2, 3 ] } 228 | } 229 | } 230 | ] 231 | },{ 232 | "name": "object", 233 | "cases": [ 234 | { 235 | "expression": "{a:1}", 236 | "result": { 237 | "array": [ { "a":1 } ], 238 | "object": { "a":1 } 239 | } 240 | }, 241 | { 242 | "expression": "{a:1 b:two c:3}", 243 | "result": { 244 | "array": [ { "a":1, "b":"two", "c":3 } ], 245 | "object": { "a":1, "b":"two", "c":3 } 246 | } 247 | }, 248 | { 249 | "expression": "{a:1,b:two,c:3}", 250 | "result": { 251 | "array": [ { "a":1, "b":"two", "c":3 } ], 252 | "object": { "a":1, "b":"two", "c":3 } 253 | } 254 | }, 255 | { 256 | "expression": "{a:1,b:two c:3,d:4}", 257 | "result": { 258 | "array": [ { "a":1, "b":"two", "c":3, "d":4 } ], 259 | "object": { "a":1, "b":"two", "c":3, "d":4 } 260 | } 261 | }, 262 | { 263 | "expression": "obj!'\"a\":1'", 264 | "result": { 265 | "array": [ { "a":1 } ], 266 | "object": { "a":1 } 267 | } 268 | }, 269 | { 270 | "expression": "x:{a:1 b:coffee}", 271 | "result": { 272 | "array": [ { "x": { "a": 1, "b": "coffee" }} ], 273 | "object": { "x": { "a": 1, "b": "coffee" }} 274 | } 275 | } 276 | ] 277 | },{ 278 | "name": "assign", 279 | "cases": [ 280 | { 281 | "expression": "a:1", 282 | "result": { 283 | "array": [ { "a":1 } ], 284 | "object": { "a":1 } 285 | } 286 | }, 287 | { 288 | "expression": "a:b:c:string", 289 | "result": { 290 | "array": [ {"a":{"b":{"c":"string"}}} ], 291 | "object": {"a":{"b":{"c":"string"}}} 292 | } 293 | }, 294 | { 295 | "expression": "a:1 b:2 c:3", 296 | "result": { 297 | "array": [ { "a":1 }, { "b":2 }, { "c":3 } ], 298 | "object": { "a":1, "b":2, "c":3 } 299 | } 300 | }, 301 | { 302 | "expression": "'a':1", 303 | "result": { 304 | "array": [ { "a":1 } ], 305 | "object": { "a":1 } 306 | } 307 | }, 308 | { 309 | "expression": "\"a\":1", 310 | "result": { 311 | "array": [ { "a":1 } ], 312 | "object": { "a":1 } 313 | } 314 | }, 315 | { 316 | "expression": "~@$%^&*()-:1", 317 | "result": { 318 | "array": [ { "~@$%^&*()-":1 } ], 319 | "object": { "~@$%^&*()-": 1 } 320 | } 321 | } 322 | ] 323 | },{ 324 | "name": "comments", 325 | "cases": [ 326 | { 327 | "expression": "#", 328 | "result": { 329 | "array": [], 330 | "object": {} 331 | } 332 | }, 333 | { 334 | "expression": "a:\\#", 335 | "result": { 336 | "array": [ { "a": "#" } ], 337 | "object": { "a": "#" } 338 | } 339 | }, 340 | { 341 | "expression": "a:'\\#1'", 342 | "result": { 343 | "array": [ { "a": "#1" } ], 344 | "object": { "a": "#1" } 345 | } 346 | }, 347 | { 348 | "expression": "a:1 # a", 349 | "result": { 350 | "array": [ { "a":1 } ], 351 | "object": { "a":1 } 352 | } 353 | }, 354 | { 355 | "expression": " # a", 356 | "result": { 357 | "array": [], 358 | "object": {} 359 | } 360 | }, 361 | { 362 | "expression": "#a", 363 | "result": { 364 | "array": [], 365 | "object": {} 366 | } 367 | }, 368 | { 369 | "expression": "x: [a # b c]\n# good\n tone ]", 370 | "result": { 371 | "array": [ { "x": ["a", "tone"] } ], 372 | "object": { "x": ["a", "tone"] } 373 | } 374 | }, 375 | { 376 | "expression": "{x: [#y ]\n] #n\n} 42 #^\n@", 377 | "result": { 378 | "array": [ { "x": [] }, 42, "@" ], 379 | "object": { "0": 42, "1": "@", "x": [] } 380 | } 381 | }, 382 | { 383 | "expression": "{x: [#y ]\n] #n\n} 42 #^\n@", 384 | "result": { 385 | "array": [ { "x": [] }, 42, "@" ], 386 | "object": { "0": 42, "1": "@", "x": [] } 387 | } 388 | } 389 | ] 390 | }] 391 | -------------------------------------------------------------------------------- /test/fixtures/json-pass1.json: -------------------------------------------------------------------------------- 1 | [ 2 | "JSON Test Pattern pass1", 3 | {"object with 1 member":["array with 1 element"]}, 4 | {}, 5 | [], 6 | -42, 7 | true, 8 | false, 9 | null, 10 | { 11 | "integer": 1234567890, 12 | "real": -9876.543210, 13 | "e": 0.123456789e-12, 14 | "E": 1.234567890E+34, 15 | "": 23456789012E66, 16 | "zero": 0, 17 | "one": 1, 18 | "space": " ", 19 | "quote": "\"", 20 | "backslash": "\\", 21 | "controls": "\b\f\n\r\t", 22 | "slash": "/ & \/", 23 | "alpha": "abcdefghijklmnopqrstuvwyz", 24 | "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", 25 | "digit": "0123456789", 26 | "0123456789": "digit", 27 | "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", 28 | "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", 29 | "true": true, 30 | "false": false, 31 | "null": null, 32 | "array":[ ], 33 | "object":{ }, 34 | "address": "50 St. James Street", 35 | "url": "http://www.JSON.org/", 36 | "comment": "// /* */": " ", 38 | " s p a c e d " :[1,2 , 3 39 | 40 | , 41 | 42 | 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], 43 | "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", 44 | "quotes": "" \u0022 %22 0x22 034 "", 45 | "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" 46 | : "A key can be any string" 47 | }, 48 | 0.5 ,98.6 49 | , 50 | 99.44 51 | , 52 | 53 | 1066, 54 | 1e1, 55 | 0.1e1, 56 | 1e-1, 57 | 1e00,2e+00,2e-00 58 | ,"rosebud"] 59 | -------------------------------------------------------------------------------- /test/fixtures/usonrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | types: { 3 | // `js!` , for example: `js!"4+5"` 4 | js: function(js) { 5 | return eval(js); 6 | }, 7 | // `hello!` 8 | 'hello': function(val) { 9 | return 'Hello '+ val; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var assert = require('assert'); 5 | var path = require('path'); 6 | var USON = require('../'); 7 | 8 | var loadFileSync = function(fn, cb) { 9 | return fs.readFileSync(fn, { 'encoding': 'utf8' }); 10 | } 11 | var loadFixture = function(fn, cb) { 12 | fn = path.resolve(__dirname,'fixtures',fn); 13 | fs.readFile(fn, { 'encoding': 'utf8' }, function (err, data) { 14 | cb(JSON.parse(data)); 15 | }); 16 | } 17 | 18 | describe('test/index', function() { 19 | 20 | it('should parse JSON Test Pattern: pass #1', function(done) { 21 | var fn = path.resolve(__dirname,'fixtures','json-pass1.json'); 22 | USON.parse(loadFileSync(fn)); 23 | done(); 24 | }); 25 | 26 | it('should parse own package.json file', function(done) { 27 | var fn = path.resolve(__dirname,'..','package.json'); 28 | loadFixture(fn, function(fixture) { 29 | assert.deepEqual(USON.parse(loadFileSync(fn), "json"), fixture); 30 | done(); 31 | }); 32 | }); 33 | 34 | it('support custom types #1', function() { 35 | var types = { 36 | maj: function(val){ 37 | return val+' day'; 38 | } 39 | }; 40 | assert.deepEqual(USON.parse('maj!good', null, types), ['good day']); 41 | }); 42 | it('support custom types #2', function() { 43 | var types = { 44 | myobj: function(val){ 45 | return 'hello '+val.name; 46 | } 47 | }; 48 | var res = USON.parse('myobj!name:three', null, types); 49 | assert.deepEqual(res, ['hello three']); 50 | }); 51 | }); 52 | -------------------------------------------------------------------------------- /tools/test.js: -------------------------------------------------------------------------------- 1 | var USON = require('..'); 2 | 3 | var types = { 4 | welcome: function(value) { 5 | return("Hello " + value + "!"); 6 | } 7 | }; 8 | console.log(USON.parse('welcome!john', null, types)); 9 | 10 | console.log(JSON.stringify(USON.parse('null'))); 11 | console.log(JSON.stringify(USON.parse(''))); 12 | console.log(JSON.stringify(USON.parse(' '))); 13 | console.log(JSON.stringify(USON.parse(' # neco'))); 14 | console.log(JSON.stringify(USON.parse('# neco'))); 15 | -------------------------------------------------------------------------------- /tools/testfile.uson: -------------------------------------------------------------------------------- 1 | b: [ 1 2 3 ] 2 | a : 45 # this is comment 3 | { console: true } 4 | -------------------------------------------------------------------------------- /tools/typing.js: -------------------------------------------------------------------------------- 1 | var uson = require('./'); 2 | var yaml = require('js-yaml'); 3 | var assert = require('assert'); 4 | 5 | var str = '[ true, false, null, 1, 12.34, string, undefined, NaN, Number, "false" ]'; 6 | console.log(JSON.stringify(uson.parse(str, 'json'))); 7 | console.log(JSON.stringify(yaml.load(str))); 8 | 9 | console.log(assert.deepEqual(uson.parse(str, 'json'), yaml.load(str)) ? false : true); 10 | 11 | --------------------------------------------------------------------------------