Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

modl-interpreter

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modl-interpreter - npm Package Compare versions

Comparing version 0.0.16 to 0.0.17

2

dist/bundle.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MODLInterpreter=t():e.MODLInterpreter=t()}(self,(function(){return(()=>{"use strict";var e={235:function(e,t,n){var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0}),t.ParserException=t.parseModl=void 0;var i=n(957),s=n(62),l=n(666);t.parseModl=function(e){var t=s.tokeniser(e),n=u(new l.TokenStream(t));return new i.Modl(n)};var a=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(Error);t.ParserException=a;var u=function(e){var t=p(e);return null!==t?t:c(e)},p=function(e){var t=null,n=e.next();switch(n.type){case s.TokenType.LPAREN:case s.TokenType.RPAREN:case s.TokenType.LBRACKET:case s.TokenType.RBRACKET:case s.TokenType.EQUALS:if(e.empty())throw new a("Unexpected token: "+n.toS());return e.pushBack(n),null;case s.TokenType.NULL:t=i.ModlBoolNull.ModlNull;break;case s.TokenType.TRUE:t=i.ModlBoolNull.ModlTrue;break;case s.TokenType.FALSE:t=i.ModlBoolNull.ModlFalse;break;case s.TokenType.QUOTED:t=new i.ModlQuoted(n.value);break;case s.TokenType.STRING:t=new i.ModlString(n.value);break;case s.TokenType.INTEGER:t=new i.ModlInteger(n.value);break;case s.TokenType.FLOAT:t=new i.ModlFloat(n.value);break;default:throw new a("Unknown token type in: "+n.toS())}if(null!==t){var o=e.peek();if(o&&o.type===s.TokenType.STRUCT_SEP)throw new a("Only one primitive is allowed at the root.");if(o&&(o.type===s.TokenType.LPAREN||o.type===s.TokenType.LBRACKET||o.type===s.TokenType.EQUALS))return e.pushBack(n),null;if(o)throw new a("Unexpected token: "+o.toS())}return t},c=function(e){for(var t=[];!e.empty();){t.push(f(e));var n=e.next();if(n&&n.type!==s.TokenType.STRUCT_SEP)throw new a("Expected ';' near "+n.toS())}return t},d=function(e){for(var t=e.next(),n=[];!e.empty();){var o=e.peek();if(o&&o.type===s.TokenType.RPAREN){e.next();break}var r=f(e);if(n.push(r),!(o=e.peek()))throw new a("Expected ')' near "+t.toS());if(o.type===s.TokenType.RPAREN){e.next();break}if(o.type===s.TokenType.STRUCT_SEP&&(e.next(),(o=e.peek())&&o.type===s.TokenType.RPAREN))throw new a("Unexpected ; before ] at "+o)}return new i.ModlMap(n)},T=function(e){for(var t=e.next(),n=[];!e.empty();){var o=e.peek();if(o&&o.type===s.TokenType.RBRACKET){e.next();break}var r=f(e);if(n.push(r),!(o=e.peek()))throw new a("Expected ']' near "+t.toS());if(o.type===s.TokenType.RBRACKET){e.next();break}if(o.type===s.TokenType.STRUCT_SEP&&(e.next(),(o=e.peek())&&o.type===s.TokenType.RBRACKET))throw new a("Unexpected ; before ] at "+o)}return new i.ModlArray(n)},f=function(e){var t=e.next();if(t.type===s.TokenType.LBRACKET)return e.pushBack(t),T(e);if(t.type===s.TokenType.LPAREN)return e.pushBack(t),d(e);if(t.type===s.TokenType.STRING||t.type===s.TokenType.QUOTED){var n=e.peek(),o=t.value;if(n&&n.type===s.TokenType.EQUALS)return e.next(),new i.ModlPair(o,y(e));if(n&&(n.type===s.TokenType.LBRACKET||n.type===s.TokenType.LPAREN))return new i.ModlPair(o,y(e));if(!n||n&&(n.type===s.TokenType.STRUCT_SEP||n.type===s.TokenType.RPAREN||n.type===s.TokenType.RBRACKET))return t.type===s.TokenType.STRING?new i.ModlString(t.value):new i.ModlQuoted(t.value);throw new a("Unexpected token: '"+t.toS()+"'")}if(t.type===s.TokenType.INTEGER)return new i.ModlInteger(t.value);if(t.type===s.TokenType.FLOAT)return new i.ModlFloat(t.value);if(t.type===s.TokenType.NULL)return i.ModlBoolNull.ModlNull;if(t.type===s.TokenType.TRUE)return i.ModlBoolNull.ModlTrue;if(t.type===s.TokenType.FALSE)return i.ModlBoolNull.ModlFalse;e.pushBack(t);var r=p(e);if(r)return r;throw new a("Unexpected token: '"+t.toS()+"'")},y=function(e){var t=e.next();if(t.type===s.TokenType.LBRACKET)return e.pushBack(t),T(e);if(t.type===s.TokenType.LPAREN)return e.pushBack(t),d(e);if(t.type===s.TokenType.STRING||t.type===s.TokenType.QUOTED){var n=e.peek();if(n&&n.type===s.TokenType.EQUALS)throw new a("Unexpected token: '"+t.toS()+"'");if(n&&(n.type===s.TokenType.LBRACKET||n.type===s.TokenType.LPAREN))throw new a("Unexpected token: '"+t.toS()+"'");if(!n||n&&(n.type===s.TokenType.STRUCT_SEP||n.type===s.TokenType.RPAREN||n.type===s.TokenType.RBRACKET))return t.type===s.TokenType.STRING?new i.ModlString(t.value):new i.ModlQuoted(t.value);throw new a("Unexpected token: '"+t.toS()+"'")}if(t.type===s.TokenType.INTEGER)return new i.ModlInteger(t.value);if(t.type===s.TokenType.FLOAT)return new i.ModlFloat(t.value);if(t.type===s.TokenType.NULL)return i.ModlBoolNull.ModlNull;if(t.type===s.TokenType.TRUE)return i.ModlBoolNull.ModlTrue;if(t.type===s.TokenType.FALSE)return i.ModlBoolNull.ModlFalse;e.pushBack(t);var o=p(e);if(o)return o;throw new a("Unexpected token: '"+t.toS()+"'")}},62:function(e,t){var n,o=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)});Object.defineProperty(t,"__esModule",{value:!0}),t.TokenType=t.TokeniserException=t.tokeniser=t.Token=void 0;var r=function(){function e(e,t,n,o){this.type=e,this.value=t,this.from=n,this.to=o}return e.prototype.toS=function(){return"type: "+this.type.toString()+", from: "+this.from+", to: "+this.to+', value: "'+this.value+'"'},e}();t.Token=r,t.tokeniser=function(e){return new u(e).parse()};var i=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t}(Error);t.TokeniserException=i;var s,l=new RegExp(/^-?\d+$/),a=new RegExp(/^-?([0-9]*[.])?[0-9]+([eE][-+]?\d+)?$/);!function(e){e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACKET="LBRACKET",e.RBRACKET="RBRACKET",e.STRUCT_SEP="STRUCT_SEP",e.NULL="NULL",e.TRUE="TRUE",e.FALSE="FALSE",e.EQUALS="EQUALS",e.QUOTED="QUOTED",e.STRING="STRING",e.INTEGER="INTEGER",e.FLOAT="FLOAT"}(s=t.TokenType||(t.TokenType={}));var u=function(){function e(e){this.s=e,this.tokStart=0,this.tokEnd=0,this.tokens=new Array}return e.prototype.parse=function(){for(;this.next(););return this.tokens},e.prototype.next=function(){for(var e,t=this.s.charAt(this.tokStart);""!=t&&" \t\r\n".includes(t);)this.tokStart++,t=this.s.charAt(this.tokStart);if(this.tokStart>=this.s.length)return!1;switch(this.s.charAt(this.tokStart)){case"(":e=s.LPAREN,this.tokEnd=this.tokStart+1;break;case")":e=s.RPAREN,this.tokEnd=this.tokStart+1;break;case"[":e=s.LBRACKET,this.tokEnd=this.tokStart+1;break;case"]":e=s.RBRACKET,this.tokEnd=this.tokStart+1;break;case";":e=s.STRUCT_SEP,this.tokEnd=this.tokStart+1;break;case"=":e=s.EQUALS,this.tokEnd=this.tokStart+1;break;case"`":case'"':e=s.QUOTED,this.tokEnd=this.scanToEndOfQuoted(this.s,this.tokStart,this.s.charAt(this.tokStart));break;default:e=s.STRING,this.tokEnd=this.scanToEndOfString(this.s,this.tokStart)}var n=this.s.substring(this.tokStart,this.tokEnd).trim();if(n.match(l)){var o=parseInt(n);this.tokens.push(new r(s.INTEGER,o,this.tokStart,this.tokEnd))}else n.match(a)?(o=parseFloat(n),this.tokens.push(new r(s.FLOAT,o,this.tokStart,this.tokEnd))):"null"===n?this.tokens.push(new r(s.NULL,null,this.tokStart,this.tokEnd)):"true"===n?this.tokens.push(new r(s.TRUE,!0,this.tokStart,this.tokEnd)):"false"===n?this.tokens.push(new r(s.FALSE,!1,this.tokStart,this.tokEnd)):this.tokens.push(new r(e,n,this.tokStart,this.tokEnd));return this.tokStart=this.tokEnd,this.tokEnd<this.s.length},e.prototype.scanToEndOfQuoted=function(e,t,n){for(var o=t+1;o<e.length;){var r=e.charAt(o),s=e.charAt(o-1);if(r===n&&"\\"!==s&&"~"!==s)break;o++}if(e.charAt(o)!==n)throw new i("Unclosed quote: "+n+" in "+this.s+" near "+t+":"+o);return o+1},e.prototype.scanToEndOfString=function(e,t){for(var n=t+1;n<e.length&&!'[]();"=`'.includes(e.charAt(n));)n++;return n},e}()},957:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ModlBoolNull=t.ModlString=t.ModlQuoted=t.ModlFloat=t.ModlInteger=t.ModlPair=t.ModlArray=t.ModlMap=t.Modl=void 0;t.Modl=function(e){this.s=e};t.ModlMap=function(e){this.items=e};t.ModlArray=function(e){this.items=e};t.ModlPair=function(e,t){this.key=e,this.value=t};t.ModlInteger=function(e){this.value=e};t.ModlFloat=function(e){this.value=e};t.ModlQuoted=function(e){this.value=e};var n;t.ModlString=function(e){this.value=e},(n=t.ModlBoolNull||(t.ModlBoolNull={}))[n.ModlTrue=0]="ModlTrue",n[n.ModlFalse=1]="ModlFalse",n[n.ModlNull=2]="ModlNull"},666:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TokenStream=void 0;var n=function(){function e(e){this.tokens=e}return e.prototype.next=function(){var e=void 0;return this.tokens.length>0&&(e=this.tokens.shift()),e},e.prototype.peek=function(){var e=void 0;return this.tokens.length>0&&(e=this.tokens[0]),e},e.prototype.pushBack=function(e){this.tokens.unshift(e)},e.prototype.empty=function(){return 0===this.tokens.length},e}();t.TokenStream=n},927:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.parser=t.TokeniserException=t.ParserException=t.ModlBoolNull=t.ModlString=t.ModlFloat=t.ModlInteger=t.ModlQuoted=t.ModlPair=t.ModlArray=t.ModlMap=t.Modl=void 0;var o=n(957);Object.defineProperty(t,"Modl",{enumerable:!0,get:function(){return o.Modl}}),Object.defineProperty(t,"ModlArray",{enumerable:!0,get:function(){return o.ModlArray}}),Object.defineProperty(t,"ModlBoolNull",{enumerable:!0,get:function(){return o.ModlBoolNull}}),Object.defineProperty(t,"ModlFloat",{enumerable:!0,get:function(){return o.ModlFloat}}),Object.defineProperty(t,"ModlInteger",{enumerable:!0,get:function(){return o.ModlInteger}}),Object.defineProperty(t,"ModlMap",{enumerable:!0,get:function(){return o.ModlMap}}),Object.defineProperty(t,"ModlPair",{enumerable:!0,get:function(){return o.ModlPair}}),Object.defineProperty(t,"ModlQuoted",{enumerable:!0,get:function(){return o.ModlQuoted}}),Object.defineProperty(t,"ModlString",{enumerable:!0,get:function(){return o.ModlString}});var r=n(235);Object.defineProperty(t,"ParserException",{enumerable:!0,get:function(){return r.ParserException}});var i=n(62);Object.defineProperty(t,"TokeniserException",{enumerable:!0,get:function(){return i.TokeniserException}}),t.parser=r.parseModl},143:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Interpreter=void 0;const o=n(927),r=n(861);t.Interpreter=class{interpretToJsonString(e){const t=this.interpretToJsonObject(e);return JSON.stringify(t)}interpretToPrettyJsonString(e){const t=this.interpretToJsonObject(e);return JSON.stringify(t,void 0,4)}interpretToJsonObject(e){const t=this.interpret(e);return r.modlToJson(t)}interpret(e){return o.parser(e)}}},861:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.modlToJson=void 0;const o=n(927),r=n(200);function i(e){return e instanceof o.ModlArray?u(e):e instanceof o.ModlMap?a(e,{}):e instanceof o.ModlPair?l(e,{}):e instanceof o.ModlQuoted?s.replace(p(e.value)):e instanceof o.ModlInteger||e instanceof o.ModlFloat?e.value:e instanceof o.ModlString?s.replace(p(e.value)):e!==o.ModlBoolNull.ModlFalse&&(e===o.ModlBoolNull.ModlTrue||(e===o.ModlBoolNull.ModlNull?null:e))}t.modlToJson=function(e){if(e.s instanceof Array){if(1===e.s.length&&e.s[0]instanceof o.ModlArray)return u(e.s[0]);{const t={};return e.s.forEach((e=>{if(e instanceof o.ModlPair&&l(e,t),e instanceof o.ModlMap&&a(e,t),e instanceof o.ModlArray)throw new Error("Array cannot be stored directly in a map, it must be a pair")})),0===Object.keys(t).length?null:t}}return i(e.s)};const s=r.createStringEscapeReplacer();function l(e,t){return t[s.replace(e.key instanceof o.ModlQuoted?p(e.key.value):p(e.key))]=i(e.value),t}function a(e,t){return e.items.forEach((e=>{l(e,t)})),t}function u(e){const t=new Array;return e.items.forEach((e=>t.push(i(e)))),t}function p(e){return e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):e}},200:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createStringEscapeReplacer=void 0,t.createStringEscapeReplacer=()=>new n;class n{replace(e){let t=r(e);for(let e=0;e<t.length;e++)o.forEach(((n,o)=>{t.startsWith(o,e)&&(t=t.substring(0,e)+n+t.substring(e+o.length))}));return t}}const o=new Map([["\\t","\t"],["\\n","\n"],["\\b","\b"],["\\f","\f"],["\\r","\r"],["~t","\t"],["~n","\n"],["~b","\b"],["~f","\f"],["~r","\r"],["~\\","\\"],["\\\\","\\"],["~~","~"],["\\~","~"],["~(","("],["\\(","("],["~)",")"],["\\)",")"],["~[","["],["\\[","["],["~]","]"],["\\]","]"],["~;",";"],["\\;",";"],["~`","`"],["\\`","`"],['~"','"'],['\\"','"'],["~=","="],["\\=","="]]),r=e=>{let t=0,n=e;for(;t<n.length;){const e=n.indexOf("\\u",t),o=n.indexOf("~u",t);let r;if(o<0&&e<0)break;r=o<0?e:e<0?o:Math.min(e,o);const l=u(n,r+2);if(t=r+1,!i(n,r)&&l.codePoint>0){const e=String.fromCodePoint(l.codePoint);n=s(n,e,r,l.length+2)}}return n},i=(e,t)=>t>0&&("~"===e.charAt(t-1)||"\\"===e.charAt(t-1)),s=(e,t,n,o)=>{const r=e.substring(0,n),i=Math.min(e.length,n+o);return r+t+e.substring(i)},l=e=>e>=1048576&&e<=1114111||e>=65536&&e<=1048575||e>=0&&e<=55295||e>=57344&&e<=65535,a=(e,t,n)=>{let o=0;for(;o<n&&t+o<e.length;){const n=e[t+o];if(!"0123456789".includes(n)&&"abcdefABCDEF".indexOf(n)<=-1)return!1;o++}return o===n},u=(e,t)=>{if(a(e,t,6)&&"00"!==e.substring(t,t+2)){const n=p(e,t,6);if(l(n))return new c(n,6)}if(a(e,t,5)&&"00"!==e.substring(t,t+2)){const n=p(e,t,5);if(l(n))return new c(n,5)}if(a(e,t,4)){const n=p(e,t,4);if(l(n))return new c(n,4)}return new c(0,4)},p=(e,t,n)=>Number.parseInt(e.substring(t,t+n),16);class c{constructor(e,t){this.codePoint=e,this.length=t}}}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,n),i.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.interpreter=void 0;const t=n(143);e.interpreter=new t.Interpreter})(),o})()}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MODLInterpreter=t():e.MODLInterpreter=t()}(self,(function(){return(()=>{"use strict";var e={143:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Interpreter=void 0;const o=n(403),r=n(861);t.Interpreter=class{interpretToJsonString(e){const t=this.interpretToJsonObject(e);return JSON.stringify(t)}interpretToPrettyJsonString(e){const t=this.interpretToJsonObject(e);return JSON.stringify(t,void 0,4)}interpretToJsonObject(e){const t=this.interpret(e);return r.modlToJson(t)}interpret(e){return o.parser(e)}}},861:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.modlToJson=void 0;const o=n(403),r=n(200);function i(e){return e instanceof o.ModlArray?u(e):e instanceof o.ModlMap?a(e,{}):e instanceof o.ModlPair?s(e,{}):e instanceof o.ModlQuoted?l.replace(p(e.value)):e instanceof o.ModlInteger||e instanceof o.ModlFloat?e.value:e instanceof o.ModlString?l.replace(p(e.value)):e!==o.ModlBoolNull.ModlFalse&&(e===o.ModlBoolNull.ModlTrue||(e===o.ModlBoolNull.ModlNull?null:e))}t.modlToJson=function(e){if(e.s instanceof Array){if(1===e.s.length&&e.s[0]instanceof o.ModlArray)return u(e.s[0]);{const t={};return e.s.forEach((e=>{if(e instanceof o.ModlPair&&s(e,t),e instanceof o.ModlMap&&a(e,t),e instanceof o.ModlArray)throw new Error("Array cannot be stored directly in a map, it must be a pair")})),0===Object.keys(t).length?null:t}}return i(e.s)};const l=r.createStringEscapeReplacer();function s(e,t){return t[l.replace(e.key instanceof o.ModlQuoted?p(e.key.value):p(e.key))]=i(e.value),t}function a(e,t){return e.items.forEach((e=>{s(e,t)})),t}function u(e){const t=new Array;return e.items.forEach((e=>t.push(i(e)))),t}function p(e){return e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):e}},200:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createStringEscapeReplacer=void 0,t.createStringEscapeReplacer=()=>new n;class n{replace(e){let t=r(e);for(let e=0;e<t.length;e++)o.forEach(((n,o)=>{t.startsWith(o,e)&&(t=t.substring(0,e)+n+t.substring(e+o.length))}));return t}}const o=new Map([["\\t","\t"],["\\n","\n"],["\\b","\b"],["\\f","\f"],["\\r","\r"],["~t","\t"],["~n","\n"],["~b","\b"],["~f","\f"],["~r","\r"],["~\\","\\"],["\\\\","\\"],["~~","~"],["\\~","~"],["~(","("],["\\(","("],["~)",")"],["\\)",")"],["~[","["],["\\[","["],["~]","]"],["\\]","]"],["~;",";"],["\\;",";"],["~`","`"],["\\`","`"],['~"','"'],['\\"','"'],["~=","="],["\\=","="]]),r=e=>{let t,n=0,o="";const r=/[~\\]u[0-9a-fA-F]{4}/g;do{if(t=r.exec(e),t)if(t.index>0&&("\\"===e.charAt(t.index-1)||"~"===e.charAt(t.index-1)))n<t.index-1&&(o+=e.substring(n,t.index-1)),o+=e.substring(t.index,t.index+6),n=t.index+6;else{n<t.index&&(o+=e.substring(n,t.index));const r=Number.parseInt(t[0].substr(2),16);o+=String.fromCharCode(r),n=t.index+6}else o+=e.substring(n)}while(t);return o}},637:function(e,t,n){var o,r=this&&this.__extends||(o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},o(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0}),t.ParserException=t.parseModl=void 0;var i=n(558),l=n(984),s=n(733);t.parseModl=function(e){var t=l.tokeniser(e),n=u(new s.TokenStream(t));return new i.Modl(n)};var a=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(Error);t.ParserException=a;var u=function(e){var t=p(e);return null!==t?t:c(e)},p=function(e){var t=null,n=e.next();switch(n.type){case l.TokenType.LPAREN:case l.TokenType.RPAREN:case l.TokenType.LBRACKET:case l.TokenType.RBRACKET:case l.TokenType.EQUALS:if(e.empty())throw new a("Unexpected token: "+n.toS());return e.pushBack(n),null;case l.TokenType.NULL:t=i.ModlBoolNull.ModlNull;break;case l.TokenType.TRUE:t=i.ModlBoolNull.ModlTrue;break;case l.TokenType.FALSE:t=i.ModlBoolNull.ModlFalse;break;case l.TokenType.QUOTED:t=new i.ModlQuoted(n.value);break;case l.TokenType.STRING:t=new i.ModlString(n.value);break;case l.TokenType.INTEGER:t=new i.ModlInteger(n.value);break;case l.TokenType.FLOAT:t=new i.ModlFloat(n.value);break;default:throw new a("Unknown token type in: "+n.toS())}if(null!==t){var o=e.peek();if(o&&o.type===l.TokenType.STRUCT_SEP)throw new a("Only one primitive is allowed at the root.");if(o&&(o.type===l.TokenType.LPAREN||o.type===l.TokenType.LBRACKET||o.type===l.TokenType.EQUALS))return e.pushBack(n),null;if(o)throw new a("Unexpected token: "+o.toS())}return t},c=function(e){for(var t=[];!e.empty();){t.push(f(e));var n=e.next();if(n&&n.type!==l.TokenType.STRUCT_SEP)throw new a("Expected ';' near "+n.toS())}return t},d=function(e){for(var t=e.next(),n=[];!e.empty();){var o=e.peek();if(o&&o.type===l.TokenType.RPAREN){e.next();break}var r=f(e);if(n.push(r),!(o=e.peek()))throw new a("Expected ')' near "+t.toS());if(o.type===l.TokenType.RPAREN){e.next();break}if(o.type===l.TokenType.STRUCT_SEP&&(e.next(),(o=e.peek())&&o.type===l.TokenType.RPAREN))throw new a("Unexpected ; before ] at "+o)}return new i.ModlMap(n)},T=function(e){for(var t=e.next(),n=[];!e.empty();){var o=e.peek();if(o&&o.type===l.TokenType.RBRACKET){e.next();break}var r=f(e);if(n.push(r),!(o=e.peek()))throw new a("Expected ']' near "+t.toS());if(o.type===l.TokenType.RBRACKET){e.next();break}if(o.type===l.TokenType.STRUCT_SEP&&(e.next(),(o=e.peek())&&o.type===l.TokenType.RBRACKET))throw new a("Unexpected ; before ] at "+o)}return new i.ModlArray(n)},f=function(e){var t=e.next();if(t.type===l.TokenType.LBRACKET)return e.pushBack(t),T(e);if(t.type===l.TokenType.LPAREN)return e.pushBack(t),d(e);if(t.type===l.TokenType.STRING||t.type===l.TokenType.QUOTED){var n=e.peek(),o=t.value;if(n&&n.type===l.TokenType.EQUALS)return e.next(),new i.ModlPair(o,y(e));if(n&&(n.type===l.TokenType.LBRACKET||n.type===l.TokenType.LPAREN))return new i.ModlPair(o,y(e));if(!n||n&&(n.type===l.TokenType.STRUCT_SEP||n.type===l.TokenType.RPAREN||n.type===l.TokenType.RBRACKET))return t.type===l.TokenType.STRING?new i.ModlString(t.value):new i.ModlQuoted(t.value);throw new a("Unexpected token: '"+t.toS()+"'")}if(t.type===l.TokenType.INTEGER)return new i.ModlInteger(t.value);if(t.type===l.TokenType.FLOAT)return new i.ModlFloat(t.value);if(t.type===l.TokenType.NULL)return i.ModlBoolNull.ModlNull;if(t.type===l.TokenType.TRUE)return i.ModlBoolNull.ModlTrue;if(t.type===l.TokenType.FALSE)return i.ModlBoolNull.ModlFalse;e.pushBack(t);var r=p(e);if(r)return r;throw new a("Unexpected token: '"+t.toS()+"'")},y=function(e){var t=e.next();if(t.type===l.TokenType.LBRACKET)return e.pushBack(t),T(e);if(t.type===l.TokenType.LPAREN)return e.pushBack(t),d(e);if(t.type===l.TokenType.STRING||t.type===l.TokenType.QUOTED){var n=e.peek();if(n&&n.type===l.TokenType.EQUALS)throw new a("Unexpected token: '"+t.toS()+"'");if(n&&(n.type===l.TokenType.LBRACKET||n.type===l.TokenType.LPAREN))throw new a("Unexpected token: '"+t.toS()+"'");if(!n||n&&(n.type===l.TokenType.STRUCT_SEP||n.type===l.TokenType.RPAREN||n.type===l.TokenType.RBRACKET))return t.type===l.TokenType.STRING?new i.ModlString(t.value):new i.ModlQuoted(t.value);throw new a("Unexpected token: '"+t.toS()+"'")}if(t.type===l.TokenType.INTEGER)return new i.ModlInteger(t.value);if(t.type===l.TokenType.FLOAT)return new i.ModlFloat(t.value);if(t.type===l.TokenType.NULL)return i.ModlBoolNull.ModlNull;if(t.type===l.TokenType.TRUE)return i.ModlBoolNull.ModlTrue;if(t.type===l.TokenType.FALSE)return i.ModlBoolNull.ModlFalse;e.pushBack(t);var o=p(e);if(o)return o;throw new a("Unexpected token: '"+t.toS()+"'")}},984:function(e,t){var n,o=this&&this.__extends||(n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},n(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)});Object.defineProperty(t,"__esModule",{value:!0}),t.TokenType=t.TokeniserException=t.tokeniser=t.Token=void 0;var r=function(){function e(e,t,n,o){this.type=e,this.value=t,this.from=n,this.to=o}return e.prototype.toS=function(){return"type: "+this.type.toString()+", from: "+this.from+", to: "+this.to+', value: "'+this.value+'"'},e}();t.Token=r,t.tokeniser=function(e){return new u(e).parse()};var i=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t}(Error);t.TokeniserException=i;var l,s=new RegExp(/^-?(?:0|[1-9]\d*)$/),a=new RegExp(/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/);!function(e){e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACKET="LBRACKET",e.RBRACKET="RBRACKET",e.STRUCT_SEP="STRUCT_SEP",e.NULL="NULL",e.TRUE="TRUE",e.FALSE="FALSE",e.EQUALS="EQUALS",e.QUOTED="QUOTED",e.STRING="STRING",e.INTEGER="INTEGER",e.FLOAT="FLOAT"}(l=t.TokenType||(t.TokenType={}));var u=function(){function e(e){this.s=e,this.tokStart=0,this.tokEnd=0,this.tokens=new Array}return e.prototype.parse=function(){for(;this.next(););return this.tokens},e.prototype.next=function(){for(var e,t=this.s.charAt(this.tokStart);""!=t&&" \t\r\n".includes(t);)this.tokStart++,t=this.s.charAt(this.tokStart);if(this.tokStart>=this.s.length)return!1;switch(this.s.charAt(this.tokStart)){case"(":e=l.LPAREN,this.tokEnd=this.tokStart+1;break;case")":e=l.RPAREN,this.tokEnd=this.tokStart+1;break;case"[":e=l.LBRACKET,this.tokEnd=this.tokStart+1;break;case"]":e=l.RBRACKET,this.tokEnd=this.tokStart+1;break;case";":e=l.STRUCT_SEP,this.tokEnd=this.tokStart+1;break;case"=":e=l.EQUALS,this.tokEnd=this.tokStart+1;break;case"`":case'"':e=l.QUOTED,this.tokEnd=this.scanToEndOfQuoted(this.s,this.tokStart,this.s.charAt(this.tokStart));break;default:e=l.STRING,this.tokEnd=this.scanToEndOfString(this.s,this.tokStart)}var n=this.s.substring(this.tokStart,this.tokEnd).trim();if(n.match(s)){var o=parseInt(n);this.tokens.push(new r(l.INTEGER,o,this.tokStart,this.tokEnd))}else n.match(a)?(o=parseFloat(n),this.tokens.push(new r(l.FLOAT,o,this.tokStart,this.tokEnd))):"null"===n?this.tokens.push(new r(l.NULL,null,this.tokStart,this.tokEnd)):"true"===n?this.tokens.push(new r(l.TRUE,!0,this.tokStart,this.tokEnd)):"false"===n?this.tokens.push(new r(l.FALSE,!1,this.tokStart,this.tokEnd)):this.tokens.push(new r(e,n,this.tokStart,this.tokEnd));return this.tokStart=this.tokEnd,this.tokEnd<this.s.length},e.prototype.scanToEndOfQuoted=function(e,t,n){for(var o=t+1;o<e.length;){var r=e.charAt(o),l=e.charAt(o-1);if(r===n&&"\\"!==l&&"~"!==l)break;o++}if(e.charAt(o)!==n)throw new i("Unclosed quote: "+n+" in "+this.s+" near "+t+":"+o);return o+1},e.prototype.scanToEndOfString=function(e,t){for(var n=t+1;n<e.length&&!'[]();"=`'.includes(e.charAt(n));)n++;return n},e}()},558:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ModlBoolNull=t.ModlString=t.ModlQuoted=t.ModlFloat=t.ModlInteger=t.ModlPair=t.ModlArray=t.ModlMap=t.Modl=void 0;t.Modl=function(e){this.s=e};t.ModlMap=function(e){this.items=e};t.ModlArray=function(e){this.items=e};t.ModlPair=function(e,t){this.key=e,this.value=t};t.ModlInteger=function(e){this.value=e};t.ModlFloat=function(e){this.value=e};t.ModlQuoted=function(e){this.value=e};var n;t.ModlString=function(e){this.value=e},(n=t.ModlBoolNull||(t.ModlBoolNull={}))[n.ModlTrue=0]="ModlTrue",n[n.ModlFalse=1]="ModlFalse",n[n.ModlNull=2]="ModlNull"},733:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TokenStream=void 0;var n=function(){function e(e){this.tokens=e}return e.prototype.next=function(){var e=void 0;return this.tokens.length>0&&(e=this.tokens.shift()),e},e.prototype.peek=function(){var e=void 0;return this.tokens.length>0&&(e=this.tokens[0]),e},e.prototype.pushBack=function(e){this.tokens.unshift(e)},e.prototype.empty=function(){return 0===this.tokens.length},e}();t.TokenStream=n},403:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.parser=t.TokeniserException=t.ParserException=t.ModlBoolNull=t.ModlString=t.ModlFloat=t.ModlInteger=t.ModlQuoted=t.ModlPair=t.ModlArray=t.ModlMap=t.Modl=void 0;var o=n(558);Object.defineProperty(t,"Modl",{enumerable:!0,get:function(){return o.Modl}}),Object.defineProperty(t,"ModlArray",{enumerable:!0,get:function(){return o.ModlArray}}),Object.defineProperty(t,"ModlBoolNull",{enumerable:!0,get:function(){return o.ModlBoolNull}}),Object.defineProperty(t,"ModlFloat",{enumerable:!0,get:function(){return o.ModlFloat}}),Object.defineProperty(t,"ModlInteger",{enumerable:!0,get:function(){return o.ModlInteger}}),Object.defineProperty(t,"ModlMap",{enumerable:!0,get:function(){return o.ModlMap}}),Object.defineProperty(t,"ModlPair",{enumerable:!0,get:function(){return o.ModlPair}}),Object.defineProperty(t,"ModlQuoted",{enumerable:!0,get:function(){return o.ModlQuoted}}),Object.defineProperty(t,"ModlString",{enumerable:!0,get:function(){return o.ModlString}});var r=n(637);Object.defineProperty(t,"ParserException",{enumerable:!0,get:function(){return r.ParserException}});var i=n(984);Object.defineProperty(t,"TokeniserException",{enumerable:!0,get:function(){return i.TokeniserException}}),t.parser=r.parseModl}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,n),i.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.interpreter=void 0;const t=n(143);e.interpreter=new t.Interpreter})(),o})()}));

@@ -52,94 +52,35 @@ "use strict";

]);
const BACKSLASH_U = '\\u';
const TILDE_U = '~u';
const TILDE = '~';
const BACKSLASH = '\\';
const HEX = 16;
const digits = '0123456789';
const UNICODE_SEQ_LEN = 6;
const convertUnicodeSequences = (str) => {
let m;
let start = 0;
let result = str;
while (start < result.length) {
const backslashUIndex = result.indexOf(BACKSLASH_U, start);
const tildeUIndex = result.indexOf(TILDE_U, start);
let unicodeStrIdx;
if (tildeUIndex < 0 && backslashUIndex < 0) {
break;
let result = '';
const reg = /[~\\]u[0-9a-fA-F]{4}/g;
do {
m = reg.exec(str);
if (m) {
if (m.index > 0 && (str.charAt(m.index - 1) === '\\' || str.charAt(m.index - 1) === '~')) {
if (start < m.index - 1) {
result += str.substring(start, m.index - 1);
}
result += str.substring(m.index, m.index + UNICODE_SEQ_LEN);
start = m.index + UNICODE_SEQ_LEN;
}
else {
if (start < m.index) {
result += str.substring(start, m.index);
}
const c = Number.parseInt(m[0].substr(2), HEX);
result += String.fromCharCode(c);
start = m.index + UNICODE_SEQ_LEN;
}
}
else if (tildeUIndex < 0) {
unicodeStrIdx = backslashUIndex;
}
else if (backslashUIndex < 0) {
unicodeStrIdx = tildeUIndex;
}
else {
unicodeStrIdx = Math.min(backslashUIndex, tildeUIndex);
result += str.substring(start);
}
const tryParseResult = tryParse(result, unicodeStrIdx + 2);
start = unicodeStrIdx + 1;
if (!escapeSequenceIsEscaped(result, unicodeStrIdx)) {
if (tryParseResult.codePoint > 0) {
const chars = String.fromCodePoint(tryParseResult.codePoint);
result = replace(result, chars, unicodeStrIdx, tryParseResult.length + 2);
}
}
}
} while (m);
return result;
};
const escapeSequenceIsEscaped = (result, unicodeStrIdx) => {
return (unicodeStrIdx > 0 && (result.charAt(unicodeStrIdx - 1) === TILDE || result.charAt(unicodeStrIdx - 1) === BACKSLASH));
};
const replace = (s, value, unicodeStrIdx, length) => {
const left = s.substring(0, unicodeStrIdx);
const end = Math.min(s.length, unicodeStrIdx + length);
const right = s.substring(end);
return left + value + right;
};
const isValidRange = (value) => {
return ((value >= 0x100000 && value <= 0x10FFFF) ||
(value >= 0x10000 && value <= 0xFFFFF) ||
(value >= 0 && value <= 0xD7FF) ||
(value >= 0xE000 && value <= 0xFFFF));
};
const hasEnoughDigits = (s, idx, n) => {
let i = 0;
while (i < n && idx + i < s.length) {
const c = s[idx + i];
if (!digits.includes(c) && 'abcdefABCDEF'.indexOf(c) <= -1) {
return false;
}
i++;
}
return i === n;
};
const tryParse = (str, idx) => {
if (hasEnoughDigits(str, idx, 6) && str.substring(idx, idx + 2) !== '00') {
const value = getPossibleUnicodeValue(str, idx, 6);
if (isValidRange(value)) {
return new TryParseResult(value, 6);
}
}
if (hasEnoughDigits(str, idx, 5) && str.substring(idx, idx + 2) !== '00') {
const value = getPossibleUnicodeValue(str, idx, 5);
if (isValidRange(value)) {
return new TryParseResult(value, 5);
}
}
if (hasEnoughDigits(str, idx, 4)) {
const value = getPossibleUnicodeValue(str, idx, 4);
if (isValidRange(value)) {
return new TryParseResult(value, 4);
}
}
return new TryParseResult(0, 4);
};
const getPossibleUnicodeValue = (str, idx, i) => {
return Number.parseInt(str.substring(idx, idx + i), HEX);
};
class TryParseResult {
constructor(codePoint, length) {
this.codePoint = codePoint;
this.length = length;
}
}
//# sourceMappingURL=Utils.js.map

@@ -5,4 +5,4 @@ "use strict";

const interpreter = new Interpreter_1.Interpreter();
const jsonString = interpreter.interpretToJsonString('x = a MODL string');
const jsonString = interpreter.interpretToJsonString('x=~u0645~u062c~u062a~u0645~u0639 ~u0635~u0646~u0627~u06cc~u0639 ~u0634~u06cc~u0645~u06cc~u0627~u06cc~u06cc ~u0646~u0627~u0631~u06af~u0633~u062a~u0631');
console.log(jsonString);
//# sourceMappingURL=scratch.js.map
{
"name": "modl-interpreter",
"version": "0.0.16",
"version": "0.0.17",
"description": "A MODL interpreter in TypeScript",

@@ -27,3 +27,5 @@ "main": "dist/index.js",

"tslint-config-prettier": "^1.18.0",
"typescript": "^4.0.2"
"typescript": "^4.0.2",
"webpack": "^5.56.1",
"webpack-cli": "^4.8.0"
},

@@ -41,3 +43,3 @@ "scripts": {

"lint": "tslint --fix -p tsconfig.json",
"prepare": "npm test",
"prepare": "npm test && webpack",
"publish": "npm test && git tag v${npm_package_version} && git push && git push --tags"

@@ -44,0 +46,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc