PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.28.0
Code Block Pro – Beautiful Syntax Highlighting v1.28.0
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / build / shiki / node_modules / jsonc-parser / lib / umd / impl / parser.js

parser.js in Code Block Pro – Beautiful Syntax Highlighting 1.28.0, at build/shiki/node_modules/jsonc-parser/lib/umd/impl/parser.js

1 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 !function(e){if("object"==typeof module&&"object"==typeof module.exports){var t=e(require,exports);void 0!==t&&(module.exports=t)}else"function"==typeof define&&define.amd&&define(["require","exports","./scanner"],e)}((function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getNodeType=t.stripComments=t.visit=t.findNodeAtOffset=t.contains=t.getNodeValue=t.getNodePath=t.findNodeAtLocation=t.parseTree=t.parse=t.getLocation=void 0;const n=e("./scanner");var r;function o(e,t,n=!1){return t>=e.offset&&t<e.offset+e.length||n&&t===e.offset+e.length}function a(e,t,o=r.DEFAULT){const a=(0,n.createScanner)(e,!1),i=[];let c=0;function s(e){return e?t=>0===c&&e(t,a.getTokenOffset(),a.getTokenLength(),a.getTokenStartLine(),a.getTokenStartCharacter()):()=>!0}function f(e){return e?t=>0===c&&e(t,a.getTokenOffset(),a.getTokenLength(),a.getTokenStartLine(),a.getTokenStartCharacter(),(()=>i.slice())):()=>!0}function l(e){return e?()=>{c>0?c++:!1===e(a.getTokenOffset(),a.getTokenLength(),a.getTokenStartLine(),a.getTokenStartCharacter(),(()=>i.slice()))&&(c=1)}:()=>!0}function u(e){return e?()=>{c>0&&c--,0===c&&e(a.getTokenOffset(),a.getTokenLength(),a.getTokenStartLine(),a.getTokenStartCharacter())}:()=>!0}const p=l(t.onObjectBegin),g=f(t.onObjectProperty),h=u(t.onObjectEnd),d=l(t.onArrayBegin),y=u(t.onArrayEnd),k=f(t.onLiteralValue),T=s(t.onSeparator),b=(O=t.onComment)?()=>0===c&&O(a.getTokenOffset(),a.getTokenLength(),a.getTokenStartLine(),a.getTokenStartCharacter()):()=>!0,A=s(t.onError);var O;const v=o&&o.disallowComments,j=o&&o.allowTrailingComma;function m(){for(;;){const e=a.scan();switch(a.getTokenError()){case 4:w(14);break;case 5:w(15);break;case 3:w(13);break;case 1:v||w(11);break;case 2:w(12);break;case 6:w(16)}switch(e){case 12:case 13:v?w(10):b();break;case 16:w(1);break;case 15:case 14:break;default:return e}}}function w(e,t=[],n=[]){if(A(e),t.length+n.length>0){let e=a.getToken();for(;17!==e;){if(-1!==t.indexOf(e)){m();break}if(-1!==n.indexOf(e))break;e=m()}}}function L(e){const t=a.getTokenValue();return e?k(t):(g(t),i.push(t)),m(),!0}return m(),17===a.getToken()?!!o.allowEmptyContent||(w(4,[],[]),!1):function e(){switch(a.getToken()){case 3:return function(){d(),m();let t=!0,n=!1;for(;4!==a.getToken()&&17!==a.getToken();){if(5===a.getToken()){if(n||w(4,[],[]),T(","),m(),4===a.getToken()&&j)break}else n&&w(6,[],[]);t?(i.push(0),t=!1):i[i.length-1]++,e()||w(4,[],[4,5]),n=!0}return y(),t||i.pop(),4!==a.getToken()?w(8,[4],[]):m(),!0}();case 1:return function(){p(),m();let t=!1;for(;2!==a.getToken()&&17!==a.getToken();){if(5===a.getToken()){if(t||w(4,[],[]),T(","),m(),2===a.getToken()&&j)break}else t&&w(6,[],[]);(10!==a.getToken()?(w(3,[],[2,5]),0):(L(!1),6===a.getToken()?(T(":"),m(),e()||w(4,[],[2,5])):w(5,[],[2,5]),i.pop(),1))||w(4,[],[2,5]),t=!0}return h(),2!==a.getToken()?w(7,[2],[]):m(),!0}();case 10:return L(!0);default:return function(){switch(a.getToken()){case 11:const e=a.getTokenValue();let t=Number(e);isNaN(t)&&(w(2),t=0),k(t);break;case 7:k(null);break;case 8:k(!0);break;case 9:k(!1);break;default:return!1}return m(),!0}()}}()?(17!==a.getToken()&&w(9,[],[]),!0):(w(4,[],[]),!1)}function i(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":return e?Array.isArray(e)?"array":"object":"null";default:return"null"}}!function(e){e.DEFAULT={allowTrailingComma:!1}}(r||(r={})),t.getLocation=function(e,t){const n=[],r=new Object;let o;const c={value:{},offset:0,length:0,type:"object",parent:void 0};let s=!1;function f(e,t,n,r){c.value=e,c.offset=t,c.length=n,c.type=r,c.colonOffset=void 0,o=c}try{a(e,{onObjectBegin:(e,a)=>{if(t<=e)throw r;o=void 0,s=t>e,n.push("")},onObjectProperty:(e,o,a)=>{if(t<o)throw r;if(f(e,o,a,"property"),n[n.length-1]=e,t<=o+a)throw r},onObjectEnd:(e,a)=>{if(t<=e)throw r;o=void 0,n.pop()},onArrayBegin:(e,a)=>{if(t<=e)throw r;o=void 0,n.push(0)},onArrayEnd:(e,a)=>{if(t<=e)throw r;o=void 0,n.pop()},onLiteralValue:(e,n,o)=>{if(t<n)throw r;if(f(e,n,o,i(e)),t<=n+o)throw r},onSeparator:(e,a,i)=>{if(t<=a)throw r;if(":"===e&&o&&"property"===o.type)o.colonOffset=a,s=!1,o=void 0;else if(","===e){const e=n[n.length-1];"number"==typeof e?n[n.length-1]=e+1:(s=!0,n[n.length-1]=""),o=void 0}}})}catch(e){if(e!==r)throw e}return{path:n,previousNode:o,isAtPropertyKey:s,matches:e=>{let t=0;for(let r=0;t<e.length&&r<n.length;r++)if(e[t]===n[r]||"*"===e[t])t++;else if("**"!==e[t])return!1;return t===e.length}}},t.parse=function(e,t=[],n=r.DEFAULT){let o=null,i=[];const c=[];function s(e){Array.isArray(i)?i.push(e):null!==o&&(i[o]=e)}return a(e,{onObjectBegin:()=>{const e={};s(e),c.push(i),i=e,o=null},onObjectProperty:e=>{o=e},onObjectEnd:()=>{i=c.pop()},onArrayBegin:()=>{const e=[];s(e),c.push(i),i=e,o=null},onArrayEnd:()=>{i=c.pop()},onLiteralValue:s,onError:(e,n,r)=>{t.push({error:e,offset:n,length:r})}},n),i[0]},t.parseTree=function(e,t=[],n=r.DEFAULT){let o={type:"array",offset:-1,length:-1,children:[],parent:void 0};function c(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function s(e){return o.children.push(e),e}a(e,{onObjectBegin:e=>{o=s({type:"object",offset:e,length:-1,parent:o,children:[]})},onObjectProperty:(e,t,n)=>{o=s({type:"property",offset:t,length:-1,parent:o,children:[]}),o.children.push({type:"string",value:e,offset:t,length:n,parent:o})},onObjectEnd:(e,t)=>{c(e+t),o.length=e+t-o.offset,o=o.parent,c(e+t)},onArrayBegin:(e,t)=>{o=s({type:"array",offset:e,length:-1,parent:o,children:[]})},onArrayEnd:(e,t)=>{o.length=e+t-o.offset,o=o.parent,c(e+t)},onLiteralValue:(e,t,n)=>{s({type:i(e),offset:t,length:n,parent:o,value:e}),c(t+n)},onSeparator:(e,t,n)=>{"property"===o.type&&(":"===e?o.colonOffset=t:","===e&&c(t))},onError:(e,n,r)=>{t.push({error:e,offset:n,length:r})}},n);const f=o.children[0];return f&&delete f.parent,f},t.findNodeAtLocation=function(e,t){if(!e)return;let n=e;for(let e of t)if("string"==typeof e){if("object"!==n.type||!Array.isArray(n.children))return;let t=!1;for(const r of n.children)if(Array.isArray(r.children)&&r.children[0].value===e&&2===r.children.length){n=r.children[1],t=!0;break}if(!t)return}else{const t=e;if("array"!==n.type||t<0||!Array.isArray(n.children)||t>=n.children.length)return;n=n.children[t]}return n},t.getNodePath=function e(t){if(!t.parent||!t.parent.children)return[];const n=e(t.parent);if("property"===t.parent.type){const e=t.parent.children[0].value;n.push(e)}else if("array"===t.parent.type){const e=t.parent.children.indexOf(t);-1!==e&&n.push(e)}return n},t.getNodeValue=function e(t){switch(t.type){case"array":return t.children.map(e);case"object":const n=Object.create(null);for(let r of t.children){const t=r.children[1];t&&(n[r.children[0].value]=e(t))}return n;case"null":case"string":case"number":case"boolean":return t.value;default:return}},t.contains=o,t.findNodeAtOffset=function e(t,n,r=!1){if(o(t,n,r)){const o=t.children;if(Array.isArray(o))for(let t=0;t<o.length&&o[t].offset<=n;t++){const a=e(o[t],n,r);if(a)return a}return t}},t.visit=a,t.stripComments=function(e,t){let r,o,a=(0,n.createScanner)(e),i=[],c=0;do{switch(o=a.getPosition(),r=a.scan(),r){case 12:case 13:case 17:c!==o&&i.push(e.substring(c,o)),void 0!==t&&i.push(a.getTokenValue().replace(/[^\r\n]/g,t)),c=a.getPosition()}}while(17!==r);return i.join("")},t.getNodeType=i}));