modl-interpreter
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -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={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})()})); | ||
!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?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,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),s=n(984),l=n(733);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()+"'")}},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 s,l=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"}(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))||this.escaped(e,n-1));)n++;return n},e.prototype.escaped=function(e,t){return t>=0&&("~"==e.charAt(t)||"\\"==e.charAt(t))},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})()})); |
{ | ||
"name": "modl-interpreter", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "A MODL interpreter in TypeScript", | ||
@@ -10,3 +10,3 @@ "main": "dist/index.js", | ||
"loglevel-plugin-prefix": "^0.8.4", | ||
"modl-parser": "^0.1.15" | ||
"modl-parser": "^0.1.16" | ||
}, | ||
@@ -56,2 +56,2 @@ "devDependencies": { | ||
] | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30655
Updatedmodl-parser@^0.1.16