From 285b1c874b58f76e96cde05eeda00dc8395850ad Mon Sep 17 00:00:00 2001 From: Hyppoprogramm <65360617+GulgDev@users.noreply.github.com> Date: Wed, 7 Aug 2024 21:39:34 +0500 Subject: [PATCH] Fix float conversion --- bin/sigmascript.js | 2 +- package.json | 2 +- src/sigmascript/lib/js.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/sigmascript.js b/bin/sigmascript.js index a4a7bfd..7d7bc7f 100755 --- a/bin/sigmascript.js +++ b/bin/sigmascript.js @@ -37,7 +37,7 @@ e.exports=function(e,t){let r,o,s,i=!0;Array.isArray(e)?(r=[],o=e.length):(s=Obj * * Copyright (c) 2015-present, Jon Schlinkert. * Released under the MIT License. - */const n=r(1929),o=(e,t,r)=>{if(!1===n(e))throw new TypeError("toRegexRange: expected the first argument to be a number");if(void 0===t||e===t)return String(e);if(!1===n(t))throw new TypeError("toRegexRange: expected the second argument to be a number.");let s={relaxZeros:!0,...r};"boolean"==typeof s.strictZeros&&(s.relaxZeros=!1===s.strictZeros);let l=e+":"+t+"="+String(s.relaxZeros)+String(s.shorthand)+String(s.capture)+String(s.wrap);if(o.cache.hasOwnProperty(l))return o.cache[l].result;let c=Math.min(e,t),u=Math.max(e,t);if(1===Math.abs(c-u)){let r=e+"|"+t;return s.capture?`(${r})`:!1===s.wrap?r:`(?:${r})`}let d=f(e)||f(t),h={min:e,max:t,a:c,b:u},p=[],_=[];if(d&&(h.isPadded=d,h.maxLen=String(h.max).length),c<0){_=i(u<0?Math.abs(u):1,Math.abs(c),h,s),c=h.a=0}return u>=0&&(p=i(c,u,h,s)),h.negatives=_,h.positives=p,h.result=function(e,t,r){let n=a(e,t,"-",!1,r)||[],o=a(t,e,"",!1,r)||[],s=a(e,t,"-?",!0,r)||[];return n.concat(s).concat(o).join("|")}(_,p,s),!0===s.capture?h.result=`(${h.result})`:!1!==s.wrap&&p.length+_.length>1&&(h.result=`(?:${h.result})`),o.cache[l]=h,h.result};function s(e,t,r){if(e===t)return{pattern:e,count:[],digits:0};let n=function(e,t){let r=[];for(let n=0;n1&&o.count.pop(),o.count.push(l.count[0]),o.string=o.pattern+h(o.count),c=t+1)}return a}function a(e,t,r,n,o){let s=[];for(let o of e){let{string:e}=o;n||c(t,"string",e)||s.push(r+e),n&&c(t,"string",e)&&s.push(r+e)}return s}function l(e,t){return e>t?1:t>e?-1:0}function c(e,t,r){return e.some((e=>e[t]===r))}function u(e,t){return Number(String(e).slice(0,-t)+"9".repeat(t))}function d(e,t){return e-e%Math.pow(10,t)}function h(e){let[t=0,r=""]=e;return r||t>1?`{${t+(r?","+r:"")}}`:""}function p(e,t,r){return`[${e}${t-e==1?"":"-"}${t}]`}function f(e){return/^-?(0+)\d/.test(e)}function _(e,t,r){if(!t.isPadded)return e;let n=Math.abs(t.maxLen-String(e).length),o=!1!==r.relaxZeros;switch(n){case 0:return"";case 1:return o?"0?":"0";case 2:return o?"0{0,2}":"00";default:return o?`0{0,${n}}`:`0{${n}}`}}o.cache={},o.clearCache=()=>o.cache={},e.exports=o},6909:(e,t,r)=>{"use strict";r.a(e,(async(e,t)=>{try{var n=r(7101),o=r(2921),s=r(2065),i=r(1943),a=r(6928),l=r(9923),c=r(4447);const u={compile:"C",bundle:"B","bundle-runtime":"R",ssx:"X"},d=["node","browser","ssx"];function h(e){try{new URL(e)}catch{return!1}return!0}const p=new Map,f=[];e:for(const b of process.argv.slice(2))if(/^(-[A-Z]|--[a-z-]+)(=.+)?$/.test(b)){const y=b.match(/^(-([A-Z])|--([a-z-]+))/),g=y[2]??y[3],S=b.indexOf("="),v=-1===S?g:b.slice(S+1);for(const[w,E]of Object.entries(u))if(w===g||E===g){p.set(w,v);continue e}console.error(`Invalid flag: '${g}' (${b})`)}else h(b)?f.push(b):f.push(...await c(b,{dot:!0}));p.has("bundle-runtime")&&!d.includes(p.get("bundle-runtime"))&&(console.error(`Unknown runtime: '${p.get("bundle-runtime")}'`),process.exit(-1)),p.has("bundle")&&p.has("compile")&&(console.error("Cannot use '--bundle' and '--compile' together"),process.exit(-1)),!p.has("bundle")&&p.has("bundle-runtime")&&console.warn("'--bundle-runtime' is ignored when '--bundle' flag is not set"),!p.has("ssx")||p.has("bundle")||p.has("compile")?p.has("ssx")&&p.has("bundle-runtime")&&"ssx"!==p.get("bundle-runtime")&&console.warn("'--ssx' is enabled, but '--bundle-runtime' is not 'ssx'"):(console.error("Cannot run scripts with '--ssx' flag"),process.exit(-1));const _=(p.has("bundle")||p.has("compile"))&&p.has("ssx")?new o.x(null):new n.b(l.f),m=[];for(const R of f){let A;const T=h(R);if(T){let P;try{P=await(0,s.Ay)(R)}catch(x){console.error(`${R} - ${x.message}`);continue}if(!P.ok){console.error(`${R} - ${P.status} (${P.statusText})`);continue}try{A=await P.text()}catch(k){console.error(`${R} - ${k.message}`);continue}}else try{A=await(0,i.readFile)(R,{encoding:"utf8"})}catch(C){console.error(`${R} - ${C.message}`);continue}if(p.has("compile"))await(0,i.writeFile)((T?(0,a.basename)(R):R).split(".").slice(0,-1).join(".")+".js",_.compile(A)??"");else{const O=_.getLibName(A),$={lib:O,source:A};O?m.unshift($):m.push($)}}if(p.has("bundle")){let L=p.has("bundle-runtime")?await(0,i.readFile)((0,a.resolve)(__dirname,`../dist/runtime/${p.get("bundle-runtime")}.js`),{encoding:"utf8"})+"\n":"";for(const M of m){const D=_.compile(M.source);if(!D)continue;const j=`(runtime) => {\n${D}}`;L+=M.lib?`runtime.lib("${M.lib}", ${j});\n`:`(${j})(runtime);\n`}await(0,i.writeFile)(p.get("bundle"),L)}else for(const{source:B}of m)_.load(B);t()}catch(F){t(F)}}),1)},5842:(e,t,r)=>{"use strict";r.d(t,{h:()=>s});var n=r(7879),o=r(7056);class s extends n.j{constructor(){super(...arguments),this.registry=new o.O("array"),this.functions={array:(...e)=>this.array(e),array_add:(e,t)=>this.add(e,t),array_remove:(e,t)=>this.remove(e,t),array_at:(e,t)=>this.at(e,t),array_set:(e,t,r)=>this.set(e,t,r),array_length:e=>this.length(e),array_find:(e,t)=>this.find(e,t)}}array(e){return this.registry.add(e)}add(e,t){return this.registry.get(e)?.push(t),"unknown"}remove(e,t){return this.registry.get(e)?.splice(Number.parseInt(t),1),"unknown"}at(e,t){return this.registry.get(e)?.at(Number.parseInt(t))??"unknown"}set(e,t,r){const n=this.registry.get(e),o=Number.parseInt(t);return n&&!Number.isNaN(o)&&o>=-n.length&&o{"use strict";r.d(t,{a:()=>s});var n=r(7879),o=r(7056);class s extends n.j{constructor(){super(...arguments),this.registry=new o.O("fn"),this.functions={call:(e,...t)=>this.call(e,t)}}addFn(e){return this.registry.add(e)}getFn(e){return this.registry.get(e)}call(e,t){return this.registry.get(e)?.(...t)??"unknown"}}},7879:(e,t,r)=>{"use strict";r.d(t,{j:()=>o,y:()=>n});class n{constructor(e,t){this.result=null,this.runtime=e,this.func=t}use(e){this.runtime.copyScope(this.result??(this.result=this.func(this.runtime)),e)}}class o{constructor(e){this.variables={},this.functions={},this.runtime=e}use(e){Object.assign(e.variables,this.variables),Object.assign(e.functions,this.functions)}}},8201:(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{"use strict";__webpack_require__.d(__webpack_exports__,{L:()=>NodeJSLib});var _js__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(6416);class NodeJSLib extends _js__WEBPACK_IMPORTED_MODULE_0__.V{constructor(){super(...arguments),this.variables={js_env:"node",js_global:this.registry.add(globalThis)},this.functions={...this.functions,js_require:path=>this.toSS(eval("require")(path))}}}},6416:(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{"use strict";__webpack_require__.d(__webpack_exports__,{V:()=>JSLib});var ___WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(7879),_registry__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(7056),_array__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(5842),_fn__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(6855),_ref__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(7642),_struct__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3126);const ssSymbol=Symbol("ss");class JSLib extends ___WEBPACK_IMPORTED_MODULE_4__.j{constructor(){super(...arguments),this.registry=new _registry__WEBPACK_IMPORTED_MODULE_5__.O("js"),this.functions={js:e=>this.js(e),js_get:(e,t)=>this.get(e,t),js_set:(e,t,r)=>this.set(e,t,r),js_new:(e,...t)=>this.new(e,t),js_object:()=>this.toSS({}),js_array:()=>this.toSS([]),js_call:(e,...t)=>this.call(e,t),js_call_method:(e,t,...r)=>this.callMethod(e,t,r)}}getObject(e){return this.registry.get(e)}toJSObject(e){if(e.startsWith("#js:"))return this.getObject(e);if(e.startsWith("#fn")){const t=this.runtime.getLib(_fn__WEBPACK_IMPORTED_MODULE_1__.a).getFn(e);if(!t)return;return(...e)=>this.toJS(t(...e.map((e=>this.toSS(e)))))}if(e.startsWith("#struct:")){const t=this.runtime.getLib(_struct__WEBPACK_IMPORTED_MODULE_3__.B).getStruct(e);if(!t)return;const r={};for(const e in t)r[e]=this.toJS(t[e]);return r}if(e.startsWith("#array:")){const t=this.runtime.getLib(_array__WEBPACK_IMPORTED_MODULE_0__.h).getArray(e);if(!t)return;return t.map((e=>this.toJS(e)))}return e}toJS(e){if(e.startsWith("#ref:"))return this.toJS(this.runtime.getLib(_ref__WEBPACK_IMPORTED_MODULE_2__.t).get(e));if("unknown"===e)return;if("false"===e)return!1;if("true"===e)return!0;if(/^-?[0-9]+(\.[0-9]+)?$/.test(e))return Number.parseFloat(e);const t=this.toJSObject(e);return t instanceof Object&&!t[ssSymbol]&&Object.defineProperty(t,ssSymbol,{value:e,enumerable:!1}),t}toSS(e){const t=e[ssSymbol];return void 0!==t?t:"string"==typeof e||e instanceof String||"boolean"==typeof e||e instanceof Boolean||Number.isInteger(e)?`${e}`:null==e||Number.isNaN(e)?"unknown":this.registry.add(e)}js(code){return this.toSS(eval(code))}get(e,t){const r=this.toJS(e)?.[t];return null==r?"unknown":this.toSS(r)}set(e,t,r){const n=this.toJS(e);return null!=n&&(n[t]=this.toJS(r)),"unknown"}new(e,t){const r=this.toJS(e);if(null==r)return"unknown";const n=new r(...t.map((e=>this.toJS(e))));return null==n?"unknown":this.toSS(n)}call(e,t){const r=this.toJS(e)?.(...t.map((e=>this.toJS(e))));return null==r?"unknown":this.toSS(r)}callMethod(e,t,r){const n=this.toJS(e)?.[t]?.(...r.map((e=>this.toJS(e))));return null==n?"unknown":this.toSS(n)}}},7642:(e,t,r)=>{"use strict";r.d(t,{t:()=>s});var n=r(7879),o=r(7056);class s extends n.j{constructor(){super(...arguments),this.registry=new o.O("ref"),this.functions={ref:e=>this.ref(e),ref_set:(e,t)=>this.set(e,t),ref_get:e=>this.get(e)}}ref(e){return this.registry.add(e)}set(e,t){return this.registry.set(e,t),"unknown"}get(e){return this.registry.get(e)??"unknown"}}},3126:(e,t,r)=>{"use strict";r.d(t,{B:()=>s});var n=r(7879),o=r(7056);class s extends n.j{constructor(){super(...arguments),this.registry=new o.O("struct"),this.functions={struct:()=>this.struct(),struct_set:(e,t,r)=>this.set(e,t,r),struct_get:(e,t)=>this.get(e,t)}}struct(){return this.registry.add({})}set(e,t,r){const n=this.registry.get(e);return n&&(n[t]=r),"unknown"}get(e,t){return this.registry.get(e)?.[t]??"unknown"}getStruct(e){return this.registry.get(e)}}},7056:(e,t,r)=>{"use strict";r.d(t,{O:()=>n});class n{constructor(e){this.elements={},this.id=-1,this.name=e}add(e){const t=`#${this.name}:${++this.id}`;return this.elements[t]=e,t}set(e,t){e in this.elements&&(this.elements[e]=t)}get(e){return this.elements[e]}}},9923:(e,t,r)=>{"use strict";r.d(t,{f:()=>p});var n=r(7879),o=r(6855),s=r(6416);var i=r(8201),a=r(7642);class l extends n.j{constructor(){super(...arguments),this.functions={string_at:(e,t)=>e.at(Number.parseInt(t))??"unknown",string_length:e=>`${e.length}`,string_slice:(e,t,r)=>e.slice(Number.parseInt(t),Number.parseInt(r)),string_replace:(e,t,r)=>e.replaceAll(t,r),string_format:(e,...t)=>this.format(e,t)}}format(e,t){if(0===t.length)return e;let r="";const n=e.length;let o=0,s=0;for(;o=t.length){r+=e.slice(o);break}continue}++o}r+=n}return r}}var c=r(3126),u=r(5842);function d(e){return(...t)=>{const r=e(...t.map((e=>Number.parseFloat(e))));return Number.isNaN(r)?"unknown":`${r}`}}class h extends n.j{constructor(){super(...arguments),this.variables={pi:`${Math.PI}`},this.functions={abs:d((e=>Math.abs(e))),sign:d((e=>Math.sign(e))),sqrt:d((e=>Math.sqrt(e))),mod:d(((e,t)=>e%t)),sin:d((e=>Math.sin(e))),cos:d((e=>Math.cos(e))),tan:d((e=>Math.tan(e))),asin:d((e=>Math.asin(e))),acos:d((e=>Math.acos(e))),atan:d(((e,t)=>null==t?Math.atan(e):Math.atan2(e,t))),sinh:d((e=>Math.sinh(e))),cosh:d((e=>Math.cosh(e))),tanh:d((e=>Math.tanh(e))),asinh:d((e=>Math.asinh(e))),acosh:d((e=>Math.acosh(e))),atanh:d((e=>Math.atanh(e))),exp:d((e=>Math.exp(e))),rad:d((e=>e*Math.PI/180)),deg:d((e=>180*e/Math.PI)),round:d(((e,t=1)=>Math.round(e/t)*t)),floor:d(((e,t=1)=>Math.floor(e/t)*t)),ceil:d(((e,t=1)=>Math.ceil(e/t)*t)),random:()=>`${Math.random()}`,randint:(e,t)=>this.randint(e,t)}}randint(e,t){const r=Number.parseFloat(e),n=Number.parseFloat(t),o=Math.min(r,n),s=Math.max(r,n);return`${Math.random()*(s-o)+o}`}}const p=new class{constructor(){this.libs={}}addLib(e,t){return this.libs[e]=t}getLib(e){return Object.values(this.libs).find((t=>t instanceof e))}lib(e,t){this.addLib(e,new n.y(this,t))}scope(e){const t={variables:{},functions:{}};return e&&this.copyScope(e,t),t}copyScope(e,t){Object.assign(t.variables,e.variables),Object.assign(t.functions,e.functions)}lambda(e){return this.getLib(o.a).addFn(e)}print(e){void 0===(e=this.getLib(s.V).toJS(e))&&(e="unknown"),console.log(e)}};p.addLib("fn",new o.a(p)),p.addLib("js",new i.L(p)),p.addLib("ref",new a.t(p)),p.addLib("string",new l(p)),p.addLib("struct",new c.B(p)),p.addLib("array",new u.h(p)),p.addLib("math",new h(p))},7101:(e,t,r)=>{"use strict";var n;r.d(t,{b:()=>T}),function(e){e.isWhitespace=function(e){return" "===e||"\n"===e||"\r"===e},e.isDigit=function(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57},e.isLetter=function(e){if(!e)return!1;const t=e.toLowerCase().charCodeAt(0);return t>=97&&t<=122}}(n||(n={}));class o{constructor(e){this.buffer=e,this._offset=0,this.line=0,this.column=0}get location(){return{offset:this._offset,line:this.line,column:this.column}}set location(e){this._offset=e.offset,this.line=e.line,this.column=e.column}get offset(){return this._offset}peekch(){return this.buffer[this._offset]}consume(){"\n"===this.peekch()?(++this.line,this.column=0):++this.column,++this._offset}}class s{constructor(e={},t){this.elements=e,this.last=t}with(e,t){const r={...this.elements};return r[e]=r[e]?[...r[e],t]:[t],new s(r,t)}has(e,t){return this.elements[e]?.includes(t)}}class i{}class a extends i{constructor(e){super(),this.ch=e}match(e){const t=e.location;if(e.peekch()===this.ch)return e.consume(),{start:t,end:e.location}}}class l extends i{constructor(e,t){super(),this.a=e,this.b=t}match(e,t,r=1,n=new s,o={}){const i=e.location,a=!(this.a instanceof m&&n.has(i.offset,this.a.name))&&this.a.match(e,t,r,n,o),l=e.location;e.location=i;const c=!(this.b instanceof m&&n.has(i.offset,this.b.name))&&this.b.match(e,t,r,n,o),u=e.location;let d=!a&&c||!c&&a;if(a&&c&&(d=l.offset>u.offset?a:c),d===a&&(e.location=l),d)return{start:i,end:e.location,children:[d]}}}class c extends i{match(e){const t=e.location;for(;n.isWhitespace(e.peekch());)e.consume();return{start:t,end:e.location}}}class u extends i{match(e){const t=e.location;if(e.peekch())return e.consume(),{start:t,end:e.location}}}class d extends i{match(e){const t=e.location;if(n.isDigit(e.peekch()))return e.consume(),{start:t,end:e.location}}}class h extends i{constructor(e){super(),this.pattern=e}match(e,t,r=1,n=new s,o={}){const i=e.location,a=this.pattern.match(e,t,r,n,o);return a||(e.location=i),{start:i,end:e.location,children:a?[a]:[]}}}class p extends i{constructor(e){super(),this.pattern=e}match(e,t,r=1,n=new s,o={}){const i=e.location;let a=this.pattern.match(e,t,r,n,o);const l=[a];if(!a)return;let c=e.location;for(;(a=this.pattern.match(e,t,r,n,o))&&c.offset!==e.offset;)l.push(a),c=e.location;return e.location=c,{start:i,end:e.location,children:l}}}class f extends i{constructor(e,t){super(),this.group=e,this.disallow=t}match(e){const t=e.location,r=e.peekch();if(!r)return;const n=r.charCodeAt(0);e.consume();for(const o of this.group)if(Array.isArray(o)&&n>=o[0].charCodeAt(0)&&n<=o[1].charCodeAt(0)||r===o)return!this.disallow&&{start:t,end:e.location};return this.disallow&&{start:t,end:e.location}}}class _ extends i{constructor(e){super(),this.children=e}match(e,t,r=1,n=new s,o={}){const i=e.location,a=[];for(const s of this.children){const i=s.match(e,t,r,n,o);if(!i)return;a.push(i)}return{start:i,end:e.location,children:a}}}class m extends i{constructor(e,t){super(),this.name=e,this.unmatched=t}match(e,t,r=1,n=new s,o={}){const i=`${r},${n.last},${e.offset},${this.name}`,a=o[i];if(void 0!==a)return a&&(e.location=a.end),a;const l=e.location;n=n.with(l.offset,this.name);const c=t.get(this.name);if(!c||c.precedence&&c.precedence0&&!Array.isArray(r.at(-1))){n=!0;continue}r.push(s)}if(n){n=!1;const e=r.pop();r.push([r.pop(),e])}}o.push(new f(r,t))}else if("."===s)o.push(new u);else if(" "===s)o.push(new c);else{if("|"===s&&o.length>0&&!i){i=!0;continue}"?"===s&&o.length>0?o.push(new h(o.pop())):"+"===s&&o.length>0?o.push(new p(o.pop())):o.push(new a(s))}}i&&(o.push(new l(o.pop(),o.pop())),i=!1)}const g=1===o.length?o[0]:new _(o);return g.precedence=t,g.preservePrecedence=r,g}function g(e,t,r){return y(new o(e),t,r)}class S{constructor(e,t,r,n){this.name=e,this.start=t,this.end=r,this.value=n,this.children=[]}get first(){return this.children[0]}get last(){return this.children.at(-1)}*[Symbol.iterator](){for(const e of this.children)yield e}addChild(e){this.children.push(e)}get(e){return this.children[e]}findChildren(e){return this.children.filter((t=>t.name===e))}findChild(e){return this.children.find((t=>t.name===e))}find(e){const t=this.findChild(e);if(t)return t;for(const t of this.children){const r=t.find(e);if(r)return r}}}class v{constructor(e){this.patterns=new Map,this.cache={};for(const[t,r]of Object.entries(e))"string"==typeof r?this.patterns.set(t,g(r)):this.patterns.set(t,g(r.pattern,r.precedence,r.preservePrecedence))}parse(e){const t=this.cache[e];if(void 0!==t)return t;const r=this.patterns.get("root").match(new o(e),this.patterns);if(!r)return;const n=new S("root",r.start,r.end,e.slice(r.start.offset,r.end.offset));return function t(r,n){if(r.name){const t=new S(r.name,r.start,r.end,e.slice(r.start.offset,r.end.offset));n.addChild(t),n=t}if(r.children)for(const e of r.children)t(e,n)}(r,n),n}}function w(e,t){return t.replace(/\.\.\./g,e)}function E(e,t){return e?t?"string"==typeof e&&"string"==typeof t?w(e,t):"string"==typeof e&&"string"!=typeof t?{...t,pattern:w(e,t.pattern)}:"string"!=typeof e&&"string"==typeof t?{...e,pattern:w(e.pattern,t)}:"string"!=typeof e&&"string"!=typeof t?{pattern:w(e.pattern,t.pattern),precedence:t.precedence??e.precedence,preservePrecedence:t.preservePrecedence??e.preservePrecedence}:void 0:e:t}var R=r(7879);const A={number:"%d+(%.%d+)?",name:"[a-zA-Z_][a-zA-Z0-9_]+?",string:'"([^"]|(\\\\)|(\\"))+?"',bool:"(true)|(false)",neg:"- %expr",add:{pattern:"%expr %+ %expr",precedence:5},sub:{pattern:"%expr - %expr",precedence:5},mul:{pattern:"%expr * %expr",precedence:6},div:{pattern:"%expr / %expr",precedence:6},concat:{pattern:"%expr @ %expr",precedence:1},eq:{pattern:"%expr = %expr",precedence:4},lt:{pattern:"%expr < %expr",precedence:4},gt:{pattern:"%expr > %expr",precedence:4},le:{pattern:"%expr <= %expr",precedence:4},ge:{pattern:"%expr >= %expr",precedence:4},or:{pattern:"%expr %| %expr",precedence:2},and:{pattern:"%expr & %expr",precedence:3},not:"! %expr",arglist:"(%expr( , %expr)+?)?",call:"%name %( %arglist %)",lambda:"%( %paramlist %) => ({ %body })|%expr",parenthesisexpr:"%( %expr %)",expr:{pattern:"%parenthesisexpr|%number|%string|%bool|%name|%neg|%add|%sub|%mul|%div|%concat|%eq|%lt|%gt|%le|%ge|%or|%and|%not|%call|%lambda",preservePrecedence:!0},assign:"%name = %expr;",paramlist:"(%name( , %name)+?)?",if:"if %expr { %body } %else?",else:"else { %body }",while:"while %expr { %body }",function:"fn %name %( %paramlist %) { %body }",return:"ret %expr;",callstat:"%call;",print:"print %expr;",statement:"%assign|%if|%while|%function|%return|%callstat|%print",comment:"//[^\n]+?",comments:"( %!comment )+?",body:"( %!comments %statement %!comments )+?",use:"use %name;",imports:"( %use %!comments )+?",lib:"lib %name;",root:"%!comments %lib? %!comments %imports %body %!comments"};class T{constructor(e,t={}){this.runtime=e,this.parser=new v(function(e,t){const r={root:E(e.root,t.root)};for(const n in e)n in r||(r[n]=E(e[n],t[n]));for(const n in t)n in r||(r[n]=E(e[n],t[n]));return r}(A,t))}compileExpr(e,t){switch("expr"===e.name&&(e=e.first),e.name){case"parenthesisexpr":return`(${this.compileExpr(e.first,t)})`;case"name":return`(scope${t}.variables.${e.value} ?? "unknown")`;case"number":case"bool":return`"${e.value}"`;case"string":return e.value;case"neg":return`\`\${-${this.compileExpr(e.first,t)}}\``;case"add":return`\`\${+${this.compileExpr(e.first,t)} + +${this.compileExpr(e.last,t)}}\``;case"sub":return`\`\${+${this.compileExpr(e.first,t)} - +${this.compileExpr(e.last,t)}}\``;case"mul":return`\`\${+${this.compileExpr(e.first,t)} * +${this.compileExpr(e.last,t)}}\``;case"div":return`\`\${+${this.compileExpr(e.first,t)} / +${this.compileExpr(e.last,t)}}\``;case"eq":return`\`\${${this.compileExpr(e.first,t)} === ${this.compileExpr(e.last,t)}}\``;case"lt":return`\`\${+${this.compileExpr(e.first,t)} < +${this.compileExpr(e.last,t)}}\``;case"gt":return`\`\${+${this.compileExpr(e.first,t)} > +${this.compileExpr(e.last,t)}}\``;case"le":return`\`\${+${this.compileExpr(e.first,t)} <= +${this.compileExpr(e.last,t)}}\``;case"ge":return`\`\${+${this.compileExpr(e.first,t)} >= +${this.compileExpr(e.last,t)}}\``;case"or":return`\`\${${this.compileExpr(e.first,t)} === "true" || ${this.compileExpr(e.last,t)} === "true"}\``;case"and":return`\`\${${this.compileExpr(e.first,t)} === "true" && ${this.compileExpr(e.last,t)} === "true"}\``;case"not":return`\`\${${this.compileExpr(e.first,t)} === "true" ? "false" : "true"}\``;case"concat":return`${this.compileExpr(e.first,t)} + ${this.compileExpr(e.last,t)}`;case"call":return`(${this.compileCall(e,t)} ?? "unknown")`;case"lambda":return`runtime.lambda(${e.findChild("expr")?this.compileLambda(e,t):this.compileFunction(e,t)})`}}compileCall(e,t){return`scope${t}.functions.${e.find("name").value}?.(${Array.from(e.find("arglist")).map((e=>this.compileExpr(e,t))).join(", ")})`}compileFunction(e,t){const r=Array.from(e.find("paramlist"));return`(${r.map(((e,t)=>`arg${t}="unknown"`)).join(", ")}) => {\n${this.localScope(++t)+r.map(((e,r)=>`scope${t}.variables.${e.value} = arg${r};\n`)).join("")+this.compileBody(e.find("body"),t)}return "unknown";\n}`}compileLambda(e,t){const r=Array.from(e.find("paramlist"));return`(${r.map(((e,t)=>`arg${t}="unknown"`)).join(", ")}) => {\n${this.localScope(++t)+r.map(((e,r)=>`scope${t}.variables.${e.value} = arg${r};\n`)).join("")}return ${this.compileExpr(e.find("expr"),t)};\n}`}compileStatement(e,t){switch(e.name){case"assign":return`scope${t}.variables.${e.find("name").value} = ${this.compileExpr(e.find("expr"),t)};`;case"if":{let r=`if ((${this.compileExpr(e.find("expr"),t)}) === "true") {\n${this.compileBody(e.find("body"),t)}}`;const n=e.findChild("else");return n&&(r+=`\nelse {\n${this.compileBody(n.find("body"),t)}}`),r}case"while":return`while ((${this.compileExpr(e.find("expr"),t)}) === "true") {\n${this.compileBody(e.find("body"),t)}}`;case"function":return`scope${t}.functions.${e.find("name").value} = ${this.compileFunction(e,t)};`;case"print":return`runtime.print(${this.compileExpr(e.find("expr"),t)});`;case"callstat":return this.compileCall(e.first,t)+";";case"return":return`return ${this.compileExpr(e.find("expr"),t)};`}}compileBody(e,t=0){let r="";for(const{first:n}of e)r+=this.compileStatement(n,t)+"\n";return r}localScope(e){return`const scope${e} = runtime.scope(scope${e-1});\n`}globalScope(){return"const scope0 = runtime.scope();\n"}compileImports(e){let t="";for(const r of e)t+=`runtime.libs.${r.find("name").value}?.use(scope0);\n`;return t}compileProgram(e){let t=this.globalScope();return t+=this.compileImports(e.find("imports")),t+=this.compileBody(e.find("body")),t+="return scope0;\n",t}createFunction(e){return Function("runtime",this.compileProgram(e))}getLibName(e){return this.parser.parse(e)?.findChild("lib")?.find("name")?.value}compile(e){const t=this.parser.parse(e);if(t&&t.end.offset===e.length)return this.compileProgram(t)}load(e){const t=this.parser.parse(e);if(!t||t.end.offset!==e.length)return;const r=t.findChild("lib"),n=this.createFunction(t);if(!r)return n(this.runtime);this.runtime.addLib(r.find("name").value,new R.y(this.runtime,n))}}},2921:(e,t,r)=>{"use strict";r.d(t,{x:()=>i});var n=r(7101);const o={htmlname:"[a-z0-9-]+",htmlattrval:"%string|({ %expr })",htmlattr:"%htmlname=%htmlattrval",htmlentity:"&%htmlname;",htmltext:"([^&<>{}])+",htmlcontent:"(%htmltext|%htmlentity|({ %expr })|%html)+?",htmlsingle:"<%htmlname( %htmlattr )+? />",htmlpaired:"<%htmlname( %htmlattr )+?>%htmlcontent",html:"%htmlsingle|%htmlpaired",expr:"...|%html",component:"fn <%htmlname( %htmlattr )+?> { %body }",statement:"...|%component"},s={amp:"&",lt:"<",gt:">"};class i extends n.b{constructor(e){super(e,o)}compileHTMLContent(e,t){const r=[];for(const n of e)switch(n.name){case"htmltext":r.push(JSON.stringify(n.value));break;case"htmlentity":r.push(`"${s[n.find("htmlname").value]??n.value}"`);break;case"expr":case"html":r.push(this.compileExpr(n,t))}switch(r.length){case 0:return'"unknown"';case 1:return r[0];default:return`runtime.ssxGroup(${r.join(", ")})`}}compileExpr(e,t){if("expr"===e.name&&(e=e.first),"html"===e.name){const r="htmlpaired"===(e=e.first).name,n=e.first.value;return r&&e.last.value!==n?'"unknown"':`runtime.ssx(scope${t}, "${n}", { ${e.findChildren("htmlattr").map((e=>`"${e.find("htmlname").value}": ${this.compileExpr(e.find("htmlattrval").first,t)}`)).join(", ")} }, ${this.compileHTMLContent(e.findChild("htmlcontent"),t)})`}return super.compileExpr(e,t)}compileStatement(e,t){if("component"===e.name){const r={};for(const n of e.findChildren("htmlattr"))r[n.find("htmlname").value]=this.compileExpr(n.find("htmlattrval").first,t);return`scope${t}.components["${e.find("htmlname").value}"] = (attrs, children) => {\n${this.localScope(++t)}scope${t}.variables.children = children;\n${Object.keys(r).map((e=>`scope${t}.variables.${e} = attrs.${e} ?? ${r[e]};\n`)).join("")+this.compileBody(e.find("body"),t)}return "unknown";\n};`}return super.compileStatement(e,t)}}},5010:function(e,t){ + */const n=r(1929),o=(e,t,r)=>{if(!1===n(e))throw new TypeError("toRegexRange: expected the first argument to be a number");if(void 0===t||e===t)return String(e);if(!1===n(t))throw new TypeError("toRegexRange: expected the second argument to be a number.");let s={relaxZeros:!0,...r};"boolean"==typeof s.strictZeros&&(s.relaxZeros=!1===s.strictZeros);let l=e+":"+t+"="+String(s.relaxZeros)+String(s.shorthand)+String(s.capture)+String(s.wrap);if(o.cache.hasOwnProperty(l))return o.cache[l].result;let c=Math.min(e,t),u=Math.max(e,t);if(1===Math.abs(c-u)){let r=e+"|"+t;return s.capture?`(${r})`:!1===s.wrap?r:`(?:${r})`}let d=f(e)||f(t),h={min:e,max:t,a:c,b:u},p=[],_=[];if(d&&(h.isPadded=d,h.maxLen=String(h.max).length),c<0){_=i(u<0?Math.abs(u):1,Math.abs(c),h,s),c=h.a=0}return u>=0&&(p=i(c,u,h,s)),h.negatives=_,h.positives=p,h.result=function(e,t,r){let n=a(e,t,"-",!1,r)||[],o=a(t,e,"",!1,r)||[],s=a(e,t,"-?",!0,r)||[];return n.concat(s).concat(o).join("|")}(_,p,s),!0===s.capture?h.result=`(${h.result})`:!1!==s.wrap&&p.length+_.length>1&&(h.result=`(?:${h.result})`),o.cache[l]=h,h.result};function s(e,t,r){if(e===t)return{pattern:e,count:[],digits:0};let n=function(e,t){let r=[];for(let n=0;n1&&o.count.pop(),o.count.push(l.count[0]),o.string=o.pattern+h(o.count),c=t+1)}return a}function a(e,t,r,n,o){let s=[];for(let o of e){let{string:e}=o;n||c(t,"string",e)||s.push(r+e),n&&c(t,"string",e)&&s.push(r+e)}return s}function l(e,t){return e>t?1:t>e?-1:0}function c(e,t,r){return e.some((e=>e[t]===r))}function u(e,t){return Number(String(e).slice(0,-t)+"9".repeat(t))}function d(e,t){return e-e%Math.pow(10,t)}function h(e){let[t=0,r=""]=e;return r||t>1?`{${t+(r?","+r:"")}}`:""}function p(e,t,r){return`[${e}${t-e==1?"":"-"}${t}]`}function f(e){return/^-?(0+)\d/.test(e)}function _(e,t,r){if(!t.isPadded)return e;let n=Math.abs(t.maxLen-String(e).length),o=!1!==r.relaxZeros;switch(n){case 0:return"";case 1:return o?"0?":"0";case 2:return o?"0{0,2}":"00";default:return o?`0{0,${n}}`:`0{${n}}`}}o.cache={},o.clearCache=()=>o.cache={},e.exports=o},6909:(e,t,r)=>{"use strict";r.a(e,(async(e,t)=>{try{var n=r(7101),o=r(2921),s=r(2065),i=r(1943),a=r(6928),l=r(9923),c=r(4447);const u={compile:"C",bundle:"B","bundle-runtime":"R",ssx:"X"},d=["node","browser","ssx"];function h(e){try{new URL(e)}catch{return!1}return!0}const p=new Map,f=[];e:for(const b of process.argv.slice(2))if(/^(-[A-Z]|--[a-z-]+)(=.+)?$/.test(b)){const y=b.match(/^(-([A-Z])|--([a-z-]+))/),g=y[2]??y[3],S=b.indexOf("="),v=-1===S?g:b.slice(S+1);for(const[w,E]of Object.entries(u))if(w===g||E===g){p.set(w,v);continue e}console.error(`Invalid flag: '${g}' (${b})`)}else h(b)?f.push(b):f.push(...await c(b,{dot:!0}));p.has("bundle-runtime")&&!d.includes(p.get("bundle-runtime"))&&(console.error(`Unknown runtime: '${p.get("bundle-runtime")}'`),process.exit(-1)),p.has("bundle")&&p.has("compile")&&(console.error("Cannot use '--bundle' and '--compile' together"),process.exit(-1)),!p.has("bundle")&&p.has("bundle-runtime")&&console.warn("'--bundle-runtime' is ignored when '--bundle' flag is not set"),!p.has("ssx")||p.has("bundle")||p.has("compile")?p.has("ssx")&&p.has("bundle-runtime")&&"ssx"!==p.get("bundle-runtime")&&console.warn("'--ssx' is enabled, but '--bundle-runtime' is not 'ssx'"):(console.error("Cannot run scripts with '--ssx' flag"),process.exit(-1));const _=(p.has("bundle")||p.has("compile"))&&p.has("ssx")?new o.x(null):new n.b(l.f),m=[];for(const R of f){let A;const T=h(R);if(T){let P;try{P=await(0,s.Ay)(R)}catch(x){console.error(`${R} - ${x.message}`);continue}if(!P.ok){console.error(`${R} - ${P.status} (${P.statusText})`);continue}try{A=await P.text()}catch(k){console.error(`${R} - ${k.message}`);continue}}else try{A=await(0,i.readFile)(R,{encoding:"utf8"})}catch(C){console.error(`${R} - ${C.message}`);continue}if(p.has("compile"))await(0,i.writeFile)((T?(0,a.basename)(R):R).split(".").slice(0,-1).join(".")+".js",_.compile(A)??"");else{const O=_.getLibName(A),$={lib:O,source:A};O?m.unshift($):m.push($)}}if(p.has("bundle")){let L=p.has("bundle-runtime")?await(0,i.readFile)((0,a.resolve)(__dirname,`../dist/runtime/${p.get("bundle-runtime")}.js`),{encoding:"utf8"})+"\n":"";for(const M of m){const D=_.compile(M.source);if(!D)continue;const j=`(runtime) => {\n${D}}`;L+=M.lib?`runtime.lib("${M.lib}", ${j});\n`:`(${j})(runtime);\n`}await(0,i.writeFile)(p.get("bundle"),L)}else for(const{source:B}of m)_.load(B);t()}catch(F){t(F)}}),1)},5842:(e,t,r)=>{"use strict";r.d(t,{h:()=>s});var n=r(7879),o=r(7056);class s extends n.j{constructor(){super(...arguments),this.registry=new o.O("array"),this.functions={array:(...e)=>this.array(e),array_add:(e,t)=>this.add(e,t),array_remove:(e,t)=>this.remove(e,t),array_at:(e,t)=>this.at(e,t),array_set:(e,t,r)=>this.set(e,t,r),array_length:e=>this.length(e),array_find:(e,t)=>this.find(e,t)}}array(e){return this.registry.add(e)}add(e,t){return this.registry.get(e)?.push(t),"unknown"}remove(e,t){return this.registry.get(e)?.splice(Number.parseInt(t),1),"unknown"}at(e,t){return this.registry.get(e)?.at(Number.parseInt(t))??"unknown"}set(e,t,r){const n=this.registry.get(e),o=Number.parseInt(t);return n&&!Number.isNaN(o)&&o>=-n.length&&o{"use strict";r.d(t,{a:()=>s});var n=r(7879),o=r(7056);class s extends n.j{constructor(){super(...arguments),this.registry=new o.O("fn"),this.functions={call:(e,...t)=>this.call(e,t)}}addFn(e){return this.registry.add(e)}getFn(e){return this.registry.get(e)}call(e,t){return this.registry.get(e)?.(...t)??"unknown"}}},7879:(e,t,r)=>{"use strict";r.d(t,{j:()=>o,y:()=>n});class n{constructor(e,t){this.result=null,this.runtime=e,this.func=t}use(e){this.runtime.copyScope(this.result??(this.result=this.func(this.runtime)),e)}}class o{constructor(e){this.variables={},this.functions={},this.runtime=e}use(e){Object.assign(e.variables,this.variables),Object.assign(e.functions,this.functions)}}},8201:(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{"use strict";__webpack_require__.d(__webpack_exports__,{L:()=>NodeJSLib});var _js__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(6416);class NodeJSLib extends _js__WEBPACK_IMPORTED_MODULE_0__.V{constructor(){super(...arguments),this.variables={js_env:"node",js_global:this.registry.add(globalThis)},this.functions={...this.functions,js_require:path=>this.toSS(eval("require")(path))}}}},6416:(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{"use strict";__webpack_require__.d(__webpack_exports__,{V:()=>JSLib});var ___WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(7879),_registry__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(7056),_array__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(5842),_fn__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(6855),_ref__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(7642),_struct__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(3126);const ssSymbol=Symbol("ss");class JSLib extends ___WEBPACK_IMPORTED_MODULE_4__.j{constructor(){super(...arguments),this.registry=new _registry__WEBPACK_IMPORTED_MODULE_5__.O("js"),this.functions={js:e=>this.js(e),js_get:(e,t)=>this.get(e,t),js_set:(e,t,r)=>this.set(e,t,r),js_new:(e,...t)=>this.new(e,t),js_object:()=>this.toSS({}),js_array:()=>this.toSS([]),js_call:(e,...t)=>this.call(e,t),js_call_method:(e,t,...r)=>this.callMethod(e,t,r)}}getObject(e){return this.registry.get(e)}toJSObject(e){if(e.startsWith("#js:"))return this.getObject(e);if(e.startsWith("#fn")){const t=this.runtime.getLib(_fn__WEBPACK_IMPORTED_MODULE_1__.a).getFn(e);if(!t)return;return(...e)=>this.toJS(t(...e.map((e=>this.toSS(e)))))}if(e.startsWith("#struct:")){const t=this.runtime.getLib(_struct__WEBPACK_IMPORTED_MODULE_3__.B).getStruct(e);if(!t)return;const r={};for(const e in t)r[e]=this.toJS(t[e]);return r}if(e.startsWith("#array:")){const t=this.runtime.getLib(_array__WEBPACK_IMPORTED_MODULE_0__.h).getArray(e);if(!t)return;return t.map((e=>this.toJS(e)))}return e}toJS(e){if(e.startsWith("#ref:"))return this.toJS(this.runtime.getLib(_ref__WEBPACK_IMPORTED_MODULE_2__.t).get(e));if("unknown"===e)return;if("false"===e)return!1;if("true"===e)return!0;if(/^-?[0-9]+(\.[0-9]+)?$/.test(e))return Number.parseFloat(e);const t=this.toJSObject(e);return t instanceof Object&&!t[ssSymbol]&&Object.defineProperty(t,ssSymbol,{value:e,enumerable:!1}),t}toSS(e){const t=e[ssSymbol];return void 0!==t?t:null==e||Number.isNaN(e)?"unknown":"string"==typeof e||e instanceof String||"boolean"==typeof e||e instanceof Boolean||"number"==typeof e||e instanceof Number?`${e}`:this.registry.add(e)}js(code){return this.toSS(eval(code))}get(e,t){const r=this.toJS(e)?.[t];return null==r?"unknown":this.toSS(r)}set(e,t,r){const n=this.toJS(e);return null!=n&&(n[t]=this.toJS(r)),"unknown"}new(e,t){const r=this.toJS(e);if(null==r)return"unknown";const n=new r(...t.map((e=>this.toJS(e))));return null==n?"unknown":this.toSS(n)}call(e,t){const r=this.toJS(e)?.(...t.map((e=>this.toJS(e))));return null==r?"unknown":this.toSS(r)}callMethod(e,t,r){const n=this.toJS(e)?.[t]?.(...r.map((e=>this.toJS(e))));return null==n?"unknown":this.toSS(n)}}},7642:(e,t,r)=>{"use strict";r.d(t,{t:()=>s});var n=r(7879),o=r(7056);class s extends n.j{constructor(){super(...arguments),this.registry=new o.O("ref"),this.functions={ref:e=>this.ref(e),ref_set:(e,t)=>this.set(e,t),ref_get:e=>this.get(e)}}ref(e){return this.registry.add(e)}set(e,t){return this.registry.set(e,t),"unknown"}get(e){return this.registry.get(e)??"unknown"}}},3126:(e,t,r)=>{"use strict";r.d(t,{B:()=>s});var n=r(7879),o=r(7056);class s extends n.j{constructor(){super(...arguments),this.registry=new o.O("struct"),this.functions={struct:()=>this.struct(),struct_set:(e,t,r)=>this.set(e,t,r),struct_get:(e,t)=>this.get(e,t)}}struct(){return this.registry.add({})}set(e,t,r){const n=this.registry.get(e);return n&&(n[t]=r),"unknown"}get(e,t){return this.registry.get(e)?.[t]??"unknown"}getStruct(e){return this.registry.get(e)}}},7056:(e,t,r)=>{"use strict";r.d(t,{O:()=>n});class n{constructor(e){this.elements={},this.id=-1,this.name=e}add(e){const t=`#${this.name}:${++this.id}`;return this.elements[t]=e,t}set(e,t){e in this.elements&&(this.elements[e]=t)}get(e){return this.elements[e]}}},9923:(e,t,r)=>{"use strict";r.d(t,{f:()=>p});var n=r(7879),o=r(6855),s=r(6416);var i=r(8201),a=r(7642);class l extends n.j{constructor(){super(...arguments),this.functions={string_at:(e,t)=>e.at(Number.parseInt(t))??"unknown",string_length:e=>`${e.length}`,string_slice:(e,t,r)=>e.slice(Number.parseInt(t),Number.parseInt(r)),string_replace:(e,t,r)=>e.replaceAll(t,r),string_format:(e,...t)=>this.format(e,t)}}format(e,t){if(0===t.length)return e;let r="";const n=e.length;let o=0,s=0;for(;o=t.length){r+=e.slice(o);break}continue}++o}r+=n}return r}}var c=r(3126),u=r(5842);function d(e){return(...t)=>{const r=e(...t.map((e=>Number.parseFloat(e))));return Number.isNaN(r)?"unknown":`${r}`}}class h extends n.j{constructor(){super(...arguments),this.variables={pi:`${Math.PI}`},this.functions={abs:d((e=>Math.abs(e))),sign:d((e=>Math.sign(e))),sqrt:d((e=>Math.sqrt(e))),mod:d(((e,t)=>e%t)),sin:d((e=>Math.sin(e))),cos:d((e=>Math.cos(e))),tan:d((e=>Math.tan(e))),asin:d((e=>Math.asin(e))),acos:d((e=>Math.acos(e))),atan:d(((e,t)=>null==t?Math.atan(e):Math.atan2(e,t))),sinh:d((e=>Math.sinh(e))),cosh:d((e=>Math.cosh(e))),tanh:d((e=>Math.tanh(e))),asinh:d((e=>Math.asinh(e))),acosh:d((e=>Math.acosh(e))),atanh:d((e=>Math.atanh(e))),exp:d((e=>Math.exp(e))),rad:d((e=>e*Math.PI/180)),deg:d((e=>180*e/Math.PI)),round:d(((e,t=1)=>Math.round(e/t)*t)),floor:d(((e,t=1)=>Math.floor(e/t)*t)),ceil:d(((e,t=1)=>Math.ceil(e/t)*t)),random:()=>`${Math.random()}`,randint:(e,t)=>this.randint(e,t)}}randint(e,t){const r=Number.parseFloat(e),n=Number.parseFloat(t),o=Math.min(r,n),s=Math.max(r,n);return`${Math.random()*(s-o)+o}`}}const p=new class{constructor(){this.libs={}}addLib(e,t){return this.libs[e]=t}getLib(e){return Object.values(this.libs).find((t=>t instanceof e))}lib(e,t){this.addLib(e,new n.y(this,t))}scope(e){const t={variables:{},functions:{}};return e&&this.copyScope(e,t),t}copyScope(e,t){Object.assign(t.variables,e.variables),Object.assign(t.functions,e.functions)}lambda(e){return this.getLib(o.a).addFn(e)}print(e){void 0===(e=this.getLib(s.V).toJS(e))&&(e="unknown"),console.log(e)}};p.addLib("fn",new o.a(p)),p.addLib("js",new i.L(p)),p.addLib("ref",new a.t(p)),p.addLib("string",new l(p)),p.addLib("struct",new c.B(p)),p.addLib("array",new u.h(p)),p.addLib("math",new h(p))},7101:(e,t,r)=>{"use strict";var n;r.d(t,{b:()=>T}),function(e){e.isWhitespace=function(e){return" "===e||"\n"===e||"\r"===e},e.isDigit=function(e){if(!e)return!1;const t=e.charCodeAt(0);return t>=48&&t<=57},e.isLetter=function(e){if(!e)return!1;const t=e.toLowerCase().charCodeAt(0);return t>=97&&t<=122}}(n||(n={}));class o{constructor(e){this.buffer=e,this._offset=0,this.line=0,this.column=0}get location(){return{offset:this._offset,line:this.line,column:this.column}}set location(e){this._offset=e.offset,this.line=e.line,this.column=e.column}get offset(){return this._offset}peekch(){return this.buffer[this._offset]}consume(){"\n"===this.peekch()?(++this.line,this.column=0):++this.column,++this._offset}}class s{constructor(e={},t){this.elements=e,this.last=t}with(e,t){const r={...this.elements};return r[e]=r[e]?[...r[e],t]:[t],new s(r,t)}has(e,t){return this.elements[e]?.includes(t)}}class i{}class a extends i{constructor(e){super(),this.ch=e}match(e){const t=e.location;if(e.peekch()===this.ch)return e.consume(),{start:t,end:e.location}}}class l extends i{constructor(e,t){super(),this.a=e,this.b=t}match(e,t,r=1,n=new s,o={}){const i=e.location,a=!(this.a instanceof m&&n.has(i.offset,this.a.name))&&this.a.match(e,t,r,n,o),l=e.location;e.location=i;const c=!(this.b instanceof m&&n.has(i.offset,this.b.name))&&this.b.match(e,t,r,n,o),u=e.location;let d=!a&&c||!c&&a;if(a&&c&&(d=l.offset>u.offset?a:c),d===a&&(e.location=l),d)return{start:i,end:e.location,children:[d]}}}class c extends i{match(e){const t=e.location;for(;n.isWhitespace(e.peekch());)e.consume();return{start:t,end:e.location}}}class u extends i{match(e){const t=e.location;if(e.peekch())return e.consume(),{start:t,end:e.location}}}class d extends i{match(e){const t=e.location;if(n.isDigit(e.peekch()))return e.consume(),{start:t,end:e.location}}}class h extends i{constructor(e){super(),this.pattern=e}match(e,t,r=1,n=new s,o={}){const i=e.location,a=this.pattern.match(e,t,r,n,o);return a||(e.location=i),{start:i,end:e.location,children:a?[a]:[]}}}class p extends i{constructor(e){super(),this.pattern=e}match(e,t,r=1,n=new s,o={}){const i=e.location;let a=this.pattern.match(e,t,r,n,o);const l=[a];if(!a)return;let c=e.location;for(;(a=this.pattern.match(e,t,r,n,o))&&c.offset!==e.offset;)l.push(a),c=e.location;return e.location=c,{start:i,end:e.location,children:l}}}class f extends i{constructor(e,t){super(),this.group=e,this.disallow=t}match(e){const t=e.location,r=e.peekch();if(!r)return;const n=r.charCodeAt(0);e.consume();for(const o of this.group)if(Array.isArray(o)&&n>=o[0].charCodeAt(0)&&n<=o[1].charCodeAt(0)||r===o)return!this.disallow&&{start:t,end:e.location};return this.disallow&&{start:t,end:e.location}}}class _ extends i{constructor(e){super(),this.children=e}match(e,t,r=1,n=new s,o={}){const i=e.location,a=[];for(const s of this.children){const i=s.match(e,t,r,n,o);if(!i)return;a.push(i)}return{start:i,end:e.location,children:a}}}class m extends i{constructor(e,t){super(),this.name=e,this.unmatched=t}match(e,t,r=1,n=new s,o={}){const i=`${r},${n.last},${e.offset},${this.name}`,a=o[i];if(void 0!==a)return a&&(e.location=a.end),a;const l=e.location;n=n.with(l.offset,this.name);const c=t.get(this.name);if(!c||c.precedence&&c.precedence0&&!Array.isArray(r.at(-1))){n=!0;continue}r.push(s)}if(n){n=!1;const e=r.pop();r.push([r.pop(),e])}}o.push(new f(r,t))}else if("."===s)o.push(new u);else if(" "===s)o.push(new c);else{if("|"===s&&o.length>0&&!i){i=!0;continue}"?"===s&&o.length>0?o.push(new h(o.pop())):"+"===s&&o.length>0?o.push(new p(o.pop())):o.push(new a(s))}}i&&(o.push(new l(o.pop(),o.pop())),i=!1)}const g=1===o.length?o[0]:new _(o);return g.precedence=t,g.preservePrecedence=r,g}function g(e,t,r){return y(new o(e),t,r)}class S{constructor(e,t,r,n){this.name=e,this.start=t,this.end=r,this.value=n,this.children=[]}get first(){return this.children[0]}get last(){return this.children.at(-1)}*[Symbol.iterator](){for(const e of this.children)yield e}addChild(e){this.children.push(e)}get(e){return this.children[e]}findChildren(e){return this.children.filter((t=>t.name===e))}findChild(e){return this.children.find((t=>t.name===e))}find(e){const t=this.findChild(e);if(t)return t;for(const t of this.children){const r=t.find(e);if(r)return r}}}class v{constructor(e){this.patterns=new Map,this.cache={};for(const[t,r]of Object.entries(e))"string"==typeof r?this.patterns.set(t,g(r)):this.patterns.set(t,g(r.pattern,r.precedence,r.preservePrecedence))}parse(e){const t=this.cache[e];if(void 0!==t)return t;const r=this.patterns.get("root").match(new o(e),this.patterns);if(!r)return;const n=new S("root",r.start,r.end,e.slice(r.start.offset,r.end.offset));return function t(r,n){if(r.name){const t=new S(r.name,r.start,r.end,e.slice(r.start.offset,r.end.offset));n.addChild(t),n=t}if(r.children)for(const e of r.children)t(e,n)}(r,n),n}}function w(e,t){return t.replace(/\.\.\./g,e)}function E(e,t){return e?t?"string"==typeof e&&"string"==typeof t?w(e,t):"string"==typeof e&&"string"!=typeof t?{...t,pattern:w(e,t.pattern)}:"string"!=typeof e&&"string"==typeof t?{...e,pattern:w(e.pattern,t)}:"string"!=typeof e&&"string"!=typeof t?{pattern:w(e.pattern,t.pattern),precedence:t.precedence??e.precedence,preservePrecedence:t.preservePrecedence??e.preservePrecedence}:void 0:e:t}var R=r(7879);const A={number:"%d+(%.%d+)?",name:"[a-zA-Z_][a-zA-Z0-9_]+?",string:'"([^"]|(\\\\)|(\\"))+?"',bool:"(true)|(false)",neg:"- %expr",add:{pattern:"%expr %+ %expr",precedence:5},sub:{pattern:"%expr - %expr",precedence:5},mul:{pattern:"%expr * %expr",precedence:6},div:{pattern:"%expr / %expr",precedence:6},concat:{pattern:"%expr @ %expr",precedence:1},eq:{pattern:"%expr = %expr",precedence:4},lt:{pattern:"%expr < %expr",precedence:4},gt:{pattern:"%expr > %expr",precedence:4},le:{pattern:"%expr <= %expr",precedence:4},ge:{pattern:"%expr >= %expr",precedence:4},or:{pattern:"%expr %| %expr",precedence:2},and:{pattern:"%expr & %expr",precedence:3},not:"! %expr",arglist:"(%expr( , %expr)+?)?",call:"%name %( %arglist %)",lambda:"%( %paramlist %) => ({ %body })|%expr",parenthesisexpr:"%( %expr %)",expr:{pattern:"%parenthesisexpr|%number|%string|%bool|%name|%neg|%add|%sub|%mul|%div|%concat|%eq|%lt|%gt|%le|%ge|%or|%and|%not|%call|%lambda",preservePrecedence:!0},assign:"%name = %expr;",paramlist:"(%name( , %name)+?)?",if:"if %expr { %body } %else?",else:"else { %body }",while:"while %expr { %body }",function:"fn %name %( %paramlist %) { %body }",return:"ret %expr;",callstat:"%call;",print:"print %expr;",statement:"%assign|%if|%while|%function|%return|%callstat|%print",comment:"//[^\n]+?",comments:"( %!comment )+?",body:"( %!comments %statement %!comments )+?",use:"use %name;",imports:"( %use %!comments )+?",lib:"lib %name;",root:"%!comments %lib? %!comments %imports %body %!comments"};class T{constructor(e,t={}){this.runtime=e,this.parser=new v(function(e,t){const r={root:E(e.root,t.root)};for(const n in e)n in r||(r[n]=E(e[n],t[n]));for(const n in t)n in r||(r[n]=E(e[n],t[n]));return r}(A,t))}compileExpr(e,t){switch("expr"===e.name&&(e=e.first),e.name){case"parenthesisexpr":return`(${this.compileExpr(e.first,t)})`;case"name":return`(scope${t}.variables.${e.value} ?? "unknown")`;case"number":case"bool":return`"${e.value}"`;case"string":return e.value;case"neg":return`\`\${-${this.compileExpr(e.first,t)}}\``;case"add":return`\`\${+${this.compileExpr(e.first,t)} + +${this.compileExpr(e.last,t)}}\``;case"sub":return`\`\${+${this.compileExpr(e.first,t)} - +${this.compileExpr(e.last,t)}}\``;case"mul":return`\`\${+${this.compileExpr(e.first,t)} * +${this.compileExpr(e.last,t)}}\``;case"div":return`\`\${+${this.compileExpr(e.first,t)} / +${this.compileExpr(e.last,t)}}\``;case"eq":return`\`\${${this.compileExpr(e.first,t)} === ${this.compileExpr(e.last,t)}}\``;case"lt":return`\`\${+${this.compileExpr(e.first,t)} < +${this.compileExpr(e.last,t)}}\``;case"gt":return`\`\${+${this.compileExpr(e.first,t)} > +${this.compileExpr(e.last,t)}}\``;case"le":return`\`\${+${this.compileExpr(e.first,t)} <= +${this.compileExpr(e.last,t)}}\``;case"ge":return`\`\${+${this.compileExpr(e.first,t)} >= +${this.compileExpr(e.last,t)}}\``;case"or":return`\`\${${this.compileExpr(e.first,t)} === "true" || ${this.compileExpr(e.last,t)} === "true"}\``;case"and":return`\`\${${this.compileExpr(e.first,t)} === "true" && ${this.compileExpr(e.last,t)} === "true"}\``;case"not":return`\`\${${this.compileExpr(e.first,t)} === "true" ? "false" : "true"}\``;case"concat":return`${this.compileExpr(e.first,t)} + ${this.compileExpr(e.last,t)}`;case"call":return`(${this.compileCall(e,t)} ?? "unknown")`;case"lambda":return`runtime.lambda(${e.findChild("expr")?this.compileLambda(e,t):this.compileFunction(e,t)})`}}compileCall(e,t){return`scope${t}.functions.${e.find("name").value}?.(${Array.from(e.find("arglist")).map((e=>this.compileExpr(e,t))).join(", ")})`}compileFunction(e,t){const r=Array.from(e.find("paramlist"));return`(${r.map(((e,t)=>`arg${t}="unknown"`)).join(", ")}) => {\n${this.localScope(++t)+r.map(((e,r)=>`scope${t}.variables.${e.value} = arg${r};\n`)).join("")+this.compileBody(e.find("body"),t)}return "unknown";\n}`}compileLambda(e,t){const r=Array.from(e.find("paramlist"));return`(${r.map(((e,t)=>`arg${t}="unknown"`)).join(", ")}) => {\n${this.localScope(++t)+r.map(((e,r)=>`scope${t}.variables.${e.value} = arg${r};\n`)).join("")}return ${this.compileExpr(e.find("expr"),t)};\n}`}compileStatement(e,t){switch(e.name){case"assign":return`scope${t}.variables.${e.find("name").value} = ${this.compileExpr(e.find("expr"),t)};`;case"if":{let r=`if ((${this.compileExpr(e.find("expr"),t)}) === "true") {\n${this.compileBody(e.find("body"),t)}}`;const n=e.findChild("else");return n&&(r+=`\nelse {\n${this.compileBody(n.find("body"),t)}}`),r}case"while":return`while ((${this.compileExpr(e.find("expr"),t)}) === "true") {\n${this.compileBody(e.find("body"),t)}}`;case"function":return`scope${t}.functions.${e.find("name").value} = ${this.compileFunction(e,t)};`;case"print":return`runtime.print(${this.compileExpr(e.find("expr"),t)});`;case"callstat":return this.compileCall(e.first,t)+";";case"return":return`return ${this.compileExpr(e.find("expr"),t)};`}}compileBody(e,t=0){let r="";for(const{first:n}of e)r+=this.compileStatement(n,t)+"\n";return r}localScope(e){return`const scope${e} = runtime.scope(scope${e-1});\n`}globalScope(){return"const scope0 = runtime.scope();\n"}compileImports(e){let t="";for(const r of e)t+=`runtime.libs.${r.find("name").value}?.use(scope0);\n`;return t}compileProgram(e){let t=this.globalScope();return t+=this.compileImports(e.find("imports")),t+=this.compileBody(e.find("body")),t+="return scope0;\n",t}createFunction(e){return Function("runtime",this.compileProgram(e))}getLibName(e){return this.parser.parse(e)?.findChild("lib")?.find("name")?.value}compile(e){const t=this.parser.parse(e);if(t&&t.end.offset===e.length)return this.compileProgram(t)}load(e){const t=this.parser.parse(e);if(!t||t.end.offset!==e.length)return;const r=t.findChild("lib"),n=this.createFunction(t);if(!r)return n(this.runtime);this.runtime.addLib(r.find("name").value,new R.y(this.runtime,n))}}},2921:(e,t,r)=>{"use strict";r.d(t,{x:()=>i});var n=r(7101);const o={htmlname:"[a-z0-9-]+",htmlattrval:"%string|({ %expr })",htmlattr:"%htmlname=%htmlattrval",htmlentity:"&%htmlname;",htmltext:"([^&<>{}])+",htmlcontent:"(%htmltext|%htmlentity|({ %expr })|%html)+?",htmlsingle:"<%htmlname( %htmlattr )+? />",htmlpaired:"<%htmlname( %htmlattr )+?>%htmlcontent",html:"%htmlsingle|%htmlpaired",expr:"...|%html",component:"fn <%htmlname( %htmlattr )+?> { %body }",statement:"...|%component"},s={amp:"&",lt:"<",gt:">"};class i extends n.b{constructor(e){super(e,o)}compileHTMLContent(e,t){const r=[];for(const n of e)switch(n.name){case"htmltext":r.push(JSON.stringify(n.value));break;case"htmlentity":r.push(`"${s[n.find("htmlname").value]??n.value}"`);break;case"expr":case"html":r.push(this.compileExpr(n,t))}switch(r.length){case 0:return'"unknown"';case 1:return r[0];default:return`runtime.ssxGroup(${r.join(", ")})`}}compileExpr(e,t){if("expr"===e.name&&(e=e.first),"html"===e.name){const r="htmlpaired"===(e=e.first).name,n=e.first.value;return r&&e.last.value!==n?'"unknown"':`runtime.ssx(scope${t}, "${n}", { ${e.findChildren("htmlattr").map((e=>`"${e.find("htmlname").value}": ${this.compileExpr(e.find("htmlattrval").first,t)}`)).join(", ")} }, ${this.compileHTMLContent(e.findChild("htmlcontent"),t)})`}return super.compileExpr(e,t)}compileStatement(e,t){if("component"===e.name){const r={};for(const n of e.findChildren("htmlattr"))r[n.find("htmlname").value]=this.compileExpr(n.find("htmlattrval").first,t);return`scope${t}.components["${e.find("htmlname").value}"] = (attrs, children) => {\n${this.localScope(++t)}scope${t}.variables.children = children;\n${Object.keys(r).map((e=>`scope${t}.variables.${e} = attrs.${e} ?? ${r[e]};\n`)).join("")+this.compileBody(e.find("body"),t)}return "unknown";\n};`}return super.compileStatement(e,t)}}},5010:function(e,t){ /** * @license * web-streams-polyfill v3.3.3 diff --git a/package.json b/package.json index f9d742f..3d3e4da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sigmascript", - "version": "1.2.2", + "version": "1.2.3", "description": "Programming language made for sigma males", "main": "index.js", "scripts": { diff --git a/src/sigmascript/lib/js.ts b/src/sigmascript/lib/js.ts index d34a8f3..6fa5c9a 100644 --- a/src/sigmascript/lib/js.ts +++ b/src/sigmascript/lib/js.ts @@ -64,10 +64,10 @@ export class JSLib extends NativeLib { toSS(value: any): string { const ssValue = value[ssSymbol]; if (ssValue !== undefined) return ssValue; + if (value == null || Number.isNaN(value)) return "unknown"; if (typeof value === "string" || value instanceof String || typeof value === "boolean" || value instanceof Boolean || - Number.isInteger(value)) return `${value}`; - if (value == null || Number.isNaN(value)) return "unknown"; + typeof value === "number" || value instanceof Number) return `${value}`; return this.registry.add(value); }