├── .gitignore ├── LICENSE ├── README.md ├── __tests__ ├── compose-test.js └── parser-test.js ├── grammar.pegjs ├── index.js ├── lib ├── compose.js ├── inject-params.js ├── parser.js └── stringify.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jamie Greeff 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GraphQLite [![NPM](https://img.shields.io/npm/v/graphqlite.svg?style=flat)](https://npmjs.org/package/graphqlite) ![Downloads](https://img.shields.io/npm/dm/graphqlite.svg?style=flat) 2 | ======= 3 | 4 | GraphQLite is a Javascript Parser for Facebook's GraphQL. 5 | 6 | (see http://facebook.github.io/react/blog/2015/05/01/graphql-introduction.html) 7 | 8 | ## Installation 9 | 10 | ```sh 11 | $ npm install graphqlite 12 | ``` 13 | 14 | ## Usage 15 | 16 | GraphQLite exposes a simple API for parsing GraphQL (example uses ES6 multi-line strings). 17 | 18 | ```javascript 19 | var graphql = require('graphqlite') 20 | 21 | var output = graphql.parse(` 22 | node(id: 123) { 23 | id, 24 | name, 25 | birthdate { 26 | month, 27 | day, 28 | }, 29 | friends(first: 1) { 30 | cursor, 31 | edges { 32 | node { 33 | name 34 | } 35 | } 36 | } 37 | } 38 | 39 | filter(name: "test string parameter") { 40 | 41 | } 42 | `) 43 | 44 | var backToString = graphql.stringify(output) 45 | var pretty = graphql.stringify(output, true) 46 | ``` 47 | 48 | In the above example, `output` will be: 49 | 50 | ```javascript 51 | [{ 52 | "type": "node", 53 | "params": { 54 | "id": 123 55 | }, 56 | "fields": { 57 | "id": true, 58 | "name": true, 59 | "birthdate": { 60 | "fields": { 61 | "month": true, 62 | "day": true 63 | } 64 | }, 65 | "friends": { 66 | "params": { 67 | "first": 1 68 | }, 69 | "fields": { 70 | "cursor": true, 71 | "edges": { 72 | "fields": { 73 | "node": { 74 | "fields": { 75 | "name": true 76 | } 77 | } 78 | } 79 | } 80 | } 81 | } 82 | } 83 | }, { 84 | "type": "filter", 85 | "params": { 86 | "name": "test string parameter" 87 | } 88 | }] 89 | ``` 90 | 91 | `stringify` takes the output from `parse` and generates a GraphQL string. If no second parameter is provided, the output will be minified. If the second parameter is `true`, the output will be prettified. 92 | 93 | ### ES6 Templates 94 | 95 | GraphQLite can also be used with ES6 template strings, like follows: 96 | 97 | ```javascript 98 | var graphql = require('graphqlite') 99 | 100 | var EventQuery = graphql` 101 | Event { 102 | name, 103 | location 104 | } 105 | ` 106 | 107 | var UserQuery = graphql` 108 | User { 109 | name, 110 | profilePic 111 | } 112 | ` 113 | 114 | var FinalQuery = graphql` 115 | Viewer { 116 | endpoint, 117 | feed(first: ) { 118 | id 119 | }, 120 | 121 | ${EventQuery}, 122 | ${UserQuery} 123 | } 124 | ` 125 | 126 | ``` 127 | 128 | This allows queries to be composed. `FinalQuery` in the above example will be a composed GraphQL string. 129 | 130 | ## Roadmap 131 | Facebook will be releasing a GraphQL module in the future, but I didn't know what to expect from this 132 | so I created this basic one as an experiment. 133 | Therefore this module could become obsolete in the future. 134 | 135 | ## License 136 | 137 | Licensed under the MIT License. 138 | 139 | View the full license [here](https://raw.githubusercontent.com/madjam002/graphqlite/master/LICENSE). 140 | -------------------------------------------------------------------------------- /__tests__/compose-test.js: -------------------------------------------------------------------------------- 1 | jest.autoMockOff() 2 | 3 | describe('compose', function () { 4 | it('should combine several queries', function () { 5 | var graphqlite = require('../') 6 | var output 7 | 8 | var UserQuery = graphqlite` 9 | User { 10 | name 11 | } 12 | ` 13 | 14 | var EventQuery = graphqlite` 15 | Event { 16 | name, 17 | location, 18 | 19 | creator { 20 | ${UserQuery} 21 | } 22 | } 23 | ` 24 | 25 | output = graphqlite` 26 | Viewer { 27 | ipAddress, 28 | 29 | events(first: ) { 30 | ${EventQuery} 31 | }, 32 | 33 | friends(first: 10) { 34 | ${UserQuery} 35 | } 36 | } 37 | ` 38 | 39 | expected = ` 40 | Viewer { 41 | ipAddress, 42 | 43 | events(first: ) { 44 | name, 45 | location, 46 | 47 | creator { 48 | name 49 | } 50 | }, 51 | 52 | friends(first: 10) { 53 | name 54 | } 55 | } 56 | ` 57 | 58 | expect(graphqlite.stringify(graphqlite.parse(output))) 59 | .toEqual(graphqlite.stringify(graphqlite.parse(expected))) 60 | }) 61 | }) 62 | -------------------------------------------------------------------------------- /__tests__/parser-test.js: -------------------------------------------------------------------------------- 1 | jest.autoMockOff() 2 | 3 | describe('parser', function () { 4 | it('should parse graphql input', function () { 5 | var graphqlite = require('../') 6 | var output 7 | 8 | output = graphqlite.parse(` 9 | user(id: "abc123,_-@'/hi\\"test with spaces") { 10 | id, 11 | name, 12 | birthdate { 13 | month, day 14 | }, 15 | birthdate { 16 | day, 17 | year, 18 | }, 19 | friends(first: , after: 100) { 20 | edges { 21 | node { 22 | name, 23 | id, 24 | } 25 | } 26 | }, 27 | profilePicture() { 28 | id, 29 | } 30 | } 31 | 32 | Viewer { 33 | something(first: 62, minus: -1503423, decimal: 523.3594358, decimalAndMinus: -234234.4656456, string: ) { 34 | edges { 35 | node { 36 | id 37 | } 38 | } 39 | } 40 | } 41 | 42 | test(id: backwardsCompatibility) { 43 | name 44 | } 45 | `) 46 | 47 | expected = [{ 48 | "type": "user", 49 | "params": { 50 | "id": "abc123,_-@'/hi\"test with spaces" 51 | }, 52 | "fields": { 53 | "id": true, 54 | "name": true, 55 | "birthdate": { 56 | "fields": { 57 | "day": true, 58 | "month": true, 59 | "year": true 60 | } 61 | }, 62 | "friends": { 63 | "params": { 64 | "first": { "type": "queryParam", "name": "first" }, 65 | "after": 100 66 | }, 67 | "fields": { 68 | "edges": { 69 | "fields": { 70 | "node": { 71 | "fields": { 72 | "name": true, 73 | "id": true 74 | } 75 | } 76 | } 77 | } 78 | } 79 | }, 80 | "profilePicture": { 81 | "params": {}, 82 | "fields": { 83 | "id": true 84 | } 85 | } 86 | } 87 | }, { 88 | "type": "Viewer", 89 | "fields": { 90 | "something": { 91 | "params": { 92 | "first": 62, 93 | "minus": -1503423, 94 | "decimal": 523.3594358, 95 | "decimalAndMinus": -234234.4656456, 96 | "string": { "type": "queryParam", "name": "hello" } 97 | }, 98 | "fields": { 99 | "edges": { 100 | "fields": { 101 | "node": { 102 | "fields": { 103 | "id": true 104 | } 105 | } 106 | } 107 | } 108 | } 109 | } 110 | } 111 | }, { 112 | "type": "test", 113 | "params": { 114 | "id": "backwardsCompatibility" 115 | }, 116 | "fields": { 117 | "name": true 118 | } 119 | }] 120 | 121 | expect(output).toEqual(expected) 122 | 123 | var queryString = graphqlite.stringify(expected) 124 | var queryStringPretty = graphqlite.stringify(expected, true) 125 | 126 | var output2 = graphqlite.parse(queryString) 127 | var output3 = graphqlite.parse(queryStringPretty) 128 | 129 | var injectedParams = graphqlite.injectParams(output, {first: 999, hello: 'foobar'}) 130 | 131 | expect(output2).toEqual(expected) 132 | expect(output3).toEqual(expected) 133 | 134 | expected[0].fields.friends.params.first = 999 135 | expected[1].fields.something.params.string = 'foobar' 136 | 137 | expect(injectedParams).toEqual(expected) 138 | }) 139 | }) 140 | -------------------------------------------------------------------------------- /grammar.pegjs: -------------------------------------------------------------------------------- 1 | /* 2 | GraphQL Grammar 3 | */ 4 | 5 | { 6 | var extend = require('extend') 7 | } 8 | 9 | GraphQL 10 | = ws value:definitionOrCall* ws { return value; } 11 | 12 | ws "whitespace" = [ \t\n\r]* 13 | 14 | beginObject = ws "{" ws 15 | endObject = ws "}" ws 16 | valueSeparator = ws "," ws 17 | callSeparator = ws "." ws 18 | paramNameSeparator = ws ":" ws 19 | 20 | // Values 21 | value = false 22 | / true 23 | / null 24 | / queryParam 25 | / number 26 | / string 27 | / name // for backwards compatibility of strings without using quotes 28 | / undefined 29 | 30 | nameOrUndf = name 31 | / undefined 32 | 33 | undefined = "" { return undefined; } 34 | false = "false" { return false; } 35 | null = "null" { return null; } 36 | true = "true" { return true; } 37 | 38 | // Numbers 39 | number "number" 40 | = minus? int frac? exp? { return parseFloat(text()); } 41 | 42 | decimal_point = "." 43 | digit1_9 = [1-9] 44 | e = [eE] 45 | exp = e (minus / plus)? DIGIT+ 46 | frac = decimal_point DIGIT+ 47 | int = zero / (digit1_9 DIGIT*) 48 | minus = "-" 49 | plus = "+" 50 | zero = "0" 51 | 52 | // Strings 53 | 54 | name "name" 55 | = chars:nameChar+ { 56 | var str = chars.join(""); 57 | var num = parseInt(str); 58 | if (!isNaN(num) && num.toString() === str) return num; 59 | else return str; 60 | } 61 | 62 | nameChar = [0-9a-zA-Z/_-] 63 | 64 | string "string" 65 | = quotation_mark chars:char* quotation_mark { return chars.join(""); } 66 | 67 | char 68 | = unescaped 69 | / escape 70 | sequence:( 71 | '"' 72 | / "\\" 73 | / "/" 74 | / "b" { return "\b"; } 75 | / "f" { return "\f"; } 76 | / "n" { return "\n"; } 77 | / "r" { return "\r"; } 78 | / "t" { return "\t"; } 79 | / "u" digits:$(HEXDIG HEXDIG HEXDIG HEXDIG) { 80 | return String.fromCharCode(parseInt(digits, 16)); 81 | } 82 | ) 83 | { return sequence; } 84 | 85 | escape = "\\" 86 | quotation_mark = '"' 87 | unescaped = [\x20-\x21\x23-\x5B\x5D-\u10FFFF] 88 | 89 | /* ----- Core ABNF Rules ----- */ 90 | 91 | /* See RFC 4234, Appendix B (http://tools.ietf.org/html/rfc4627). */ 92 | DIGIT = [0-9] 93 | HEXDIG = [0-9a-f]i 94 | 95 | // Objects 96 | 97 | object 98 | = beginObject 99 | members:( 100 | first:member 101 | rest:(valueSeparator m:member { return m; })* 102 | { 103 | var result = {}, i, newData; 104 | 105 | if (first.name !== undefined) { 106 | newData = {}; 107 | newData[first.name] = first.value || true; 108 | extend(true, result, newData); 109 | } 110 | 111 | for (i = 0; i < rest.length; i++) { 112 | if (rest[i].name !== undefined) { 113 | newData = {}; 114 | newData[rest[i].name] = rest[i].value || true; 115 | extend(true, result, newData); 116 | } 117 | } 118 | 119 | return result; 120 | } 121 | )? 122 | endObject 123 | { return members !== null ? members: {}; } 124 | 125 | member 126 | = name:name ws value:childDefinitionOrCall { 127 | return { name: name, value: value }; 128 | } 129 | / name:nameOrUndf { 130 | return { name: name }; 131 | } 132 | 133 | // Definitions 134 | 135 | definition "definition" 136 | = type:nameOrUndf 137 | members:object { 138 | return { type: type, fields: members } 139 | } 140 | 141 | childDefinition 142 | = members:object { 143 | return { fields: members } 144 | } 145 | 146 | // Calls 147 | 148 | params 149 | = (first:param 150 | rest:(valueSeparator m:param { return m; })* 151 | { 152 | var result = {}, i; 153 | 154 | result[first.name] = first.value; 155 | 156 | for (i = 0; i < rest.length; i++) { 157 | result[rest[i].name] = rest[i].value; 158 | } 159 | 160 | return result; 161 | })? 162 | 163 | param 164 | = name:name paramNameSeparator value:value { 165 | return { name: name, value: value }; 166 | } 167 | 168 | call 169 | = ws type:name ws "(" params:params ")" members:object { 170 | return { type: type, params: params || {}, fields: members } 171 | } 172 | 173 | childCall 174 | = ws "(" params:params ")" members:object { 175 | return { params: params || {}, fields: members } 176 | } 177 | 178 | // Query Params 179 | 180 | queryParam = "<" name:name ">" { 181 | return { type: "queryParam", name: name } 182 | } 183 | 184 | definitionOrCall = definition / call 185 | childDefinitionOrCall = childDefinition / childCall 186 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var compose = require('./lib/compose') 2 | 3 | module.exports = function () { 4 | return compose(arguments[0], Array.prototype.slice.call(arguments, 1)) 5 | } 6 | 7 | module.exports.parse = require('./lib/parser').parse 8 | 9 | module.exports.stringify = require('./lib/stringify') 10 | 11 | module.exports.injectParams = require('./lib/inject-params') 12 | -------------------------------------------------------------------------------- /lib/compose.js: -------------------------------------------------------------------------------- 1 | var parse = require('./parser').parse 2 | var stringify = require('./stringify') 3 | 4 | module.exports = function (queryParts, subQueries) { 5 | var subQueryStrings = subQueries.map(function (subQuery) { 6 | var parsed = parse(subQuery) 7 | 8 | if (parsed.length > 1) { 9 | throw new Error('Query can only return one call') 10 | } 11 | 12 | // get rid of type so it can be minified 13 | parsed[0].type = undefined 14 | 15 | var minified = stringify(parsed) 16 | if (minified.substring(0, 1) === '{') 17 | minified = minified.substring(1, minified.length - 1) 18 | 19 | return minified 20 | }) 21 | 22 | // build final query 23 | var finalQuery = '' 24 | 25 | for (var i = 0; i < queryParts.length; i++) { 26 | var part = queryParts[i] 27 | finalQuery += part 28 | 29 | if (i < subQueryStrings.length) 30 | finalQuery += subQueryStrings[i] 31 | } 32 | 33 | return finalQuery 34 | } 35 | -------------------------------------------------------------------------------- /lib/inject-params.js: -------------------------------------------------------------------------------- 1 | var parseDefinition = function (definition, params) { 2 | // params 3 | if (definition.params) { 4 | for (var paramName in definition.params) { 5 | var paramValue = definition.params[paramName] 6 | 7 | if (paramValue.type === 'queryParam') { 8 | definition.params[paramName] = params[paramValue.name] 9 | } 10 | } 11 | } 12 | 13 | // recurse through sub definitions 14 | for (field in definition.fields) { 15 | var fieldValue = definition.fields[field] 16 | 17 | if (fieldValue !== true) { 18 | // sub definition 19 | parseDefinition(fieldValue, params) 20 | } 21 | } 22 | } 23 | 24 | module.exports = function (data, params) { 25 | // loop through definitions 26 | for (var i = 0; i < data.length; i++) { 27 | parseDefinition(data[i], params) 28 | } 29 | 30 | return data 31 | } 32 | -------------------------------------------------------------------------------- /lib/parser.js: -------------------------------------------------------------------------------- 1 | module.exports = (function() { 2 | /* 3 | * Generated by PEG.js 0.8.0. 4 | * 5 | * http://pegjs.majda.cz/ 6 | */ 7 | 8 | function peg$subclass(child, parent) { 9 | function ctor() { this.constructor = child; } 10 | ctor.prototype = parent.prototype; 11 | child.prototype = new ctor(); 12 | } 13 | 14 | function SyntaxError(message, expected, found, offset, line, column) { 15 | this.message = message; 16 | this.expected = expected; 17 | this.found = found; 18 | this.offset = offset; 19 | this.line = line; 20 | this.column = column; 21 | 22 | this.name = "SyntaxError"; 23 | } 24 | 25 | peg$subclass(SyntaxError, Error); 26 | 27 | function parse(input) { 28 | var options = arguments.length > 1 ? arguments[1] : {}, 29 | 30 | peg$FAILED = {}, 31 | 32 | peg$startRuleFunctions = { GraphQL: peg$parseGraphQL }, 33 | peg$startRuleFunction = peg$parseGraphQL, 34 | 35 | peg$c0 = peg$FAILED, 36 | peg$c1 = [], 37 | peg$c2 = function(value) { return value; }, 38 | peg$c3 = { type: "other", description: "whitespace" }, 39 | peg$c4 = /^[ \t\n\r]/, 40 | peg$c5 = { type: "class", value: "[ \\t\\n\\r]", description: "[ \\t\\n\\r]" }, 41 | peg$c6 = "{", 42 | peg$c7 = { type: "literal", value: "{", description: "\"{\"" }, 43 | peg$c8 = "}", 44 | peg$c9 = { type: "literal", value: "}", description: "\"}\"" }, 45 | peg$c10 = ",", 46 | peg$c11 = { type: "literal", value: ",", description: "\",\"" }, 47 | peg$c12 = ".", 48 | peg$c13 = { type: "literal", value: ".", description: "\".\"" }, 49 | peg$c14 = ":", 50 | peg$c15 = { type: "literal", value: ":", description: "\":\"" }, 51 | peg$c16 = "", 52 | peg$c17 = function() { return undefined; }, 53 | peg$c18 = "false", 54 | peg$c19 = { type: "literal", value: "false", description: "\"false\"" }, 55 | peg$c20 = function() { return false; }, 56 | peg$c21 = "null", 57 | peg$c22 = { type: "literal", value: "null", description: "\"null\"" }, 58 | peg$c23 = function() { return null; }, 59 | peg$c24 = "true", 60 | peg$c25 = { type: "literal", value: "true", description: "\"true\"" }, 61 | peg$c26 = function() { return true; }, 62 | peg$c27 = { type: "other", description: "number" }, 63 | peg$c28 = null, 64 | peg$c29 = function() { return parseFloat(text()); }, 65 | peg$c30 = /^[1-9]/, 66 | peg$c31 = { type: "class", value: "[1-9]", description: "[1-9]" }, 67 | peg$c32 = /^[eE]/, 68 | peg$c33 = { type: "class", value: "[eE]", description: "[eE]" }, 69 | peg$c34 = "-", 70 | peg$c35 = { type: "literal", value: "-", description: "\"-\"" }, 71 | peg$c36 = "+", 72 | peg$c37 = { type: "literal", value: "+", description: "\"+\"" }, 73 | peg$c38 = "0", 74 | peg$c39 = { type: "literal", value: "0", description: "\"0\"" }, 75 | peg$c40 = { type: "other", description: "name" }, 76 | peg$c41 = function(chars) { 77 | var str = chars.join(""); 78 | var num = parseInt(str); 79 | if (!isNaN(num) && num.toString() === str) return num; 80 | else return str; 81 | }, 82 | peg$c42 = /^[0-9a-zA-Z\/_\-]/, 83 | peg$c43 = { type: "class", value: "[0-9a-zA-Z\\/_\\-]", description: "[0-9a-zA-Z\\/_\\-]" }, 84 | peg$c44 = { type: "other", description: "string" }, 85 | peg$c45 = function(chars) { return chars.join(""); }, 86 | peg$c46 = "\"", 87 | peg$c47 = { type: "literal", value: "\"", description: "\"\\\"\"" }, 88 | peg$c48 = "\\", 89 | peg$c49 = { type: "literal", value: "\\", description: "\"\\\\\"" }, 90 | peg$c50 = "/", 91 | peg$c51 = { type: "literal", value: "/", description: "\"/\"" }, 92 | peg$c52 = "b", 93 | peg$c53 = { type: "literal", value: "b", description: "\"b\"" }, 94 | peg$c54 = function() { return "\b"; }, 95 | peg$c55 = "f", 96 | peg$c56 = { type: "literal", value: "f", description: "\"f\"" }, 97 | peg$c57 = function() { return "\f"; }, 98 | peg$c58 = "n", 99 | peg$c59 = { type: "literal", value: "n", description: "\"n\"" }, 100 | peg$c60 = function() { return "\n"; }, 101 | peg$c61 = "r", 102 | peg$c62 = { type: "literal", value: "r", description: "\"r\"" }, 103 | peg$c63 = function() { return "\r"; }, 104 | peg$c64 = "t", 105 | peg$c65 = { type: "literal", value: "t", description: "\"t\"" }, 106 | peg$c66 = function() { return "\t"; }, 107 | peg$c67 = "u", 108 | peg$c68 = { type: "literal", value: "u", description: "\"u\"" }, 109 | peg$c69 = function(digits) { 110 | return String.fromCharCode(parseInt(digits, 16)); 111 | }, 112 | peg$c70 = function(sequence) { return sequence; }, 113 | peg$c71 = /^[ -!#-[\]-\u10FFFF]/, 114 | peg$c72 = { type: "class", value: "[ -!#-[\\]-\\u10FFFF]", description: "[ -!#-[\\]-\\u10FFFF]" }, 115 | peg$c73 = /^[0-9]/, 116 | peg$c74 = { type: "class", value: "[0-9]", description: "[0-9]" }, 117 | peg$c75 = /^[0-9a-f]/i, 118 | peg$c76 = { type: "class", value: "[0-9a-f]i", description: "[0-9a-f]i" }, 119 | peg$c77 = function(m) { return m; }, 120 | peg$c78 = function(first, rest) { 121 | var result = {}, i, newData; 122 | 123 | if (first.name !== undefined) { 124 | newData = {}; 125 | newData[first.name] = first.value || true; 126 | extend(true, result, newData); 127 | } 128 | 129 | for (i = 0; i < rest.length; i++) { 130 | if (rest[i].name !== undefined) { 131 | newData = {}; 132 | newData[rest[i].name] = rest[i].value || true; 133 | extend(true, result, newData); 134 | } 135 | } 136 | 137 | return result; 138 | }, 139 | peg$c79 = function(members) { return members !== null ? members: {}; }, 140 | peg$c80 = function(name, value) { 141 | return { name: name, value: value }; 142 | }, 143 | peg$c81 = function(name) { 144 | return { name: name }; 145 | }, 146 | peg$c82 = { type: "other", description: "definition" }, 147 | peg$c83 = function(type, members) { 148 | return { type: type, fields: members } 149 | }, 150 | peg$c84 = function(members) { 151 | return { fields: members } 152 | }, 153 | peg$c85 = function(first, rest) { 154 | var result = {}, i; 155 | 156 | result[first.name] = first.value; 157 | 158 | for (i = 0; i < rest.length; i++) { 159 | result[rest[i].name] = rest[i].value; 160 | } 161 | 162 | return result; 163 | }, 164 | peg$c86 = "(", 165 | peg$c87 = { type: "literal", value: "(", description: "\"(\"" }, 166 | peg$c88 = ")", 167 | peg$c89 = { type: "literal", value: ")", description: "\")\"" }, 168 | peg$c90 = function(type, params, members) { 169 | return { type: type, params: params || {}, fields: members } 170 | }, 171 | peg$c91 = function(params, members) { 172 | return { params: params || {}, fields: members } 173 | }, 174 | peg$c92 = "<", 175 | peg$c93 = { type: "literal", value: "<", description: "\"<\"" }, 176 | peg$c94 = ">", 177 | peg$c95 = { type: "literal", value: ">", description: "\">\"" }, 178 | peg$c96 = function(name) { 179 | return { type: "queryParam", name: name } 180 | }, 181 | 182 | peg$currPos = 0, 183 | peg$reportedPos = 0, 184 | peg$cachedPos = 0, 185 | peg$cachedPosDetails = { line: 1, column: 1, seenCR: false }, 186 | peg$maxFailPos = 0, 187 | peg$maxFailExpected = [], 188 | peg$silentFails = 0, 189 | 190 | peg$result; 191 | 192 | if ("startRule" in options) { 193 | if (!(options.startRule in peg$startRuleFunctions)) { 194 | throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); 195 | } 196 | 197 | peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; 198 | } 199 | 200 | function text() { 201 | return input.substring(peg$reportedPos, peg$currPos); 202 | } 203 | 204 | function offset() { 205 | return peg$reportedPos; 206 | } 207 | 208 | function line() { 209 | return peg$computePosDetails(peg$reportedPos).line; 210 | } 211 | 212 | function column() { 213 | return peg$computePosDetails(peg$reportedPos).column; 214 | } 215 | 216 | function expected(description) { 217 | throw peg$buildException( 218 | null, 219 | [{ type: "other", description: description }], 220 | peg$reportedPos 221 | ); 222 | } 223 | 224 | function error(message) { 225 | throw peg$buildException(message, null, peg$reportedPos); 226 | } 227 | 228 | function peg$computePosDetails(pos) { 229 | function advance(details, startPos, endPos) { 230 | var p, ch; 231 | 232 | for (p = startPos; p < endPos; p++) { 233 | ch = input.charAt(p); 234 | if (ch === "\n") { 235 | if (!details.seenCR) { details.line++; } 236 | details.column = 1; 237 | details.seenCR = false; 238 | } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") { 239 | details.line++; 240 | details.column = 1; 241 | details.seenCR = true; 242 | } else { 243 | details.column++; 244 | details.seenCR = false; 245 | } 246 | } 247 | } 248 | 249 | if (peg$cachedPos !== pos) { 250 | if (peg$cachedPos > pos) { 251 | peg$cachedPos = 0; 252 | peg$cachedPosDetails = { line: 1, column: 1, seenCR: false }; 253 | } 254 | advance(peg$cachedPosDetails, peg$cachedPos, pos); 255 | peg$cachedPos = pos; 256 | } 257 | 258 | return peg$cachedPosDetails; 259 | } 260 | 261 | function peg$fail(expected) { 262 | if (peg$currPos < peg$maxFailPos) { return; } 263 | 264 | if (peg$currPos > peg$maxFailPos) { 265 | peg$maxFailPos = peg$currPos; 266 | peg$maxFailExpected = []; 267 | } 268 | 269 | peg$maxFailExpected.push(expected); 270 | } 271 | 272 | function peg$buildException(message, expected, pos) { 273 | function cleanupExpected(expected) { 274 | var i = 1; 275 | 276 | expected.sort(function(a, b) { 277 | if (a.description < b.description) { 278 | return -1; 279 | } else if (a.description > b.description) { 280 | return 1; 281 | } else { 282 | return 0; 283 | } 284 | }); 285 | 286 | while (i < expected.length) { 287 | if (expected[i - 1] === expected[i]) { 288 | expected.splice(i, 1); 289 | } else { 290 | i++; 291 | } 292 | } 293 | } 294 | 295 | function buildMessage(expected, found) { 296 | function stringEscape(s) { 297 | function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } 298 | 299 | return s 300 | .replace(/\\/g, '\\\\') 301 | .replace(/"/g, '\\"') 302 | .replace(/\x08/g, '\\b') 303 | .replace(/\t/g, '\\t') 304 | .replace(/\n/g, '\\n') 305 | .replace(/\f/g, '\\f') 306 | .replace(/\r/g, '\\r') 307 | .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) 308 | .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); }) 309 | .replace(/[\u0180-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); }) 310 | .replace(/[\u1080-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); }); 311 | } 312 | 313 | var expectedDescs = new Array(expected.length), 314 | expectedDesc, foundDesc, i; 315 | 316 | for (i = 0; i < expected.length; i++) { 317 | expectedDescs[i] = expected[i].description; 318 | } 319 | 320 | expectedDesc = expected.length > 1 321 | ? expectedDescs.slice(0, -1).join(", ") 322 | + " or " 323 | + expectedDescs[expected.length - 1] 324 | : expectedDescs[0]; 325 | 326 | foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input"; 327 | 328 | return "Expected " + expectedDesc + " but " + foundDesc + " found."; 329 | } 330 | 331 | var posDetails = peg$computePosDetails(pos), 332 | found = pos < input.length ? input.charAt(pos) : null; 333 | 334 | if (expected !== null) { 335 | cleanupExpected(expected); 336 | } 337 | 338 | return new SyntaxError( 339 | message !== null ? message : buildMessage(expected, found), 340 | expected, 341 | found, 342 | pos, 343 | posDetails.line, 344 | posDetails.column 345 | ); 346 | } 347 | 348 | function peg$parseGraphQL() { 349 | var s0, s1, s2, s3; 350 | 351 | s0 = peg$currPos; 352 | s1 = peg$parsews(); 353 | if (s1 !== peg$FAILED) { 354 | s2 = []; 355 | s3 = peg$parsedefinitionOrCall(); 356 | while (s3 !== peg$FAILED) { 357 | s2.push(s3); 358 | s3 = peg$parsedefinitionOrCall(); 359 | } 360 | if (s2 !== peg$FAILED) { 361 | s3 = peg$parsews(); 362 | if (s3 !== peg$FAILED) { 363 | peg$reportedPos = s0; 364 | s1 = peg$c2(s2); 365 | s0 = s1; 366 | } else { 367 | peg$currPos = s0; 368 | s0 = peg$c0; 369 | } 370 | } else { 371 | peg$currPos = s0; 372 | s0 = peg$c0; 373 | } 374 | } else { 375 | peg$currPos = s0; 376 | s0 = peg$c0; 377 | } 378 | 379 | return s0; 380 | } 381 | 382 | function peg$parsews() { 383 | var s0, s1; 384 | 385 | peg$silentFails++; 386 | s0 = []; 387 | if (peg$c4.test(input.charAt(peg$currPos))) { 388 | s1 = input.charAt(peg$currPos); 389 | peg$currPos++; 390 | } else { 391 | s1 = peg$FAILED; 392 | if (peg$silentFails === 0) { peg$fail(peg$c5); } 393 | } 394 | while (s1 !== peg$FAILED) { 395 | s0.push(s1); 396 | if (peg$c4.test(input.charAt(peg$currPos))) { 397 | s1 = input.charAt(peg$currPos); 398 | peg$currPos++; 399 | } else { 400 | s1 = peg$FAILED; 401 | if (peg$silentFails === 0) { peg$fail(peg$c5); } 402 | } 403 | } 404 | peg$silentFails--; 405 | if (s0 === peg$FAILED) { 406 | s1 = peg$FAILED; 407 | if (peg$silentFails === 0) { peg$fail(peg$c3); } 408 | } 409 | 410 | return s0; 411 | } 412 | 413 | function peg$parsebeginObject() { 414 | var s0, s1, s2, s3; 415 | 416 | s0 = peg$currPos; 417 | s1 = peg$parsews(); 418 | if (s1 !== peg$FAILED) { 419 | if (input.charCodeAt(peg$currPos) === 123) { 420 | s2 = peg$c6; 421 | peg$currPos++; 422 | } else { 423 | s2 = peg$FAILED; 424 | if (peg$silentFails === 0) { peg$fail(peg$c7); } 425 | } 426 | if (s2 !== peg$FAILED) { 427 | s3 = peg$parsews(); 428 | if (s3 !== peg$FAILED) { 429 | s1 = [s1, s2, s3]; 430 | s0 = s1; 431 | } else { 432 | peg$currPos = s0; 433 | s0 = peg$c0; 434 | } 435 | } else { 436 | peg$currPos = s0; 437 | s0 = peg$c0; 438 | } 439 | } else { 440 | peg$currPos = s0; 441 | s0 = peg$c0; 442 | } 443 | 444 | return s0; 445 | } 446 | 447 | function peg$parseendObject() { 448 | var s0, s1, s2, s3; 449 | 450 | s0 = peg$currPos; 451 | s1 = peg$parsews(); 452 | if (s1 !== peg$FAILED) { 453 | if (input.charCodeAt(peg$currPos) === 125) { 454 | s2 = peg$c8; 455 | peg$currPos++; 456 | } else { 457 | s2 = peg$FAILED; 458 | if (peg$silentFails === 0) { peg$fail(peg$c9); } 459 | } 460 | if (s2 !== peg$FAILED) { 461 | s3 = peg$parsews(); 462 | if (s3 !== peg$FAILED) { 463 | s1 = [s1, s2, s3]; 464 | s0 = s1; 465 | } else { 466 | peg$currPos = s0; 467 | s0 = peg$c0; 468 | } 469 | } else { 470 | peg$currPos = s0; 471 | s0 = peg$c0; 472 | } 473 | } else { 474 | peg$currPos = s0; 475 | s0 = peg$c0; 476 | } 477 | 478 | return s0; 479 | } 480 | 481 | function peg$parsevalueSeparator() { 482 | var s0, s1, s2, s3; 483 | 484 | s0 = peg$currPos; 485 | s1 = peg$parsews(); 486 | if (s1 !== peg$FAILED) { 487 | if (input.charCodeAt(peg$currPos) === 44) { 488 | s2 = peg$c10; 489 | peg$currPos++; 490 | } else { 491 | s2 = peg$FAILED; 492 | if (peg$silentFails === 0) { peg$fail(peg$c11); } 493 | } 494 | if (s2 !== peg$FAILED) { 495 | s3 = peg$parsews(); 496 | if (s3 !== peg$FAILED) { 497 | s1 = [s1, s2, s3]; 498 | s0 = s1; 499 | } else { 500 | peg$currPos = s0; 501 | s0 = peg$c0; 502 | } 503 | } else { 504 | peg$currPos = s0; 505 | s0 = peg$c0; 506 | } 507 | } else { 508 | peg$currPos = s0; 509 | s0 = peg$c0; 510 | } 511 | 512 | return s0; 513 | } 514 | 515 | function peg$parsecallSeparator() { 516 | var s0, s1, s2, s3; 517 | 518 | s0 = peg$currPos; 519 | s1 = peg$parsews(); 520 | if (s1 !== peg$FAILED) { 521 | if (input.charCodeAt(peg$currPos) === 46) { 522 | s2 = peg$c12; 523 | peg$currPos++; 524 | } else { 525 | s2 = peg$FAILED; 526 | if (peg$silentFails === 0) { peg$fail(peg$c13); } 527 | } 528 | if (s2 !== peg$FAILED) { 529 | s3 = peg$parsews(); 530 | if (s3 !== peg$FAILED) { 531 | s1 = [s1, s2, s3]; 532 | s0 = s1; 533 | } else { 534 | peg$currPos = s0; 535 | s0 = peg$c0; 536 | } 537 | } else { 538 | peg$currPos = s0; 539 | s0 = peg$c0; 540 | } 541 | } else { 542 | peg$currPos = s0; 543 | s0 = peg$c0; 544 | } 545 | 546 | return s0; 547 | } 548 | 549 | function peg$parseparamNameSeparator() { 550 | var s0, s1, s2, s3; 551 | 552 | s0 = peg$currPos; 553 | s1 = peg$parsews(); 554 | if (s1 !== peg$FAILED) { 555 | if (input.charCodeAt(peg$currPos) === 58) { 556 | s2 = peg$c14; 557 | peg$currPos++; 558 | } else { 559 | s2 = peg$FAILED; 560 | if (peg$silentFails === 0) { peg$fail(peg$c15); } 561 | } 562 | if (s2 !== peg$FAILED) { 563 | s3 = peg$parsews(); 564 | if (s3 !== peg$FAILED) { 565 | s1 = [s1, s2, s3]; 566 | s0 = s1; 567 | } else { 568 | peg$currPos = s0; 569 | s0 = peg$c0; 570 | } 571 | } else { 572 | peg$currPos = s0; 573 | s0 = peg$c0; 574 | } 575 | } else { 576 | peg$currPos = s0; 577 | s0 = peg$c0; 578 | } 579 | 580 | return s0; 581 | } 582 | 583 | function peg$parsevalue() { 584 | var s0; 585 | 586 | s0 = peg$parsefalse(); 587 | if (s0 === peg$FAILED) { 588 | s0 = peg$parsetrue(); 589 | if (s0 === peg$FAILED) { 590 | s0 = peg$parsenull(); 591 | if (s0 === peg$FAILED) { 592 | s0 = peg$parsequeryParam(); 593 | if (s0 === peg$FAILED) { 594 | s0 = peg$parsenumber(); 595 | if (s0 === peg$FAILED) { 596 | s0 = peg$parsestring(); 597 | if (s0 === peg$FAILED) { 598 | s0 = peg$parsename(); 599 | if (s0 === peg$FAILED) { 600 | s0 = peg$parseundefined(); 601 | } 602 | } 603 | } 604 | } 605 | } 606 | } 607 | } 608 | 609 | return s0; 610 | } 611 | 612 | function peg$parsenameOrUndf() { 613 | var s0; 614 | 615 | s0 = peg$parsename(); 616 | if (s0 === peg$FAILED) { 617 | s0 = peg$parseundefined(); 618 | } 619 | 620 | return s0; 621 | } 622 | 623 | function peg$parseundefined() { 624 | var s0, s1; 625 | 626 | s0 = peg$currPos; 627 | s1 = peg$c16; 628 | if (s1 !== peg$FAILED) { 629 | peg$reportedPos = s0; 630 | s1 = peg$c17(); 631 | } 632 | s0 = s1; 633 | 634 | return s0; 635 | } 636 | 637 | function peg$parsefalse() { 638 | var s0, s1; 639 | 640 | s0 = peg$currPos; 641 | if (input.substr(peg$currPos, 5) === peg$c18) { 642 | s1 = peg$c18; 643 | peg$currPos += 5; 644 | } else { 645 | s1 = peg$FAILED; 646 | if (peg$silentFails === 0) { peg$fail(peg$c19); } 647 | } 648 | if (s1 !== peg$FAILED) { 649 | peg$reportedPos = s0; 650 | s1 = peg$c20(); 651 | } 652 | s0 = s1; 653 | 654 | return s0; 655 | } 656 | 657 | function peg$parsenull() { 658 | var s0, s1; 659 | 660 | s0 = peg$currPos; 661 | if (input.substr(peg$currPos, 4) === peg$c21) { 662 | s1 = peg$c21; 663 | peg$currPos += 4; 664 | } else { 665 | s1 = peg$FAILED; 666 | if (peg$silentFails === 0) { peg$fail(peg$c22); } 667 | } 668 | if (s1 !== peg$FAILED) { 669 | peg$reportedPos = s0; 670 | s1 = peg$c23(); 671 | } 672 | s0 = s1; 673 | 674 | return s0; 675 | } 676 | 677 | function peg$parsetrue() { 678 | var s0, s1; 679 | 680 | s0 = peg$currPos; 681 | if (input.substr(peg$currPos, 4) === peg$c24) { 682 | s1 = peg$c24; 683 | peg$currPos += 4; 684 | } else { 685 | s1 = peg$FAILED; 686 | if (peg$silentFails === 0) { peg$fail(peg$c25); } 687 | } 688 | if (s1 !== peg$FAILED) { 689 | peg$reportedPos = s0; 690 | s1 = peg$c26(); 691 | } 692 | s0 = s1; 693 | 694 | return s0; 695 | } 696 | 697 | function peg$parsenumber() { 698 | var s0, s1, s2, s3, s4; 699 | 700 | peg$silentFails++; 701 | s0 = peg$currPos; 702 | s1 = peg$parseminus(); 703 | if (s1 === peg$FAILED) { 704 | s1 = peg$c28; 705 | } 706 | if (s1 !== peg$FAILED) { 707 | s2 = peg$parseint(); 708 | if (s2 !== peg$FAILED) { 709 | s3 = peg$parsefrac(); 710 | if (s3 === peg$FAILED) { 711 | s3 = peg$c28; 712 | } 713 | if (s3 !== peg$FAILED) { 714 | s4 = peg$parseexp(); 715 | if (s4 === peg$FAILED) { 716 | s4 = peg$c28; 717 | } 718 | if (s4 !== peg$FAILED) { 719 | peg$reportedPos = s0; 720 | s1 = peg$c29(); 721 | s0 = s1; 722 | } else { 723 | peg$currPos = s0; 724 | s0 = peg$c0; 725 | } 726 | } else { 727 | peg$currPos = s0; 728 | s0 = peg$c0; 729 | } 730 | } else { 731 | peg$currPos = s0; 732 | s0 = peg$c0; 733 | } 734 | } else { 735 | peg$currPos = s0; 736 | s0 = peg$c0; 737 | } 738 | peg$silentFails--; 739 | if (s0 === peg$FAILED) { 740 | s1 = peg$FAILED; 741 | if (peg$silentFails === 0) { peg$fail(peg$c27); } 742 | } 743 | 744 | return s0; 745 | } 746 | 747 | function peg$parsedecimal_point() { 748 | var s0; 749 | 750 | if (input.charCodeAt(peg$currPos) === 46) { 751 | s0 = peg$c12; 752 | peg$currPos++; 753 | } else { 754 | s0 = peg$FAILED; 755 | if (peg$silentFails === 0) { peg$fail(peg$c13); } 756 | } 757 | 758 | return s0; 759 | } 760 | 761 | function peg$parsedigit1_9() { 762 | var s0; 763 | 764 | if (peg$c30.test(input.charAt(peg$currPos))) { 765 | s0 = input.charAt(peg$currPos); 766 | peg$currPos++; 767 | } else { 768 | s0 = peg$FAILED; 769 | if (peg$silentFails === 0) { peg$fail(peg$c31); } 770 | } 771 | 772 | return s0; 773 | } 774 | 775 | function peg$parsee() { 776 | var s0; 777 | 778 | if (peg$c32.test(input.charAt(peg$currPos))) { 779 | s0 = input.charAt(peg$currPos); 780 | peg$currPos++; 781 | } else { 782 | s0 = peg$FAILED; 783 | if (peg$silentFails === 0) { peg$fail(peg$c33); } 784 | } 785 | 786 | return s0; 787 | } 788 | 789 | function peg$parseexp() { 790 | var s0, s1, s2, s3, s4; 791 | 792 | s0 = peg$currPos; 793 | s1 = peg$parsee(); 794 | if (s1 !== peg$FAILED) { 795 | s2 = peg$parseminus(); 796 | if (s2 === peg$FAILED) { 797 | s2 = peg$parseplus(); 798 | } 799 | if (s2 === peg$FAILED) { 800 | s2 = peg$c28; 801 | } 802 | if (s2 !== peg$FAILED) { 803 | s3 = []; 804 | s4 = peg$parseDIGIT(); 805 | if (s4 !== peg$FAILED) { 806 | while (s4 !== peg$FAILED) { 807 | s3.push(s4); 808 | s4 = peg$parseDIGIT(); 809 | } 810 | } else { 811 | s3 = peg$c0; 812 | } 813 | if (s3 !== peg$FAILED) { 814 | s1 = [s1, s2, s3]; 815 | s0 = s1; 816 | } else { 817 | peg$currPos = s0; 818 | s0 = peg$c0; 819 | } 820 | } else { 821 | peg$currPos = s0; 822 | s0 = peg$c0; 823 | } 824 | } else { 825 | peg$currPos = s0; 826 | s0 = peg$c0; 827 | } 828 | 829 | return s0; 830 | } 831 | 832 | function peg$parsefrac() { 833 | var s0, s1, s2, s3; 834 | 835 | s0 = peg$currPos; 836 | s1 = peg$parsedecimal_point(); 837 | if (s1 !== peg$FAILED) { 838 | s2 = []; 839 | s3 = peg$parseDIGIT(); 840 | if (s3 !== peg$FAILED) { 841 | while (s3 !== peg$FAILED) { 842 | s2.push(s3); 843 | s3 = peg$parseDIGIT(); 844 | } 845 | } else { 846 | s2 = peg$c0; 847 | } 848 | if (s2 !== peg$FAILED) { 849 | s1 = [s1, s2]; 850 | s0 = s1; 851 | } else { 852 | peg$currPos = s0; 853 | s0 = peg$c0; 854 | } 855 | } else { 856 | peg$currPos = s0; 857 | s0 = peg$c0; 858 | } 859 | 860 | return s0; 861 | } 862 | 863 | function peg$parseint() { 864 | var s0, s1, s2, s3; 865 | 866 | s0 = peg$parsezero(); 867 | if (s0 === peg$FAILED) { 868 | s0 = peg$currPos; 869 | s1 = peg$parsedigit1_9(); 870 | if (s1 !== peg$FAILED) { 871 | s2 = []; 872 | s3 = peg$parseDIGIT(); 873 | while (s3 !== peg$FAILED) { 874 | s2.push(s3); 875 | s3 = peg$parseDIGIT(); 876 | } 877 | if (s2 !== peg$FAILED) { 878 | s1 = [s1, s2]; 879 | s0 = s1; 880 | } else { 881 | peg$currPos = s0; 882 | s0 = peg$c0; 883 | } 884 | } else { 885 | peg$currPos = s0; 886 | s0 = peg$c0; 887 | } 888 | } 889 | 890 | return s0; 891 | } 892 | 893 | function peg$parseminus() { 894 | var s0; 895 | 896 | if (input.charCodeAt(peg$currPos) === 45) { 897 | s0 = peg$c34; 898 | peg$currPos++; 899 | } else { 900 | s0 = peg$FAILED; 901 | if (peg$silentFails === 0) { peg$fail(peg$c35); } 902 | } 903 | 904 | return s0; 905 | } 906 | 907 | function peg$parseplus() { 908 | var s0; 909 | 910 | if (input.charCodeAt(peg$currPos) === 43) { 911 | s0 = peg$c36; 912 | peg$currPos++; 913 | } else { 914 | s0 = peg$FAILED; 915 | if (peg$silentFails === 0) { peg$fail(peg$c37); } 916 | } 917 | 918 | return s0; 919 | } 920 | 921 | function peg$parsezero() { 922 | var s0; 923 | 924 | if (input.charCodeAt(peg$currPos) === 48) { 925 | s0 = peg$c38; 926 | peg$currPos++; 927 | } else { 928 | s0 = peg$FAILED; 929 | if (peg$silentFails === 0) { peg$fail(peg$c39); } 930 | } 931 | 932 | return s0; 933 | } 934 | 935 | function peg$parsename() { 936 | var s0, s1, s2; 937 | 938 | peg$silentFails++; 939 | s0 = peg$currPos; 940 | s1 = []; 941 | s2 = peg$parsenameChar(); 942 | if (s2 !== peg$FAILED) { 943 | while (s2 !== peg$FAILED) { 944 | s1.push(s2); 945 | s2 = peg$parsenameChar(); 946 | } 947 | } else { 948 | s1 = peg$c0; 949 | } 950 | if (s1 !== peg$FAILED) { 951 | peg$reportedPos = s0; 952 | s1 = peg$c41(s1); 953 | } 954 | s0 = s1; 955 | peg$silentFails--; 956 | if (s0 === peg$FAILED) { 957 | s1 = peg$FAILED; 958 | if (peg$silentFails === 0) { peg$fail(peg$c40); } 959 | } 960 | 961 | return s0; 962 | } 963 | 964 | function peg$parsenameChar() { 965 | var s0; 966 | 967 | if (peg$c42.test(input.charAt(peg$currPos))) { 968 | s0 = input.charAt(peg$currPos); 969 | peg$currPos++; 970 | } else { 971 | s0 = peg$FAILED; 972 | if (peg$silentFails === 0) { peg$fail(peg$c43); } 973 | } 974 | 975 | return s0; 976 | } 977 | 978 | function peg$parsestring() { 979 | var s0, s1, s2, s3; 980 | 981 | peg$silentFails++; 982 | s0 = peg$currPos; 983 | s1 = peg$parsequotation_mark(); 984 | if (s1 !== peg$FAILED) { 985 | s2 = []; 986 | s3 = peg$parsechar(); 987 | while (s3 !== peg$FAILED) { 988 | s2.push(s3); 989 | s3 = peg$parsechar(); 990 | } 991 | if (s2 !== peg$FAILED) { 992 | s3 = peg$parsequotation_mark(); 993 | if (s3 !== peg$FAILED) { 994 | peg$reportedPos = s0; 995 | s1 = peg$c45(s2); 996 | s0 = s1; 997 | } else { 998 | peg$currPos = s0; 999 | s0 = peg$c0; 1000 | } 1001 | } else { 1002 | peg$currPos = s0; 1003 | s0 = peg$c0; 1004 | } 1005 | } else { 1006 | peg$currPos = s0; 1007 | s0 = peg$c0; 1008 | } 1009 | peg$silentFails--; 1010 | if (s0 === peg$FAILED) { 1011 | s1 = peg$FAILED; 1012 | if (peg$silentFails === 0) { peg$fail(peg$c44); } 1013 | } 1014 | 1015 | return s0; 1016 | } 1017 | 1018 | function peg$parsechar() { 1019 | var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; 1020 | 1021 | s0 = peg$parseunescaped(); 1022 | if (s0 === peg$FAILED) { 1023 | s0 = peg$currPos; 1024 | s1 = peg$parseescape(); 1025 | if (s1 !== peg$FAILED) { 1026 | if (input.charCodeAt(peg$currPos) === 34) { 1027 | s2 = peg$c46; 1028 | peg$currPos++; 1029 | } else { 1030 | s2 = peg$FAILED; 1031 | if (peg$silentFails === 0) { peg$fail(peg$c47); } 1032 | } 1033 | if (s2 === peg$FAILED) { 1034 | if (input.charCodeAt(peg$currPos) === 92) { 1035 | s2 = peg$c48; 1036 | peg$currPos++; 1037 | } else { 1038 | s2 = peg$FAILED; 1039 | if (peg$silentFails === 0) { peg$fail(peg$c49); } 1040 | } 1041 | if (s2 === peg$FAILED) { 1042 | if (input.charCodeAt(peg$currPos) === 47) { 1043 | s2 = peg$c50; 1044 | peg$currPos++; 1045 | } else { 1046 | s2 = peg$FAILED; 1047 | if (peg$silentFails === 0) { peg$fail(peg$c51); } 1048 | } 1049 | if (s2 === peg$FAILED) { 1050 | s2 = peg$currPos; 1051 | if (input.charCodeAt(peg$currPos) === 98) { 1052 | s3 = peg$c52; 1053 | peg$currPos++; 1054 | } else { 1055 | s3 = peg$FAILED; 1056 | if (peg$silentFails === 0) { peg$fail(peg$c53); } 1057 | } 1058 | if (s3 !== peg$FAILED) { 1059 | peg$reportedPos = s2; 1060 | s3 = peg$c54(); 1061 | } 1062 | s2 = s3; 1063 | if (s2 === peg$FAILED) { 1064 | s2 = peg$currPos; 1065 | if (input.charCodeAt(peg$currPos) === 102) { 1066 | s3 = peg$c55; 1067 | peg$currPos++; 1068 | } else { 1069 | s3 = peg$FAILED; 1070 | if (peg$silentFails === 0) { peg$fail(peg$c56); } 1071 | } 1072 | if (s3 !== peg$FAILED) { 1073 | peg$reportedPos = s2; 1074 | s3 = peg$c57(); 1075 | } 1076 | s2 = s3; 1077 | if (s2 === peg$FAILED) { 1078 | s2 = peg$currPos; 1079 | if (input.charCodeAt(peg$currPos) === 110) { 1080 | s3 = peg$c58; 1081 | peg$currPos++; 1082 | } else { 1083 | s3 = peg$FAILED; 1084 | if (peg$silentFails === 0) { peg$fail(peg$c59); } 1085 | } 1086 | if (s3 !== peg$FAILED) { 1087 | peg$reportedPos = s2; 1088 | s3 = peg$c60(); 1089 | } 1090 | s2 = s3; 1091 | if (s2 === peg$FAILED) { 1092 | s2 = peg$currPos; 1093 | if (input.charCodeAt(peg$currPos) === 114) { 1094 | s3 = peg$c61; 1095 | peg$currPos++; 1096 | } else { 1097 | s3 = peg$FAILED; 1098 | if (peg$silentFails === 0) { peg$fail(peg$c62); } 1099 | } 1100 | if (s3 !== peg$FAILED) { 1101 | peg$reportedPos = s2; 1102 | s3 = peg$c63(); 1103 | } 1104 | s2 = s3; 1105 | if (s2 === peg$FAILED) { 1106 | s2 = peg$currPos; 1107 | if (input.charCodeAt(peg$currPos) === 116) { 1108 | s3 = peg$c64; 1109 | peg$currPos++; 1110 | } else { 1111 | s3 = peg$FAILED; 1112 | if (peg$silentFails === 0) { peg$fail(peg$c65); } 1113 | } 1114 | if (s3 !== peg$FAILED) { 1115 | peg$reportedPos = s2; 1116 | s3 = peg$c66(); 1117 | } 1118 | s2 = s3; 1119 | if (s2 === peg$FAILED) { 1120 | s2 = peg$currPos; 1121 | if (input.charCodeAt(peg$currPos) === 117) { 1122 | s3 = peg$c67; 1123 | peg$currPos++; 1124 | } else { 1125 | s3 = peg$FAILED; 1126 | if (peg$silentFails === 0) { peg$fail(peg$c68); } 1127 | } 1128 | if (s3 !== peg$FAILED) { 1129 | s4 = peg$currPos; 1130 | s5 = peg$currPos; 1131 | s6 = peg$parseHEXDIG(); 1132 | if (s6 !== peg$FAILED) { 1133 | s7 = peg$parseHEXDIG(); 1134 | if (s7 !== peg$FAILED) { 1135 | s8 = peg$parseHEXDIG(); 1136 | if (s8 !== peg$FAILED) { 1137 | s9 = peg$parseHEXDIG(); 1138 | if (s9 !== peg$FAILED) { 1139 | s6 = [s6, s7, s8, s9]; 1140 | s5 = s6; 1141 | } else { 1142 | peg$currPos = s5; 1143 | s5 = peg$c0; 1144 | } 1145 | } else { 1146 | peg$currPos = s5; 1147 | s5 = peg$c0; 1148 | } 1149 | } else { 1150 | peg$currPos = s5; 1151 | s5 = peg$c0; 1152 | } 1153 | } else { 1154 | peg$currPos = s5; 1155 | s5 = peg$c0; 1156 | } 1157 | if (s5 !== peg$FAILED) { 1158 | s5 = input.substring(s4, peg$currPos); 1159 | } 1160 | s4 = s5; 1161 | if (s4 !== peg$FAILED) { 1162 | peg$reportedPos = s2; 1163 | s3 = peg$c69(s4); 1164 | s2 = s3; 1165 | } else { 1166 | peg$currPos = s2; 1167 | s2 = peg$c0; 1168 | } 1169 | } else { 1170 | peg$currPos = s2; 1171 | s2 = peg$c0; 1172 | } 1173 | } 1174 | } 1175 | } 1176 | } 1177 | } 1178 | } 1179 | } 1180 | } 1181 | if (s2 !== peg$FAILED) { 1182 | peg$reportedPos = s0; 1183 | s1 = peg$c70(s2); 1184 | s0 = s1; 1185 | } else { 1186 | peg$currPos = s0; 1187 | s0 = peg$c0; 1188 | } 1189 | } else { 1190 | peg$currPos = s0; 1191 | s0 = peg$c0; 1192 | } 1193 | } 1194 | 1195 | return s0; 1196 | } 1197 | 1198 | function peg$parseescape() { 1199 | var s0; 1200 | 1201 | if (input.charCodeAt(peg$currPos) === 92) { 1202 | s0 = peg$c48; 1203 | peg$currPos++; 1204 | } else { 1205 | s0 = peg$FAILED; 1206 | if (peg$silentFails === 0) { peg$fail(peg$c49); } 1207 | } 1208 | 1209 | return s0; 1210 | } 1211 | 1212 | function peg$parsequotation_mark() { 1213 | var s0; 1214 | 1215 | if (input.charCodeAt(peg$currPos) === 34) { 1216 | s0 = peg$c46; 1217 | peg$currPos++; 1218 | } else { 1219 | s0 = peg$FAILED; 1220 | if (peg$silentFails === 0) { peg$fail(peg$c47); } 1221 | } 1222 | 1223 | return s0; 1224 | } 1225 | 1226 | function peg$parseunescaped() { 1227 | var s0; 1228 | 1229 | if (peg$c71.test(input.charAt(peg$currPos))) { 1230 | s0 = input.charAt(peg$currPos); 1231 | peg$currPos++; 1232 | } else { 1233 | s0 = peg$FAILED; 1234 | if (peg$silentFails === 0) { peg$fail(peg$c72); } 1235 | } 1236 | 1237 | return s0; 1238 | } 1239 | 1240 | function peg$parseDIGIT() { 1241 | var s0; 1242 | 1243 | if (peg$c73.test(input.charAt(peg$currPos))) { 1244 | s0 = input.charAt(peg$currPos); 1245 | peg$currPos++; 1246 | } else { 1247 | s0 = peg$FAILED; 1248 | if (peg$silentFails === 0) { peg$fail(peg$c74); } 1249 | } 1250 | 1251 | return s0; 1252 | } 1253 | 1254 | function peg$parseHEXDIG() { 1255 | var s0; 1256 | 1257 | if (peg$c75.test(input.charAt(peg$currPos))) { 1258 | s0 = input.charAt(peg$currPos); 1259 | peg$currPos++; 1260 | } else { 1261 | s0 = peg$FAILED; 1262 | if (peg$silentFails === 0) { peg$fail(peg$c76); } 1263 | } 1264 | 1265 | return s0; 1266 | } 1267 | 1268 | function peg$parseobject() { 1269 | var s0, s1, s2, s3, s4, s5, s6, s7; 1270 | 1271 | s0 = peg$currPos; 1272 | s1 = peg$parsebeginObject(); 1273 | if (s1 !== peg$FAILED) { 1274 | s2 = peg$currPos; 1275 | s3 = peg$parsemember(); 1276 | if (s3 !== peg$FAILED) { 1277 | s4 = []; 1278 | s5 = peg$currPos; 1279 | s6 = peg$parsevalueSeparator(); 1280 | if (s6 !== peg$FAILED) { 1281 | s7 = peg$parsemember(); 1282 | if (s7 !== peg$FAILED) { 1283 | peg$reportedPos = s5; 1284 | s6 = peg$c77(s7); 1285 | s5 = s6; 1286 | } else { 1287 | peg$currPos = s5; 1288 | s5 = peg$c0; 1289 | } 1290 | } else { 1291 | peg$currPos = s5; 1292 | s5 = peg$c0; 1293 | } 1294 | while (s5 !== peg$FAILED) { 1295 | s4.push(s5); 1296 | s5 = peg$currPos; 1297 | s6 = peg$parsevalueSeparator(); 1298 | if (s6 !== peg$FAILED) { 1299 | s7 = peg$parsemember(); 1300 | if (s7 !== peg$FAILED) { 1301 | peg$reportedPos = s5; 1302 | s6 = peg$c77(s7); 1303 | s5 = s6; 1304 | } else { 1305 | peg$currPos = s5; 1306 | s5 = peg$c0; 1307 | } 1308 | } else { 1309 | peg$currPos = s5; 1310 | s5 = peg$c0; 1311 | } 1312 | } 1313 | if (s4 !== peg$FAILED) { 1314 | peg$reportedPos = s2; 1315 | s3 = peg$c78(s3, s4); 1316 | s2 = s3; 1317 | } else { 1318 | peg$currPos = s2; 1319 | s2 = peg$c0; 1320 | } 1321 | } else { 1322 | peg$currPos = s2; 1323 | s2 = peg$c0; 1324 | } 1325 | if (s2 === peg$FAILED) { 1326 | s2 = peg$c28; 1327 | } 1328 | if (s2 !== peg$FAILED) { 1329 | s3 = peg$parseendObject(); 1330 | if (s3 !== peg$FAILED) { 1331 | peg$reportedPos = s0; 1332 | s1 = peg$c79(s2); 1333 | s0 = s1; 1334 | } else { 1335 | peg$currPos = s0; 1336 | s0 = peg$c0; 1337 | } 1338 | } else { 1339 | peg$currPos = s0; 1340 | s0 = peg$c0; 1341 | } 1342 | } else { 1343 | peg$currPos = s0; 1344 | s0 = peg$c0; 1345 | } 1346 | 1347 | return s0; 1348 | } 1349 | 1350 | function peg$parsemember() { 1351 | var s0, s1, s2, s3; 1352 | 1353 | s0 = peg$currPos; 1354 | s1 = peg$parsename(); 1355 | if (s1 !== peg$FAILED) { 1356 | s2 = peg$parsews(); 1357 | if (s2 !== peg$FAILED) { 1358 | s3 = peg$parsechildDefinitionOrCall(); 1359 | if (s3 !== peg$FAILED) { 1360 | peg$reportedPos = s0; 1361 | s1 = peg$c80(s1, s3); 1362 | s0 = s1; 1363 | } else { 1364 | peg$currPos = s0; 1365 | s0 = peg$c0; 1366 | } 1367 | } else { 1368 | peg$currPos = s0; 1369 | s0 = peg$c0; 1370 | } 1371 | } else { 1372 | peg$currPos = s0; 1373 | s0 = peg$c0; 1374 | } 1375 | if (s0 === peg$FAILED) { 1376 | s0 = peg$currPos; 1377 | s1 = peg$parsenameOrUndf(); 1378 | if (s1 !== peg$FAILED) { 1379 | peg$reportedPos = s0; 1380 | s1 = peg$c81(s1); 1381 | } 1382 | s0 = s1; 1383 | } 1384 | 1385 | return s0; 1386 | } 1387 | 1388 | function peg$parsedefinition() { 1389 | var s0, s1, s2; 1390 | 1391 | peg$silentFails++; 1392 | s0 = peg$currPos; 1393 | s1 = peg$parsenameOrUndf(); 1394 | if (s1 !== peg$FAILED) { 1395 | s2 = peg$parseobject(); 1396 | if (s2 !== peg$FAILED) { 1397 | peg$reportedPos = s0; 1398 | s1 = peg$c83(s1, s2); 1399 | s0 = s1; 1400 | } else { 1401 | peg$currPos = s0; 1402 | s0 = peg$c0; 1403 | } 1404 | } else { 1405 | peg$currPos = s0; 1406 | s0 = peg$c0; 1407 | } 1408 | peg$silentFails--; 1409 | if (s0 === peg$FAILED) { 1410 | s1 = peg$FAILED; 1411 | if (peg$silentFails === 0) { peg$fail(peg$c82); } 1412 | } 1413 | 1414 | return s0; 1415 | } 1416 | 1417 | function peg$parsechildDefinition() { 1418 | var s0, s1; 1419 | 1420 | s0 = peg$currPos; 1421 | s1 = peg$parseobject(); 1422 | if (s1 !== peg$FAILED) { 1423 | peg$reportedPos = s0; 1424 | s1 = peg$c84(s1); 1425 | } 1426 | s0 = s1; 1427 | 1428 | return s0; 1429 | } 1430 | 1431 | function peg$parseparams() { 1432 | var s0, s1, s2, s3, s4, s5; 1433 | 1434 | s0 = peg$currPos; 1435 | s1 = peg$parseparam(); 1436 | if (s1 !== peg$FAILED) { 1437 | s2 = []; 1438 | s3 = peg$currPos; 1439 | s4 = peg$parsevalueSeparator(); 1440 | if (s4 !== peg$FAILED) { 1441 | s5 = peg$parseparam(); 1442 | if (s5 !== peg$FAILED) { 1443 | peg$reportedPos = s3; 1444 | s4 = peg$c77(s5); 1445 | s3 = s4; 1446 | } else { 1447 | peg$currPos = s3; 1448 | s3 = peg$c0; 1449 | } 1450 | } else { 1451 | peg$currPos = s3; 1452 | s3 = peg$c0; 1453 | } 1454 | while (s3 !== peg$FAILED) { 1455 | s2.push(s3); 1456 | s3 = peg$currPos; 1457 | s4 = peg$parsevalueSeparator(); 1458 | if (s4 !== peg$FAILED) { 1459 | s5 = peg$parseparam(); 1460 | if (s5 !== peg$FAILED) { 1461 | peg$reportedPos = s3; 1462 | s4 = peg$c77(s5); 1463 | s3 = s4; 1464 | } else { 1465 | peg$currPos = s3; 1466 | s3 = peg$c0; 1467 | } 1468 | } else { 1469 | peg$currPos = s3; 1470 | s3 = peg$c0; 1471 | } 1472 | } 1473 | if (s2 !== peg$FAILED) { 1474 | peg$reportedPos = s0; 1475 | s1 = peg$c85(s1, s2); 1476 | s0 = s1; 1477 | } else { 1478 | peg$currPos = s0; 1479 | s0 = peg$c0; 1480 | } 1481 | } else { 1482 | peg$currPos = s0; 1483 | s0 = peg$c0; 1484 | } 1485 | if (s0 === peg$FAILED) { 1486 | s0 = peg$c28; 1487 | } 1488 | 1489 | return s0; 1490 | } 1491 | 1492 | function peg$parseparam() { 1493 | var s0, s1, s2, s3; 1494 | 1495 | s0 = peg$currPos; 1496 | s1 = peg$parsename(); 1497 | if (s1 !== peg$FAILED) { 1498 | s2 = peg$parseparamNameSeparator(); 1499 | if (s2 !== peg$FAILED) { 1500 | s3 = peg$parsevalue(); 1501 | if (s3 !== peg$FAILED) { 1502 | peg$reportedPos = s0; 1503 | s1 = peg$c80(s1, s3); 1504 | s0 = s1; 1505 | } else { 1506 | peg$currPos = s0; 1507 | s0 = peg$c0; 1508 | } 1509 | } else { 1510 | peg$currPos = s0; 1511 | s0 = peg$c0; 1512 | } 1513 | } else { 1514 | peg$currPos = s0; 1515 | s0 = peg$c0; 1516 | } 1517 | 1518 | return s0; 1519 | } 1520 | 1521 | function peg$parsecall() { 1522 | var s0, s1, s2, s3, s4, s5, s6, s7; 1523 | 1524 | s0 = peg$currPos; 1525 | s1 = peg$parsews(); 1526 | if (s1 !== peg$FAILED) { 1527 | s2 = peg$parsename(); 1528 | if (s2 !== peg$FAILED) { 1529 | s3 = peg$parsews(); 1530 | if (s3 !== peg$FAILED) { 1531 | if (input.charCodeAt(peg$currPos) === 40) { 1532 | s4 = peg$c86; 1533 | peg$currPos++; 1534 | } else { 1535 | s4 = peg$FAILED; 1536 | if (peg$silentFails === 0) { peg$fail(peg$c87); } 1537 | } 1538 | if (s4 !== peg$FAILED) { 1539 | s5 = peg$parseparams(); 1540 | if (s5 !== peg$FAILED) { 1541 | if (input.charCodeAt(peg$currPos) === 41) { 1542 | s6 = peg$c88; 1543 | peg$currPos++; 1544 | } else { 1545 | s6 = peg$FAILED; 1546 | if (peg$silentFails === 0) { peg$fail(peg$c89); } 1547 | } 1548 | if (s6 !== peg$FAILED) { 1549 | s7 = peg$parseobject(); 1550 | if (s7 !== peg$FAILED) { 1551 | peg$reportedPos = s0; 1552 | s1 = peg$c90(s2, s5, s7); 1553 | s0 = s1; 1554 | } else { 1555 | peg$currPos = s0; 1556 | s0 = peg$c0; 1557 | } 1558 | } else { 1559 | peg$currPos = s0; 1560 | s0 = peg$c0; 1561 | } 1562 | } else { 1563 | peg$currPos = s0; 1564 | s0 = peg$c0; 1565 | } 1566 | } else { 1567 | peg$currPos = s0; 1568 | s0 = peg$c0; 1569 | } 1570 | } else { 1571 | peg$currPos = s0; 1572 | s0 = peg$c0; 1573 | } 1574 | } else { 1575 | peg$currPos = s0; 1576 | s0 = peg$c0; 1577 | } 1578 | } else { 1579 | peg$currPos = s0; 1580 | s0 = peg$c0; 1581 | } 1582 | 1583 | return s0; 1584 | } 1585 | 1586 | function peg$parsechildCall() { 1587 | var s0, s1, s2, s3, s4, s5; 1588 | 1589 | s0 = peg$currPos; 1590 | s1 = peg$parsews(); 1591 | if (s1 !== peg$FAILED) { 1592 | if (input.charCodeAt(peg$currPos) === 40) { 1593 | s2 = peg$c86; 1594 | peg$currPos++; 1595 | } else { 1596 | s2 = peg$FAILED; 1597 | if (peg$silentFails === 0) { peg$fail(peg$c87); } 1598 | } 1599 | if (s2 !== peg$FAILED) { 1600 | s3 = peg$parseparams(); 1601 | if (s3 !== peg$FAILED) { 1602 | if (input.charCodeAt(peg$currPos) === 41) { 1603 | s4 = peg$c88; 1604 | peg$currPos++; 1605 | } else { 1606 | s4 = peg$FAILED; 1607 | if (peg$silentFails === 0) { peg$fail(peg$c89); } 1608 | } 1609 | if (s4 !== peg$FAILED) { 1610 | s5 = peg$parseobject(); 1611 | if (s5 !== peg$FAILED) { 1612 | peg$reportedPos = s0; 1613 | s1 = peg$c91(s3, s5); 1614 | s0 = s1; 1615 | } else { 1616 | peg$currPos = s0; 1617 | s0 = peg$c0; 1618 | } 1619 | } else { 1620 | peg$currPos = s0; 1621 | s0 = peg$c0; 1622 | } 1623 | } else { 1624 | peg$currPos = s0; 1625 | s0 = peg$c0; 1626 | } 1627 | } else { 1628 | peg$currPos = s0; 1629 | s0 = peg$c0; 1630 | } 1631 | } else { 1632 | peg$currPos = s0; 1633 | s0 = peg$c0; 1634 | } 1635 | 1636 | return s0; 1637 | } 1638 | 1639 | function peg$parsequeryParam() { 1640 | var s0, s1, s2, s3; 1641 | 1642 | s0 = peg$currPos; 1643 | if (input.charCodeAt(peg$currPos) === 60) { 1644 | s1 = peg$c92; 1645 | peg$currPos++; 1646 | } else { 1647 | s1 = peg$FAILED; 1648 | if (peg$silentFails === 0) { peg$fail(peg$c93); } 1649 | } 1650 | if (s1 !== peg$FAILED) { 1651 | s2 = peg$parsename(); 1652 | if (s2 !== peg$FAILED) { 1653 | if (input.charCodeAt(peg$currPos) === 62) { 1654 | s3 = peg$c94; 1655 | peg$currPos++; 1656 | } else { 1657 | s3 = peg$FAILED; 1658 | if (peg$silentFails === 0) { peg$fail(peg$c95); } 1659 | } 1660 | if (s3 !== peg$FAILED) { 1661 | peg$reportedPos = s0; 1662 | s1 = peg$c96(s2); 1663 | s0 = s1; 1664 | } else { 1665 | peg$currPos = s0; 1666 | s0 = peg$c0; 1667 | } 1668 | } else { 1669 | peg$currPos = s0; 1670 | s0 = peg$c0; 1671 | } 1672 | } else { 1673 | peg$currPos = s0; 1674 | s0 = peg$c0; 1675 | } 1676 | 1677 | return s0; 1678 | } 1679 | 1680 | function peg$parsedefinitionOrCall() { 1681 | var s0; 1682 | 1683 | s0 = peg$parsedefinition(); 1684 | if (s0 === peg$FAILED) { 1685 | s0 = peg$parsecall(); 1686 | } 1687 | 1688 | return s0; 1689 | } 1690 | 1691 | function peg$parsechildDefinitionOrCall() { 1692 | var s0; 1693 | 1694 | s0 = peg$parsechildDefinition(); 1695 | if (s0 === peg$FAILED) { 1696 | s0 = peg$parsechildCall(); 1697 | } 1698 | 1699 | return s0; 1700 | } 1701 | 1702 | 1703 | var extend = require('extend') 1704 | 1705 | 1706 | peg$result = peg$startRuleFunction(); 1707 | 1708 | if (peg$result !== peg$FAILED && peg$currPos === input.length) { 1709 | return peg$result; 1710 | } else { 1711 | if (peg$result !== peg$FAILED && peg$currPos < input.length) { 1712 | peg$fail({ type: "end", description: "end of input" }); 1713 | } 1714 | 1715 | throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos); 1716 | } 1717 | } 1718 | 1719 | return { 1720 | SyntaxError: SyntaxError, 1721 | parse: parse 1722 | }; 1723 | })(); 1724 | -------------------------------------------------------------------------------- /lib/stringify.js: -------------------------------------------------------------------------------- 1 | var stringifyDefinition = function (definition, level, pretty) { 2 | var result = '' 3 | var indent = '' 4 | 5 | if (pretty) 6 | for (var l = 0; l < level; l++) { 7 | indent += ' ' 8 | } 9 | 10 | // type 11 | if (definition.type) 12 | result += definition.type 13 | 14 | // params 15 | if (definition.params) { 16 | result += '(' 17 | 18 | var j = 0 19 | for (var paramName in definition.params) { 20 | var paramValue = definition.params[paramName] 21 | result += paramName + ':' 22 | if (pretty) result += ' ' 23 | 24 | if (paramValue.type === 'queryParam') 25 | result += '<' + paramValue.name + '>' 26 | else if (typeof paramValue === 'string') 27 | result += '"' + paramValue.replace(/[\\]/g, '\\\\') 28 | .replace(/[\"]/g, '\\\"') 29 | .replace(/[\/]/g, '\\/') 30 | .replace(/[\b]/g, '\\b') 31 | .replace(/[\f]/g, '\\f') 32 | .replace(/[\n]/g, '\\n') 33 | .replace(/[\r]/g, '\\r') 34 | .replace(/[\t]/g, '\\t') + '"' 35 | else 36 | result += paramValue 37 | 38 | if (++j < Object.keys(definition.params).length) result += ',' + (pretty ? ' ' : '') 39 | } 40 | 41 | result += ')' 42 | } 43 | 44 | 45 | if (pretty) result += ' ' 46 | 47 | result += '{' 48 | 49 | if (pretty) result += '\n' 50 | 51 | // fields 52 | var hadFields = false 53 | for (field in definition.fields) { 54 | hadFields = true 55 | var fieldValue = definition.fields[field] 56 | 57 | result += indent 58 | 59 | if (fieldValue === true) { 60 | // simple field 61 | result += field + ',' 62 | } else { 63 | // sub object 64 | result += field + stringifyDefinition(fieldValue, level + 1, pretty) + ',' 65 | } 66 | 67 | if (pretty) result += '\n' 68 | } 69 | 70 | if (hadFields) { 71 | result = result.substring(0, result.length - (pretty ? 2 : 1)) 72 | } 73 | 74 | if (pretty) result += '\n' 75 | 76 | result += indent.substring(0, indent.length - 2) + '}' 77 | 78 | if (pretty && level === 1) result += '\n\n' 79 | 80 | return result 81 | } 82 | 83 | module.exports = function (data, pretty) { 84 | var result = '' 85 | 86 | // loop through definitions 87 | for (var i = 0; i < data.length; i++) { 88 | var definition = data[i] 89 | 90 | result += stringifyDefinition(definition, 1, pretty) 91 | } 92 | 93 | return result 94 | } 95 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graphqlite", 3 | "version": "1.3.0", 4 | "description": "An experimental implementation of Facebook's GraphQL", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "./node_modules/.bin/jest", 8 | "build": "./node_modules/.bin/pegjs grammar.pegjs lib/parser.js" 9 | }, 10 | "jest": { 11 | "scriptPreprocessor": "/node_modules/babel-jest", 12 | "testFileExtensions": [ 13 | "es6", 14 | "js" 15 | ], 16 | "moduleFileExtensions": [ 17 | "js", 18 | "json", 19 | "es6" 20 | ] 21 | }, 22 | "keywords": [ 23 | "graphql", 24 | "react" 25 | ], 26 | "repository": { 27 | "type": "git", 28 | "url": "git://github.com/madjam002/graphqlite.git" 29 | }, 30 | "author": "Jamie Greeff ", 31 | "license": "MIT", 32 | "dependencies": { 33 | "extend": "^2.0.1" 34 | }, 35 | "devDependencies": { 36 | "babel-jest": "^4.0.0", 37 | "jest-cli": "^0.4.0", 38 | "pegjs": "^0.8.0" 39 | } 40 | } 41 | --------------------------------------------------------------------------------