json-asty 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Gruntfile.js +2 -2
- package/Makefile +1 -1
- package/README.md +6 -6
- package/eslint.yaml +2 -3
- package/lib/json-asty.browser.js +2 -2
- package/lib/json-asty.node.js +2 -2
- package/package.json +19 -18
- package/src/json-asty.d.ts +1 -1
- package/src/json-asty.js +1 -1
- package/src/json-asty.pegjs +5 -3
- package/tst/json-asty.js +1 -1
package/Gruntfile.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
** JSON-ASTy -- Lossless JSON-to-AST Parser and AST-to-JSON Generator
|
|
3
|
-
** Copyright (c) 2018-
|
|
3
|
+
** Copyright (c) 2018-2023 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
4
|
**
|
|
5
5
|
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
** a copy of this software and associated documentation files (the
|
|
@@ -32,7 +32,7 @@ module.exports = function (grunt) {
|
|
|
32
32
|
grunt.initConfig({
|
|
33
33
|
eslint: {
|
|
34
34
|
options: {
|
|
35
|
-
|
|
35
|
+
overrideConfigFile: "eslint.yaml"
|
|
36
36
|
},
|
|
37
37
|
"json-asty": [ "src/**/*.js", "tst/**/*.js" ]
|
|
38
38
|
},
|
package/Makefile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
2
|
## JSON-ASTy -- Lossless JSON-to-AST Parser and AST-to-JSON Generator
|
|
3
|
-
## Copyright (c) 2018-
|
|
3
|
+
## Copyright (c) 2018-2023 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
4
|
##
|
|
5
5
|
## Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
## a copy of this software and associated documentation files (the
|
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@ JSON-ASTy
|
|
|
4
4
|
|
|
5
5
|
Lossless JSON-to-AST Parser and AST-to-JSON Generator
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
[](https://github.com/rse)
|
|
8
|
+
[](https://github.com/rse)
|
|
9
|
+
<br/>
|
|
10
|
+
[](https://npmjs.com/json-asty)
|
|
11
|
+
[](https://npmjs.com/json-asty)
|
|
12
12
|
|
|
13
13
|
About
|
|
14
14
|
-----
|
|
@@ -137,7 +137,7 @@ JSON (new):
|
|
|
137
137
|
License
|
|
138
138
|
-------
|
|
139
139
|
|
|
140
|
-
Copyright
|
|
140
|
+
Copyright © 2018-2023 Dr. Ralf S. Engelschall (http://engelschall.com/)
|
|
141
141
|
|
|
142
142
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
143
143
|
a copy of this software and associated documentation files (the
|
package/eslint.yaml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
##
|
|
2
2
|
## JSON-ASTy -- Lossless JSON-to-AST Parser and AST-to-JSON Generator
|
|
3
|
-
## Copyright (c) 2018-
|
|
3
|
+
## Copyright (c) 2018-2023 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
4
|
##
|
|
5
5
|
## Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
## a copy of this software and associated documentation files (the
|
|
@@ -34,8 +34,6 @@ parserOptions:
|
|
|
34
34
|
ecmaFeatures:
|
|
35
35
|
jsx: false
|
|
36
36
|
|
|
37
|
-
parser: babel-eslint
|
|
38
|
-
|
|
39
37
|
env:
|
|
40
38
|
browser: true
|
|
41
39
|
node: true
|
|
@@ -64,4 +62,5 @@ rules:
|
|
|
64
62
|
curly: off
|
|
65
63
|
space-in-parens: off
|
|
66
64
|
node/no-path-concat: off
|
|
65
|
+
n/no-path-concat: off
|
|
67
66
|
|
package/lib/json-asty.browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
** JSON-ASTy -- Lossless JSON-to-AST Parser and AST-to-JSON Generator
|
|
3
|
-
** Copyright (c) 2018-
|
|
3
|
+
** Copyright (c) 2018-2023 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
4
|
**
|
|
5
5
|
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
** a copy of this software and associated documentation files (the
|
|
@@ -49,6 +49,6 @@ const conversions=_dereq_("./conversions");function buildGraph(){const n={},e=Ob
|
|
|
49
49
|
},{}],11:[function(_dereq_,module,exports){
|
|
50
50
|
"use strict";module.exports={stdout:!1,stderr:!1};
|
|
51
51
|
},{}],12:[function(_dereq_,module,exports){
|
|
52
|
-
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}var ASTY=_dereq_("asty-astq"),PEGUtil=_dereq_("pegjs-util"),chalk=_dereq_("chalk"),PEGparser=function(){function e(r,t,n,a){this.message=r,this.expected=t,this.found=n,this.location=a,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,e)}return function(e,r){function t(){this.constructor=e}t.prototype=r.prototype,e.prototype=new t}(e,Error),e.buildMessage=function(e,r){var t={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var r,t="";for(r=0;r<e.parts.length;r++)t+=e.parts[r]instanceof Array?o(e.parts[r][0])+"-"+o(e.parts[r][1]):o(e.parts[r]);return"["+(e.inverted?"^":"")+t+"]"},any:function(e){return"any character"},end:function(e){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}function o(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}return"Expected "+function(e){var r,n,a,o=new Array(e.length);for(r=0;r<e.length;r++)o[r]=(a=e[r],t[a.type](a));if(o.sort(),o.length>0){for(r=1,n=1;r<o.length;r++)o[r-1]!==o[r]&&(o[n]=o[r],n++);o.length=n}switch(o.length){case 1:return o[0];case 2:return o[0]+" or "+o[1];default:return o.slice(0,-1).join(", ")+", or "+o[o.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(r)+" found."},{SyntaxError:e,parse:function(r,t){t=void 0!==t?t:{};var n,a={},o={json:0},u=0,l=[function(e,r,t){return e&&r.set("prolog",e+(r.get("prolog")||"")),t&&r.set("epilog",(r.get("epilog")||"")+t),r},"{",$("{",!1),",",$(",",!1),function(e,r,t){return t.reduce((e,r)=>(e[e.length-1].set({epilog:r[0]}),e.concat([r[1]])),[r])},"}",$("}",!1),function(e,r,t){return E("object").set({prolog:e}).set({epilog:t}).add(r)},":",$(":",!1),function(e,r,t){return E("member").add(e.set({epilog:r}),t)},"[",$("[",!1),"]",$("]",!1),function(e,r,t){return E("array").set({prolog:e}).set({epilog:t}).add(r)},y("number literal value"),"-",$("-",!1),"0",$("0",!1),/^[1-9]/,d([["1","9"]],!1,!1),/^[0-9]/,d([["0","9"]],!1,!1),".",$(".",!1),/^[eE]/,d(["e","E"],!1,!1),"+",$("+",!1),function(e,r,t){return E("number").set({body:b(),value:parseFloat(b())})},y("quoted string literal value"),'"',$('"',!1),/^[^\0-\x1F"\\]/,d([["\0",""],'"',"\\"],!0,!1),"\\",$("\\",!1),"/",$("/",!1),"b",$("b",!1),function(){return"\b"},"f",$("f",!1),function(){return"\f"},"n",$("n",!1),function(){return"\n"},"r",$("r",!1),function(){return"\r"},"t",$("t",!1),function(){return"\t"},"u",$("u",!1),/^[0-9a-f]/i,d([["0","9"],["a","f"]],!1,!0),function(e){return String.fromCharCode(parseInt(e,16))},function(e){return e},function(e){return E("string").set({body:b(),value:e.join("")})},y("object null literal value"),"null",$("null",!1),function(){return E("null").set({body:b(),value:null})},y("boolean false literal value"),"false",$("false",!1),function(){return E("boolean").set({body:b(),value:!1})},y("boolean true literal value"),"true",$("true",!1),function(){return E("boolean").set({body:b(),value:!0})},y("whitespace"),/^[ \t\n\r]/,d([" ","\t","\n","\r"],!1,!1),y("end of file"),{type:"any"}],s=[x('%;*." &"/J#;!/A$;*." &"/3$;+/*$8$: $##"!)($\'#(#\'#("\'#&\'#'),x(";\".A &;$.; &;%.5 &;&./ &;'.) &;(.# &;)"),x('%%%;*." &"/@#2!""6!7"/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/ġ#%;#/Æ#$%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;#/#$+")("\'#&\'#0i*%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;#/#$+")("\'#&\'#&/*$8":%"##! )("\'#&\'#." &"/f$%%;*." &"/@#2&""6&7\'/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/*$8#:(##"! )(#\'#("\'#&\'#'),x('%;&/o#%%;*." &"/@#2)""6)7*/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/3$;!/*$8#:+##"! )(#\'#("\'#&\'#'),x('%%%;*." &"/@#2,""6,7-/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/ġ#%;!/Æ#$%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;!/#$+")("\'#&\'#0i*%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;!/#$+")("\'#&\'#&/*$8":%"##! )("\'#&\'#." &"/f$%%;*." &"/@#2.""6.7//1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/*$8#:0##"! )(#\'#("\'#&\'#'),x('<%22""6273." &"/ċ#24""6475.O &%46""5!77/?#$48""5!790)*48""5!79&/#$+")("\'#&\'#/Ê$%2:""6:7;/E#$48""5!79/,#0)*48""5!79&&&#/#$+")("\'#&\'#." &"/$%4<""5!7=/e#22""6273.) &2>""6>7?." &"/E$$48""5!79/,#0)*48""5!79&&&#/#$+#)(#\'#("\'#&\'#." &"/*$8$:@$#"! )($\'#(#\'#("\'#&\'#=." 71'),x('<%2B""6B7C/ʍ#$4D""5!7E.ĺ &%2F""6F7G/Ī#2B""6B7C.Đ &2F""6F7G.Ą &2H""6H7I.ø &%2J""6J7K/& 8!:L! ).á &%2M""6M7N/& 8!:O! ).Ê &%2P""6P7Q/& 8!:R! ).³ &%2S""6S7T/& 8!:U! ). &%2V""6V7W/& 8!:X! ).
&%2Y""6Y7Z/u#%%4[""5!7\\/P#4[""5!7\\/A$4[""5!7\\/2$4[""5!7\\/#$+$)($\'#(#\'#("\'#&\'#/"!&,)/($8":]"! )("\'#&\'#/($8":^"! )("\'#&\'#0ņ*4D""5!7E.ĺ &%2F""6F7G/Ī#2B""6B7C.Đ &2F""6F7G.Ą &2H""6H7I.ø &%2J""6J7K/& 8!:L! ).á &%2M""6M7N/& 8!:O! ).Ê &%2P""6P7Q/& 8!:R! ).³ &%2S""6S7T/& 8!:U! ). &%2V""6V7W/& 8!:X! ).
&%2Y""6Y7Z/u#%%4[""5!7\\/P#4[""5!7\\/A$4[""5!7\\/2$4[""5!7\\/#$+$)($\'#(#\'#("\'#&\'#/"!&,)/($8":]"! )("\'#&\'#/($8":^"! )("\'#&\'#&/7$2B""6B7C/($8#:_#!!)(#\'#("\'#&\'#=." 7A'),x('<%2a""6a7b/& 8!:c! )=." 7`'),x('<%2e""6e7f/& 8!:g! )=." 7d'),x('<%2i""6i7j/& 8!:k! )=." 7h'),x('<$4m""5!7n/,#0)*4m""5!7n&&&#=." 7l'),x('<%<1""5!7p=.##&&!&\'#=." 7o')],c=0,i=0,p=[{line:1,column:1}],f=0,h=[],g=0;if("startRule"in t){if(!(t.startRule in o))throw new Error("Can't start parsing from rule \""+t.startRule+'".');u=o[t.startRule]}function b(){return r.substring(i,c)}function $(e,r){return{type:"literal",text:e,ignoreCase:r}}function d(e,r,t){return{type:"class",parts:e,inverted:r,ignoreCase:t}}function y(e){return{type:"other",description:e}}function k(e){var t,n=p[e];if(n)return n;for(t=e-1;!p[t];)t--;for(n={line:(n=p[t]).line,column:n.column};t<e;)10===r.charCodeAt(t)?(n.line++,n.column=1):n.column++,t++;return p[e]=n,n}function v(e,r){var t=k(e),n=k(r);return{start:{offset:e,line:t.line,column:t.column},end:{offset:r,line:n.line,column:n.column}}}function m(e){c<f||(c>f&&(f=c,h=[]),h.push(e))}function w(r,t,n){return new e(e.buildMessage(r,t),r,t,n)}function x(e){var r,t=new Array(e.length);for(r=0;r<e.length;r++)t[r]=e.charCodeAt(r)-32;return t}var E=t.util.makeAST(function(){return v(i,c)},t);if((n=function e(t){for(var n,o,u=s[t],p=0,f=[],h=u.length,b=[],$=[];;){for(;p<h;)switch(u[p]){case 0:$.push(l[u[p+1]]),p+=2;break;case 1:$.push(void 0),p++;break;case 2:$.push(null),p++;break;case 3:$.push(a),p++;break;case 4:$.push([]),p++;break;case 5:$.push(c),p++;break;case 6:$.pop(),p++;break;case 7:c=$.pop(),p++;break;case 8:$.length-=u[p+1],p+=2;break;case 9:$.splice(-2,1),p++;break;case 10:$[$.length-2].push($.pop()),p++;break;case 11:$.push($.splice($.length-u[p+1],u[p+1])),p+=2;break;case 12:$.push(r.substring($.pop(),c)),p++;break;case 13:b.push(h),f.push(p+3+u[p+1]+u[p+2]),$[$.length-1]?(h=p+3+u[p+1],p+=3):(h=p+3+u[p+1]+u[p+2],p+=3+u[p+1]);break;case 14:b.push(h),f.push(p+3+u[p+1]+u[p+2]),$[$.length-1]===a?(h=p+3+u[p+1],p+=3):(h=p+3+u[p+1]+u[p+2],p+=3+u[p+1]);break;case 15:b.push(h),f.push(p+3+u[p+1]+u[p+2]),$[$.length-1]!==a?(h=p+3+u[p+1],p+=3):(h=p+3+u[p+1]+u[p+2],p+=3+u[p+1]);break;case 16:$[$.length-1]!==a?(b.push(h),f.push(p),h=p+2+u[p+1],p+=2):p+=2+u[p+1];break;case 17:b.push(h),f.push(p+3+u[p+1]+u[p+2]),r.length>c?(h=p+3+u[p+1],p+=3):(h=p+3+u[p+1]+u[p+2],p+=3+u[p+1]);break;case 18:b.push(h),f.push(p+4+u[p+2]+u[p+3]),r.substr(c,l[u[p+1]].length)===l[u[p+1]]?(h=p+4+u[p+2],p+=4):(h=p+4+u[p+2]+u[p+3],p+=4+u[p+2]);break;case 19:b.push(h),f.push(p+4+u[p+2]+u[p+3]),r.substr(c,l[u[p+1]].length).toLowerCase()===l[u[p+1]]?(h=p+4+u[p+2],p+=4):(h=p+4+u[p+2]+u[p+3],p+=4+u[p+2]);break;case 20:b.push(h),f.push(p+4+u[p+2]+u[p+3]),l[u[p+1]].test(r.charAt(c))?(h=p+4+u[p+2],p+=4):(h=p+4+u[p+2]+u[p+3],p+=4+u[p+2]);break;case 21:$.push(r.substr(c,u[p+1])),c+=u[p+1],p+=2;break;case 22:$.push(l[u[p+1]]),c+=l[u[p+1]].length,p+=2;break;case 23:$.push(a),0===g&&m(l[u[p+1]]),p+=2;break;case 24:i=$[$.length-1-u[p+1]],p+=2;break;case 25:i=c,p++;break;case 26:for(n=u.slice(p+4,p+4+u[p+3]),o=0;o<u[p+3];o++)n[o]=$[$.length-1-n[o]];$.splice($.length-u[p+2],u[p+2],l[u[p+1]].apply(null,n)),p+=4+u[p+3];break;case 27:$.push(e(u[p+1])),p+=2;break;case 28:g++,p++;break;case 29:g--,p++;break;default:throw new Error("Invalid opcode: "+u[p]+".")}if(!(b.length>0))break;h=b.pop(),p=f.pop()}return $[0]}(u))!==a&&c===r.length)return n;throw n!==a&&c<r.length&&m({type:"end"}),w(h,f<r.length?r.charAt(f):null,f<r.length?v(f,f+1):v(f,f))}}}(),JsonAsty=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"parse",value:function(e){if("string"!=typeof e)throw new Error("invalid JSON argument (expected type string)");var r=new ASTY,t=PEGUtil.parse(PEGparser,e,{startRule:"json",makeAST:function(e,t,n,a){return r.create.apply(r,a).pos(e,t,n)}});if(null!==t.error)throw new Error("parse: JSON parsing failure:\n"+PEGUtil.errorMessage(t.error,!0).replace(/^/gm,"ERROR: ")+"\n");return t.ast}},{key:"dump",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(r=Object.assign({},{colors:!1},r)).colors?e.dump(1/0,function(e,r){switch(e){case"tree":r=chalk.grey(r);break;case"type":r=chalk.blue(r);break;case"value":r=chalk.yellow(r);break;case"position":r=chalk.grey(r)}return r}):e.dump(1/0)}},{key:"unparse",value:function(e){if("object"!==_typeof(e))throw new Error("generate: invalid AST argument (expected type object)");var r="";return e.walk(function(e,t,n,a){if("downward"===a){var o=e.get("prolog");void 0!==o&&(r+=o);var u=e.get("body");if(void 0!==u)r+=u;else{var l=e.get("value");void 0!==l&&(r+=JSON.stringify(l))}}else if("upward"===a){var s=e.get("epilog");void 0!==s&&(r+=s)}},"both"),r}}]),e}();module.exports=JsonAsty;
|
|
52
|
+
"use strict";function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_toPropertyKey(n.key),n)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){var r=_toPrimitive(e,"string");return"symbol"===_typeof(r)?r:String(r)}function _toPrimitive(e,r){if("object"!==_typeof(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!==_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}var ASTY=_dereq_("asty-astq"),PEGUtil=_dereq_("pegjs-util"),chalk=_dereq_("chalk"),PEGparser=function(){function e(r,t,n,o){this.message=r,this.expected=t,this.found=n,this.location=o,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,e)}return function(e,r){function t(){this.constructor=e}t.prototype=r.prototype,e.prototype=new t}(e,Error),e.buildMessage=function(e,r){var t={literal:function(e){return'"'+o(e.text)+'"'},class:function(e){var r,t="";for(r=0;r<e.parts.length;r++)t+=e.parts[r]instanceof Array?a(e.parts[r][0])+"-"+a(e.parts[r][1]):a(e.parts[r]);return"["+(e.inverted?"^":"")+t+"]"},any:function(e){return"any character"},end:function(e){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function o(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}function a(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}return"Expected "+function(e){var r,n,o,a=new Array(e.length);for(r=0;r<e.length;r++)a[r]=(o=e[r],t[o.type](o));if(a.sort(),a.length>0){for(r=1,n=1;r<a.length;r++)a[r-1]!==a[r]&&(a[n]=a[r],n++);a.length=n}switch(a.length){case 1:return a[0];case 2:return a[0]+" or "+a[1];default:return a.slice(0,-1).join(", ")+", or "+a[a.length-1]}}(e)+" but "+function(e){return e?'"'+o(e)+'"':"end of input"}(r)+" found."},{SyntaxError:e,parse:function(r,t){t=void 0!==t?t:{};var n,o={},a={json:0},u=0,i=[function(e,r,t){return e&&r.set("prolog",e+(r.get("prolog")||"")),t&&r.set("epilog",(r.get("epilog")||"")+t),r},"{",$("{",!1),",",$(",",!1),function(e,r,t){return t.reduce((e,r)=>{const t=e[e.length-1].get("epilog")||"";return e[e.length-1].set({epilog:t+r[0]}),e.concat([r[1]])},[r])},"}",$("}",!1),function(e,r,t){return S("object").set({prolog:e}).set({epilog:t}).add(r)},":",$(":",!1),function(e,r,t){return S("member").add(e.set({epilog:r}),t)},"[",$("[",!1),"]",$("]",!1),function(e,r,t){return S("array").set({prolog:e}).set({epilog:t}).add(r)},d("number literal value"),"-",$("-",!1),"0",$("0",!1),/^[1-9]/,y([["1","9"]],!1,!1),/^[0-9]/,y([["0","9"]],!1,!1),".",$(".",!1),/^[eE]/,y(["e","E"],!1,!1),"+",$("+",!1),function(e,r,t){return S("number").set({body:b(),value:parseFloat(b())})},d("quoted string literal value"),'"',$('"',!1),/^[^\0-\x1F"\\]/,y([["\0",""],'"',"\\"],!0,!1),"\\",$("\\",!1),"/",$("/",!1),"b",$("b",!1),function(){return"\b"},"f",$("f",!1),function(){return"\f"},"n",$("n",!1),function(){return"\n"},"r",$("r",!1),function(){return"\r"},"t",$("t",!1),function(){return"\t"},"u",$("u",!1),/^[0-9a-f]/i,y([["0","9"],["a","f"]],!1,!0),function(e){return String.fromCharCode(parseInt(e,16))},function(e){return e},function(e){return S("string").set({body:b(),value:e.join("")})},d("object null literal value"),"null",$("null",!1),function(){return S("null").set({body:b(),value:null})},d("boolean false literal value"),"false",$("false",!1),function(){return S("boolean").set({body:b(),value:!1})},d("boolean true literal value"),"true",$("true",!1),function(){return S("boolean").set({body:b(),value:!0})},d("whitespace"),/^[ \t\n\r]/,y([" ","\t","\n","\r"],!1,!1),d("end of file"),{type:"any"}],l=[x('%;*." &"/J#;!/A$;*." &"/3$;+/*$8$: $##"!)($\'#(#\'#("\'#&\'#'),x(";\".A &;$.; &;%.5 &;&./ &;'.) &;(.# &;)"),x('%%%;*." &"/@#2!""6!7"/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/ġ#%;#/Æ#$%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;#/#$+")("\'#&\'#0i*%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;#/#$+")("\'#&\'#&/*$8":%"##! )("\'#&\'#." &"/f$%%;*." &"/@#2&""6&7\'/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/*$8#:(##"! )(#\'#("\'#&\'#'),x('%;&/o#%%;*." &"/@#2)""6)7*/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/3$;!/*$8#:+##"! )(#\'#("\'#&\'#'),x('%%%;*." &"/@#2,""6,7-/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/ġ#%;!/Æ#$%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;!/#$+")("\'#&\'#0i*%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;!/#$+")("\'#&\'#&/*$8":%"##! )("\'#&\'#." &"/f$%%;*." &"/@#2.""6.7//1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/*$8#:0##"! )(#\'#("\'#&\'#'),x('<%22""6273." &"/ċ#24""6475.O &%46""5!77/?#$48""5!790)*48""5!79&/#$+")("\'#&\'#/Ê$%2:""6:7;/E#$48""5!79/,#0)*48""5!79&&&#/#$+")("\'#&\'#." &"/$%4<""5!7=/e#22""6273.) &2>""6>7?." &"/E$$48""5!79/,#0)*48""5!79&&&#/#$+#)(#\'#("\'#&\'#." &"/*$8$:@$#"! )($\'#(#\'#("\'#&\'#=." 71'),x('<%2B""6B7C/ʍ#$4D""5!7E.ĺ &%2F""6F7G/Ī#2B""6B7C.Đ &2F""6F7G.Ą &2H""6H7I.ø &%2J""6J7K/& 8!:L! ).á &%2M""6M7N/& 8!:O! ).Ê &%2P""6P7Q/& 8!:R! ).³ &%2S""6S7T/& 8!:U! ). &%2V""6V7W/& 8!:X! ).
&%2Y""6Y7Z/u#%%4[""5!7\\/P#4[""5!7\\/A$4[""5!7\\/2$4[""5!7\\/#$+$)($\'#(#\'#("\'#&\'#/"!&,)/($8":]"! )("\'#&\'#/($8":^"! )("\'#&\'#0ņ*4D""5!7E.ĺ &%2F""6F7G/Ī#2B""6B7C.Đ &2F""6F7G.Ą &2H""6H7I.ø &%2J""6J7K/& 8!:L! ).á &%2M""6M7N/& 8!:O! ).Ê &%2P""6P7Q/& 8!:R! ).³ &%2S""6S7T/& 8!:U! ). &%2V""6V7W/& 8!:X! ).
&%2Y""6Y7Z/u#%%4[""5!7\\/P#4[""5!7\\/A$4[""5!7\\/2$4[""5!7\\/#$+$)($\'#(#\'#("\'#&\'#/"!&,)/($8":]"! )("\'#&\'#/($8":^"! )("\'#&\'#&/7$2B""6B7C/($8#:_#!!)(#\'#("\'#&\'#=." 7A'),x('<%2a""6a7b/& 8!:c! )=." 7`'),x('<%2e""6e7f/& 8!:g! )=." 7d'),x('<%2i""6i7j/& 8!:k! )=." 7h'),x('<$4m""5!7n/,#0)*4m""5!7n&&&#=." 7l'),x('<%<1""5!7p=.##&&!&\'#=." 7o')],s=0,c=0,p=[{line:1,column:1}],f=0,g=[],h=0;if("startRule"in t){if(!(t.startRule in a))throw new Error("Can't start parsing from rule \""+t.startRule+'".');u=a[t.startRule]}function b(){return r.substring(c,s)}function $(e,r){return{type:"literal",text:e,ignoreCase:r}}function y(e,r,t){return{type:"class",parts:e,inverted:r,ignoreCase:t}}function d(e){return{type:"other",description:e}}function v(e){var t,n=p[e];if(n)return n;for(t=e-1;!p[t];)t--;for(n={line:(n=p[t]).line,column:n.column};t<e;)10===r.charCodeAt(t)?(n.line++,n.column=1):n.column++,t++;return p[e]=n,n}function k(e,r){var t=v(e),n=v(r);return{start:{offset:e,line:t.line,column:t.column},end:{offset:r,line:n.line,column:n.column}}}function m(e){s<f||(s>f&&(f=s,g=[]),g.push(e))}function w(r,t,n){return new e(e.buildMessage(r,t),r,t,n)}function x(e){var r,t=new Array(e.length);for(r=0;r<e.length;r++)t[r]=e.charCodeAt(r)-32;return t}var S=t.util.makeAST(function(){return k(c,s)},t);if((n=function e(t){for(var n,a,u=l[t],p=0,f=[],g=u.length,b=[],$=[];;){for(;p<g;)switch(u[p]){case 0:$.push(i[u[p+1]]),p+=2;break;case 1:$.push(void 0),p++;break;case 2:$.push(null),p++;break;case 3:$.push(o),p++;break;case 4:$.push([]),p++;break;case 5:$.push(s),p++;break;case 6:$.pop(),p++;break;case 7:s=$.pop(),p++;break;case 8:$.length-=u[p+1],p+=2;break;case 9:$.splice(-2,1),p++;break;case 10:$[$.length-2].push($.pop()),p++;break;case 11:$.push($.splice($.length-u[p+1],u[p+1])),p+=2;break;case 12:$.push(r.substring($.pop(),s)),p++;break;case 13:b.push(g),f.push(p+3+u[p+1]+u[p+2]),$[$.length-1]?(g=p+3+u[p+1],p+=3):(g=p+3+u[p+1]+u[p+2],p+=3+u[p+1]);break;case 14:b.push(g),f.push(p+3+u[p+1]+u[p+2]),$[$.length-1]===o?(g=p+3+u[p+1],p+=3):(g=p+3+u[p+1]+u[p+2],p+=3+u[p+1]);break;case 15:b.push(g),f.push(p+3+u[p+1]+u[p+2]),$[$.length-1]!==o?(g=p+3+u[p+1],p+=3):(g=p+3+u[p+1]+u[p+2],p+=3+u[p+1]);break;case 16:$[$.length-1]!==o?(b.push(g),f.push(p),g=p+2+u[p+1],p+=2):p+=2+u[p+1];break;case 17:b.push(g),f.push(p+3+u[p+1]+u[p+2]),r.length>s?(g=p+3+u[p+1],p+=3):(g=p+3+u[p+1]+u[p+2],p+=3+u[p+1]);break;case 18:b.push(g),f.push(p+4+u[p+2]+u[p+3]),r.substr(s,i[u[p+1]].length)===i[u[p+1]]?(g=p+4+u[p+2],p+=4):(g=p+4+u[p+2]+u[p+3],p+=4+u[p+2]);break;case 19:b.push(g),f.push(p+4+u[p+2]+u[p+3]),r.substr(s,i[u[p+1]].length).toLowerCase()===i[u[p+1]]?(g=p+4+u[p+2],p+=4):(g=p+4+u[p+2]+u[p+3],p+=4+u[p+2]);break;case 20:b.push(g),f.push(p+4+u[p+2]+u[p+3]),i[u[p+1]].test(r.charAt(s))?(g=p+4+u[p+2],p+=4):(g=p+4+u[p+2]+u[p+3],p+=4+u[p+2]);break;case 21:$.push(r.substr(s,u[p+1])),s+=u[p+1],p+=2;break;case 22:$.push(i[u[p+1]]),s+=i[u[p+1]].length,p+=2;break;case 23:$.push(o),0===h&&m(i[u[p+1]]),p+=2;break;case 24:c=$[$.length-1-u[p+1]],p+=2;break;case 25:c=s,p++;break;case 26:for(n=u.slice(p+4,p+4+u[p+3]),a=0;a<u[p+3];a++)n[a]=$[$.length-1-n[a]];$.splice($.length-u[p+2],u[p+2],i[u[p+1]].apply(null,n)),p+=4+u[p+3];break;case 27:$.push(e(u[p+1])),p+=2;break;case 28:h++,p++;break;case 29:h--,p++;break;default:throw new Error("Invalid opcode: "+u[p]+".")}if(!(b.length>0))break;g=b.pop(),p=f.pop()}return $[0]}(u))!==o&&s===r.length)return n;throw n!==o&&s<r.length&&m({type:"end"}),w(g,f<r.length?r.charAt(f):null,f<r.length?k(f,f+1):k(f,f))}}}(),JsonAsty=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"parse",value:function(e){if("string"!=typeof e)throw new Error("invalid JSON argument (expected type string)");var r=new ASTY,t=PEGUtil.parse(PEGparser,e,{startRule:"json",makeAST:function(e,t,n,o){return r.create.apply(r,o).pos(e,t,n)}});if(null!==t.error)throw new Error("parse: JSON parsing failure:\n"+PEGUtil.errorMessage(t.error,!0).replace(/^/gm,"ERROR: ")+"\n");return t.ast}},{key:"dump",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(r=Object.assign({},{colors:!1},r)).colors?e.dump(1/0,function(e,r){switch(e){case"tree":r=chalk.grey(r);break;case"type":r=chalk.blue(r);break;case"value":r=chalk.yellow(r);break;case"position":r=chalk.grey(r)}return r}):e.dump(1/0)}},{key:"unparse",value:function(e){if("object"!==_typeof(e))throw new Error("generate: invalid AST argument (expected type object)");var r="";return e.walk(function(e,t,n,o){if("downward"===o){var a=e.get("prolog");void 0!==a&&(r+=a);var u=e.get("body");if(void 0!==u)r+=u;else{var i=e.get("value");void 0!==i&&(r+=JSON.stringify(i))}}else if("upward"===o){var l=e.get("epilog");void 0!==l&&(r+=l)}},"both"),r}}]),e}();module.exports=JsonAsty;
|
|
53
53
|
},{"asty-astq":2,"chalk":3,"pegjs-util":10}]},{},[12])(12)
|
|
54
54
|
});
|
package/lib/json-asty.node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
** JSON-ASTy -- Lossless JSON-to-AST Parser and AST-to-JSON Generator
|
|
3
|
-
** Copyright (c) 2018-
|
|
3
|
+
** Copyright (c) 2018-2023 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
4
|
**
|
|
5
5
|
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
** a copy of this software and associated documentation files (the
|
|
@@ -41,6 +41,6 @@ const conversions=_dereq_("./conversions");function buildGraph(){const n={},e=Ob
|
|
|
41
41
|
},{}],9:[function(_dereq_,module,exports){
|
|
42
42
|
"use strict";module.exports={stdout:!1,stderr:!1};
|
|
43
43
|
},{}],10:[function(_dereq_,module,exports){
|
|
44
|
-
"use strict";const ASTY=_dereq_("asty-astq"),PEGUtil=_dereq_("pegjs-util"),chalk=_dereq_("chalk"),PEGparser=function(){function e(r,t,n,a){this.message=r,this.expected=t,this.found=n,this.location=a,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,e)}return function(e,r){function t(){this.constructor=e}t.prototype=r.prototype,e.prototype=new t}(e,Error),e.buildMessage=function(e,r){var t={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var r,t="";for(r=0;r<e.parts.length;r++)t+=e.parts[r]instanceof Array?u(e.parts[r][0])+"-"+u(e.parts[r][1]):u(e.parts[r]);return"["+(e.inverted?"^":"")+t+"]"},any:function(e){return"any character"},end:function(e){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}function u(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}return"Expected "+function(e){var r,n,a,u=new Array(e.length);for(r=0;r<e.length;r++)u[r]=(a=e[r],t[a.type](a));if(u.sort(),u.length>0){for(r=1,n=1;r<u.length;r++)u[r-1]!==u[r]&&(u[n]=u[r],n++);u.length=n}switch(u.length){case 1:return u[0];case 2:return u[0]+" or "+u[1];default:return u.slice(0,-1).join(", ")+", or "+u[u.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(r)+" found."},{SyntaxError:e,parse:function(r,t){t=void 0!==t?t:{};var n,a={},u={json:0},o=0,s=[function(e,r,t){return e&&r.set("prolog",e+(r.get("prolog")||"")),t&&r.set("epilog",(r.get("epilog")||"")+t),r},"{",b("{",!1),",",b(",",!1),function(e,r,t){return t.reduce((e,r)=>(e[e.length-1].set({epilog:r[0]}),e.concat([r[1]])
|
|
44
|
+
"use strict";const ASTY=_dereq_("asty-astq"),PEGUtil=_dereq_("pegjs-util"),chalk=_dereq_("chalk"),PEGparser=function(){function e(r,t,n,a){this.message=r,this.expected=t,this.found=n,this.location=a,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,e)}return function(e,r){function t(){this.constructor=e}t.prototype=r.prototype,e.prototype=new t}(e,Error),e.buildMessage=function(e,r){var t={literal:function(e){return'"'+a(e.text)+'"'},class:function(e){var r,t="";for(r=0;r<e.parts.length;r++)t+=e.parts[r]instanceof Array?u(e.parts[r][0])+"-"+u(e.parts[r][1]):u(e.parts[r]);return"["+(e.inverted?"^":"")+t+"]"},any:function(e){return"any character"},end:function(e){return"end of input"},other:function(e){return e.description}};function n(e){return e.charCodeAt(0).toString(16).toUpperCase()}function a(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}function u(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+n(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+n(e)})}return"Expected "+function(e){var r,n,a,u=new Array(e.length);for(r=0;r<e.length;r++)u[r]=(a=e[r],t[a.type](a));if(u.sort(),u.length>0){for(r=1,n=1;r<u.length;r++)u[r-1]!==u[r]&&(u[n]=u[r],n++);u.length=n}switch(u.length){case 1:return u[0];case 2:return u[0]+" or "+u[1];default:return u.slice(0,-1).join(", ")+", or "+u[u.length-1]}}(e)+" but "+function(e){return e?'"'+a(e)+'"':"end of input"}(r)+" found."},{SyntaxError:e,parse:function(r,t){t=void 0!==t?t:{};var n,a={},u={json:0},o=0,s=[function(e,r,t){return e&&r.set("prolog",e+(r.get("prolog")||"")),t&&r.set("epilog",(r.get("epilog")||"")+t),r},"{",b("{",!1),",",b(",",!1),function(e,r,t){return t.reduce((e,r)=>{const t=e[e.length-1].get("epilog")||"";return e[e.length-1].set({epilog:t+r[0]}),e.concat([r[1]])},[r])},"}",b("}",!1),function(e,r,t){return E("object").set({prolog:e}).set({epilog:t}).add(r)},":",b(":",!1),function(e,r,t){return E("member").add(e.set({epilog:r}),t)},"[",b("[",!1),"]",b("]",!1),function(e,r,t){return E("array").set({prolog:e}).set({epilog:t}).add(r)},k("number literal value"),"-",b("-",!1),"0",b("0",!1),/^[1-9]/,d([["1","9"]],!1,!1),/^[0-9]/,d([["0","9"]],!1,!1),".",b(".",!1),/^[eE]/,d(["e","E"],!1,!1),"+",b("+",!1),function(e,r,t){return E("number").set({body:$(),value:parseFloat($())})},k("quoted string literal value"),'"',b('"',!1),/^[^\0-\x1F"\\]/,d([["\0",""],'"',"\\"],!0,!1),"\\",b("\\",!1),"/",b("/",!1),"b",b("b",!1),function(){return"\b"},"f",b("f",!1),function(){return"\f"},"n",b("n",!1),function(){return"\n"},"r",b("r",!1),function(){return"\r"},"t",b("t",!1),function(){return"\t"},"u",b("u",!1),/^[0-9a-f]/i,d([["0","9"],["a","f"]],!1,!0),function(e){return String.fromCharCode(parseInt(e,16))},function(e){return e},function(e){return E("string").set({body:$(),value:e.join("")})},k("object null literal value"),"null",b("null",!1),function(){return E("null").set({body:$(),value:null})},k("boolean false literal value"),"false",b("false",!1),function(){return E("boolean").set({body:$(),value:!1})},k("boolean true literal value"),"true",b("true",!1),function(){return E("boolean").set({body:$(),value:!0})},k("whitespace"),/^[ \t\n\r]/,d([" ","\t","\n","\r"],!1,!1),k("end of file"),{type:"any"}],l=[x('%;*." &"/J#;!/A$;*." &"/3$;+/*$8$: $##"!)($\'#(#\'#("\'#&\'#'),x(";\".A &;$.; &;%.5 &;&./ &;'.) &;(.# &;)"),x('%%%;*." &"/@#2!""6!7"/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/ġ#%;#/Æ#$%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;#/#$+")("\'#&\'#0i*%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;#/#$+")("\'#&\'#&/*$8":%"##! )("\'#&\'#." &"/f$%%;*." &"/@#2&""6&7\'/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/*$8#:(##"! )(#\'#("\'#&\'#'),x('%;&/o#%%;*." &"/@#2)""6)7*/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/3$;!/*$8#:+##"! )(#\'#("\'#&\'#'),x('%%%;*." &"/@#2,""6,7-/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/ġ#%;!/Æ#$%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;!/#$+")("\'#&\'#0i*%%%;*." &"/@#2#""6#7$/1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/,#;!/#$+")("\'#&\'#&/*$8":%"##! )("\'#&\'#." &"/f$%%;*." &"/@#2.""6.7//1$;*." &"/#$+#)(#\'#("\'#&\'#/"!&,)/*$8#:0##"! )(#\'#("\'#&\'#'),x('<%22""6273." &"/ċ#24""6475.O &%46""5!77/?#$48""5!790)*48""5!79&/#$+")("\'#&\'#/Ê$%2:""6:7;/E#$48""5!79/,#0)*48""5!79&&&#/#$+")("\'#&\'#." &"/$%4<""5!7=/e#22""6273.) &2>""6>7?." &"/E$$48""5!79/,#0)*48""5!79&&&#/#$+#)(#\'#("\'#&\'#." &"/*$8$:@$#"! )($\'#(#\'#("\'#&\'#=." 71'),x('<%2B""6B7C/ʍ#$4D""5!7E.ĺ &%2F""6F7G/Ī#2B""6B7C.Đ &2F""6F7G.Ą &2H""6H7I.ø &%2J""6J7K/& 8!:L! ).á &%2M""6M7N/& 8!:O! ).Ê &%2P""6P7Q/& 8!:R! ).³ &%2S""6S7T/& 8!:U! ). &%2V""6V7W/& 8!:X! ).
&%2Y""6Y7Z/u#%%4[""5!7\\/P#4[""5!7\\/A$4[""5!7\\/2$4[""5!7\\/#$+$)($\'#(#\'#("\'#&\'#/"!&,)/($8":]"! )("\'#&\'#/($8":^"! )("\'#&\'#0ņ*4D""5!7E.ĺ &%2F""6F7G/Ī#2B""6B7C.Đ &2F""6F7G.Ą &2H""6H7I.ø &%2J""6J7K/& 8!:L! ).á &%2M""6M7N/& 8!:O! ).Ê &%2P""6P7Q/& 8!:R! ).³ &%2S""6S7T/& 8!:U! ). &%2V""6V7W/& 8!:X! ).
&%2Y""6Y7Z/u#%%4[""5!7\\/P#4[""5!7\\/A$4[""5!7\\/2$4[""5!7\\/#$+$)($\'#(#\'#("\'#&\'#/"!&,)/($8":]"! )("\'#&\'#/($8":^"! )("\'#&\'#&/7$2B""6B7C/($8#:_#!!)(#\'#("\'#&\'#=." 7A'),x('<%2a""6a7b/& 8!:c! )=." 7`'),x('<%2e""6e7f/& 8!:g! )=." 7d'),x('<%2i""6i7j/& 8!:k! )=." 7h'),x('<$4m""5!7n/,#0)*4m""5!7n&&&#=." 7l'),x('<%<1""5!7p=.##&&!&\'#=." 7o')],c=0,i=0,p=[{line:1,column:1}],f=0,g=[],h=0;if("startRule"in t){if(!(t.startRule in u))throw new Error("Can't start parsing from rule \""+t.startRule+'".');o=u[t.startRule]}function $(){return r.substring(i,c)}function b(e,r){return{type:"literal",text:e,ignoreCase:r}}function d(e,r,t){return{type:"class",parts:e,inverted:r,ignoreCase:t}}function k(e){return{type:"other",description:e}}function y(e){var t,n=p[e];if(n)return n;for(t=e-1;!p[t];)t--;for(n={line:(n=p[t]).line,column:n.column};t<e;)10===r.charCodeAt(t)?(n.line++,n.column=1):n.column++,t++;return p[e]=n,n}function v(e,r){var t=y(e),n=y(r);return{start:{offset:e,line:t.line,column:t.column},end:{offset:r,line:n.line,column:n.column}}}function m(e){c<f||(c>f&&(f=c,g=[]),g.push(e))}function w(r,t,n){return new e(e.buildMessage(r,t),r,t,n)}function x(e){var r,t=new Array(e.length);for(r=0;r<e.length;r++)t[r]=e.charCodeAt(r)-32;return t}var E=t.util.makeAST(function(){return v(i,c)},t);if((n=function e(t){for(var n,u,o=l[t],p=0,f=[],g=o.length,$=[],b=[];;){for(;p<g;)switch(o[p]){case 0:b.push(s[o[p+1]]),p+=2;break;case 1:b.push(void 0),p++;break;case 2:b.push(null),p++;break;case 3:b.push(a),p++;break;case 4:b.push([]),p++;break;case 5:b.push(c),p++;break;case 6:b.pop(),p++;break;case 7:c=b.pop(),p++;break;case 8:b.length-=o[p+1],p+=2;break;case 9:b.splice(-2,1),p++;break;case 10:b[b.length-2].push(b.pop()),p++;break;case 11:b.push(b.splice(b.length-o[p+1],o[p+1])),p+=2;break;case 12:b.push(r.substring(b.pop(),c)),p++;break;case 13:$.push(g),f.push(p+3+o[p+1]+o[p+2]),b[b.length-1]?(g=p+3+o[p+1],p+=3):(g=p+3+o[p+1]+o[p+2],p+=3+o[p+1]);break;case 14:$.push(g),f.push(p+3+o[p+1]+o[p+2]),b[b.length-1]===a?(g=p+3+o[p+1],p+=3):(g=p+3+o[p+1]+o[p+2],p+=3+o[p+1]);break;case 15:$.push(g),f.push(p+3+o[p+1]+o[p+2]),b[b.length-1]!==a?(g=p+3+o[p+1],p+=3):(g=p+3+o[p+1]+o[p+2],p+=3+o[p+1]);break;case 16:b[b.length-1]!==a?($.push(g),f.push(p),g=p+2+o[p+1],p+=2):p+=2+o[p+1];break;case 17:$.push(g),f.push(p+3+o[p+1]+o[p+2]),r.length>c?(g=p+3+o[p+1],p+=3):(g=p+3+o[p+1]+o[p+2],p+=3+o[p+1]);break;case 18:$.push(g),f.push(p+4+o[p+2]+o[p+3]),r.substr(c,s[o[p+1]].length)===s[o[p+1]]?(g=p+4+o[p+2],p+=4):(g=p+4+o[p+2]+o[p+3],p+=4+o[p+2]);break;case 19:$.push(g),f.push(p+4+o[p+2]+o[p+3]),r.substr(c,s[o[p+1]].length).toLowerCase()===s[o[p+1]]?(g=p+4+o[p+2],p+=4):(g=p+4+o[p+2]+o[p+3],p+=4+o[p+2]);break;case 20:$.push(g),f.push(p+4+o[p+2]+o[p+3]),s[o[p+1]].test(r.charAt(c))?(g=p+4+o[p+2],p+=4):(g=p+4+o[p+2]+o[p+3],p+=4+o[p+2]);break;case 21:b.push(r.substr(c,o[p+1])),c+=o[p+1],p+=2;break;case 22:b.push(s[o[p+1]]),c+=s[o[p+1]].length,p+=2;break;case 23:b.push(a),0===h&&m(s[o[p+1]]),p+=2;break;case 24:i=b[b.length-1-o[p+1]],p+=2;break;case 25:i=c,p++;break;case 26:for(n=o.slice(p+4,p+4+o[p+3]),u=0;u<o[p+3];u++)n[u]=b[b.length-1-n[u]];b.splice(b.length-o[p+2],o[p+2],s[o[p+1]].apply(null,n)),p+=4+o[p+3];break;case 27:b.push(e(o[p+1])),p+=2;break;case 28:h++,p++;break;case 29:h--,p++;break;default:throw new Error("Invalid opcode: "+o[p]+".")}if(!($.length>0))break;g=$.pop(),p=f.pop()}return b[0]}(o))!==a&&c===r.length)return n;throw n!==a&&c<r.length&&m({type:"end"}),w(g,f<r.length?r.charAt(f):null,f<r.length?v(f,f+1):v(f,f))}}}();class JsonAsty{static parse(e){if("string"!=typeof e)throw new Error("invalid JSON argument (expected type string)");const r=new ASTY,t=PEGUtil.parse(PEGparser,e,{startRule:"json",makeAST:(e,t,n,a)=>r.create.apply(r,a).pos(e,t,n)});if(null!==t.error)throw new Error("parse: JSON parsing failure:\n"+PEGUtil.errorMessage(t.error,!0).replace(/^/gm,"ERROR: ")+"\n");return t.ast}static dump(e,r={}){let t;return t=(r=Object.assign({},{colors:!1},r)).colors?e.dump(1/0,(e,r)=>{switch(e){case"tree":r=chalk.grey(r);break;case"type":r=chalk.blue(r);break;case"value":r=chalk.yellow(r);break;case"position":r=chalk.grey(r)}return r}):e.dump(1/0)}static unparse(e){if("object"!=typeof e)throw new Error("generate: invalid AST argument (expected type object)");let r="";return e.walk((e,t,n,a)=>{if("downward"===a){const t=e.get("prolog");void 0!==t&&(r+=t);const n=e.get("body");if(void 0!==n)r+=n;else{const t=e.get("value");void 0!==t&&(r+=JSON.stringify(t))}}else if("upward"===a){const t=e.get("epilog");void 0!==t&&(r+=t)}},"both"),r}}module.exports=JsonAsty;
|
|
45
45
|
},{"asty-astq":"asty-astq","chalk":2,"pegjs-util":"pegjs-util"}]},{},[10])(10)
|
|
46
46
|
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-asty",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Lossless JSON-to-AST Parser and AST-to-JSON Generator",
|
|
5
5
|
"keywords": [ "json", "ast", "parse", "generate" ],
|
|
6
6
|
"browser": "./lib/json-asty.browser.js",
|
|
7
7
|
"main": "./lib/json-asty.node.js",
|
|
8
|
+
"types": "./src/json-asty.d.ts",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
10
11
|
"url": "https://github.com/rse/json-asty.git"
|
|
@@ -18,37 +19,37 @@
|
|
|
18
19
|
"homepage": "https://github.com/rse/json-asty",
|
|
19
20
|
"bugs": "https://github.com/rse/json-asty/issues",
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"asty-astq": "1.13.
|
|
22
|
-
"pegjs-otf": "1.2.
|
|
22
|
+
"asty-astq": "1.13.7",
|
|
23
|
+
"pegjs-otf": "1.2.20",
|
|
23
24
|
"pegjs-util": "1.4.21",
|
|
24
|
-
"chalk": "4.1.
|
|
25
|
+
"chalk": "4.1.2"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"grunt": "1.
|
|
28
|
-
"grunt-cli": "1.3
|
|
29
|
-
"grunt-contrib-clean": "2.0.
|
|
28
|
+
"grunt": "1.6.1",
|
|
29
|
+
"grunt-cli": "1.4.3",
|
|
30
|
+
"grunt-contrib-clean": "2.0.1",
|
|
30
31
|
"grunt-contrib-watch": "1.1.0",
|
|
31
|
-
"grunt-eslint": "
|
|
32
|
+
"grunt-eslint": "24.3.0",
|
|
32
33
|
"grunt-browserify": "6.0.0",
|
|
33
34
|
"grunt-mocha-test": "0.13.3",
|
|
34
35
|
"browserify": "17.0.0",
|
|
35
36
|
"envify": "4.1.0",
|
|
36
37
|
"babelify": "10.0.0",
|
|
37
|
-
"babel-eslint": "10.1.0",
|
|
38
38
|
"uglifyify": "5.0.2",
|
|
39
39
|
"browserify-header": "1.1.0",
|
|
40
40
|
"browserify-derequire": "1.1.1",
|
|
41
|
-
"eslint": "
|
|
42
|
-
"eslint-config-standard": "
|
|
43
|
-
"eslint-plugin-promise": "
|
|
44
|
-
"eslint-plugin-import": "2.
|
|
41
|
+
"eslint": "8.50.0",
|
|
42
|
+
"eslint-config-standard": "17.1.0",
|
|
43
|
+
"eslint-plugin-promise": "6.1.1",
|
|
44
|
+
"eslint-plugin-import": "2.28.1",
|
|
45
45
|
"eslint-plugin-node": "11.1.0",
|
|
46
|
-
"@babel/core": "7.
|
|
47
|
-
"@babel/preset-env": "7.
|
|
48
|
-
"@babel/plugin-transform-runtime": "7.
|
|
49
|
-
"mocha": "
|
|
50
|
-
"chai": "4.3.
|
|
46
|
+
"@babel/core": "7.23.0",
|
|
47
|
+
"@babel/preset-env": "7.22.20",
|
|
48
|
+
"@babel/plugin-transform-runtime": "7.22.15",
|
|
49
|
+
"mocha": "10.2.0",
|
|
50
|
+
"chai": "4.3.10"
|
|
51
51
|
},
|
|
52
|
+
"upd": [ "!chalk" ],
|
|
52
53
|
"scripts": {
|
|
53
54
|
"prepublishOnly": "grunt default",
|
|
54
55
|
"build": "grunt default"
|
package/src/json-asty.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
** JSON-ASTy -- Lossless JSON-to-AST Parser and AST-to-JSON Generator
|
|
3
|
-
** Copyright (c) 2018-
|
|
3
|
+
** Copyright (c) 2018-2023 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
4
|
**
|
|
5
5
|
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
** a copy of this software and associated documentation files (the
|
package/src/json-asty.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
** JSON-ASTy -- Lossless JSON-to-AST Parser and AST-to-JSON Generator
|
|
3
|
-
** Copyright (c) 2018-
|
|
3
|
+
** Copyright (c) 2018-2023 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
4
|
**
|
|
5
5
|
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
** a copy of this software and associated documentation files (the
|
package/src/json-asty.pegjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
** JSON-ASTy -- Lossless JSON-to-AST Parser and AST-to-JSON Generator
|
|
3
|
-
** Copyright (c) 2018-
|
|
3
|
+
** Copyright (c) 2018-2023 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
4
|
**
|
|
5
5
|
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
** a copy of this software and associated documentation files (the
|
|
@@ -54,7 +54,8 @@ valueObject
|
|
|
54
54
|
member
|
|
55
55
|
)* {
|
|
56
56
|
return tail.reduce((memo, curr) => {
|
|
57
|
-
memo[memo.length - 1].
|
|
57
|
+
const epilog = memo[memo.length - 1].get("epilog") || ""
|
|
58
|
+
memo[memo.length - 1].set({ epilog: epilog + curr[0] })
|
|
58
59
|
return memo.concat([ curr[1] ])
|
|
59
60
|
}, [ head ])
|
|
60
61
|
}
|
|
@@ -83,7 +84,8 @@ valueArray
|
|
|
83
84
|
value /* RECURSION */
|
|
84
85
|
)* {
|
|
85
86
|
return tail.reduce((memo, curr) => {
|
|
86
|
-
memo[memo.length - 1].
|
|
87
|
+
const epilog = memo[memo.length - 1].get("epilog") || ""
|
|
88
|
+
memo[memo.length - 1].set({ epilog: epilog + curr[0] })
|
|
87
89
|
return memo.concat([ curr[1] ])
|
|
88
90
|
}, [ head ])
|
|
89
91
|
}
|
package/tst/json-asty.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
** JSON-ASTy -- Lossless JSON-to-AST Parser and AST-to-JSON Generator
|
|
3
|
-
** Copyright (c) 2018-
|
|
3
|
+
** Copyright (c) 2018-2023 Dr. Ralf S. Engelschall <rse@engelschall.com>
|
|
4
4
|
**
|
|
5
5
|
** Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
** a copy of this software and associated documentation files (the
|