just-bash 2.4.4 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +42 -4
  2. package/dist/AGENTS.md +2 -2
  3. package/dist/bin/chunks/base64-O7TCK5TL.js +6 -0
  4. package/dist/bin/{shell/chunks/cat-ZEMMQGY5.js → chunks/cat-AJXZOSPN.js} +1 -1
  5. package/dist/bin/chunks/{chunk-45SNFRCY.js → chunk-5WFYIUU2.js} +2 -2
  6. package/dist/bin/chunks/chunk-X4WRNADE.js +17 -0
  7. package/dist/bin/{shell/chunks/chunk-GX4MPCG6.js → chunks/chunk-Y5QKO4KO.js} +5 -5
  8. package/dist/bin/chunks/{cut-WWPJ2PYT.js → cut-IHF6BEOO.js} +1 -1
  9. package/dist/bin/chunks/grep-WDHYDUUD.js +9 -0
  10. package/dist/bin/{shell/chunks/gzip-MNCJB6OR.js → chunks/gzip-YXK3WZQL.js} +22 -22
  11. package/dist/bin/{shell/chunks/jq-XH2PXRWE.js → chunks/jq-XXZPU5CA.js} +1 -1
  12. package/dist/bin/chunks/{md5sum-VGXAOUBA.js → md5sum-2VAAFCTS.js} +1 -1
  13. package/dist/bin/chunks/rg-ALK3CYAN.js +29 -0
  14. package/dist/bin/chunks/{sha1sum-BIUH233Z.js → sha1sum-67P4ME4N.js} +1 -1
  15. package/dist/bin/{shell/chunks/sha256sum-SUIK2MT2.js → chunks/sha256sum-MV3WQ4QF.js} +1 -1
  16. package/dist/bin/{shell/chunks/sort-C3F6LCNY.js → chunks/sort-KUHOCH5S.js} +1 -1
  17. package/dist/bin/chunks/tar-C27YYUAS.js +63 -0
  18. package/dist/bin/{shell/chunks/uniq-DKS7RIAE.js → chunks/uniq-IXHB2FVS.js} +1 -1
  19. package/dist/bin/chunks/{wc-4LMTC3QD.js → wc-QSBRKIF5.js} +1 -1
  20. package/dist/bin/chunks/{xan-WNN2ZOAX.js → xan-6K2NGTHM.js} +1 -1
  21. package/dist/bin/just-bash.js +78 -78
  22. package/dist/bin/shell/chunks/base64-O7TCK5TL.js +6 -0
  23. package/dist/bin/{chunks/cat-ZEMMQGY5.js → shell/chunks/cat-AJXZOSPN.js} +1 -1
  24. package/dist/bin/shell/chunks/{chunk-45SNFRCY.js → chunk-5WFYIUU2.js} +2 -2
  25. package/dist/bin/shell/chunks/chunk-X4WRNADE.js +17 -0
  26. package/dist/bin/{chunks/chunk-GX4MPCG6.js → shell/chunks/chunk-Y5QKO4KO.js} +5 -5
  27. package/dist/bin/shell/chunks/{cut-WWPJ2PYT.js → cut-IHF6BEOO.js} +1 -1
  28. package/dist/bin/shell/chunks/grep-WDHYDUUD.js +9 -0
  29. package/dist/bin/{chunks/gzip-MNCJB6OR.js → shell/chunks/gzip-YXK3WZQL.js} +22 -22
  30. package/dist/bin/{chunks/jq-XH2PXRWE.js → shell/chunks/jq-XXZPU5CA.js} +1 -1
  31. package/dist/bin/shell/chunks/{md5sum-VGXAOUBA.js → md5sum-2VAAFCTS.js} +1 -1
  32. package/dist/bin/shell/chunks/rg-ALK3CYAN.js +29 -0
  33. package/dist/bin/shell/chunks/{sha1sum-BIUH233Z.js → sha1sum-67P4ME4N.js} +1 -1
  34. package/dist/bin/{chunks/sha256sum-SUIK2MT2.js → shell/chunks/sha256sum-MV3WQ4QF.js} +1 -1
  35. package/dist/bin/{chunks/sort-C3F6LCNY.js → shell/chunks/sort-KUHOCH5S.js} +1 -1
  36. package/dist/bin/shell/chunks/tar-C27YYUAS.js +63 -0
  37. package/dist/bin/{chunks/uniq-DKS7RIAE.js → shell/chunks/uniq-IXHB2FVS.js} +1 -1
  38. package/dist/bin/shell/chunks/{wc-4LMTC3QD.js → wc-QSBRKIF5.js} +1 -1
  39. package/dist/bin/shell/chunks/{xan-WNN2ZOAX.js → xan-6K2NGTHM.js} +1 -1
  40. package/dist/bin/shell/shell.js +100 -100
  41. package/dist/bundle/browser.js +542 -506
  42. package/dist/bundle/chunks/base64-3BME25ON.js +5 -0
  43. package/dist/bundle/chunks/{cat-W5XITXDC.js → cat-MV4K6AUA.js} +1 -1
  44. package/dist/bundle/chunks/{chunk-4ACWXGKW.js → chunk-7L36YK2X.js} +2 -2
  45. package/dist/bundle/chunks/chunk-7VH6U2UX.js +16 -0
  46. package/dist/bundle/chunks/{chunk-46TSKXFW.js → chunk-GFLIVSUW.js} +5 -5
  47. package/dist/bundle/chunks/{cut-KKAAQJVD.js → cut-NVKWEAZF.js} +1 -1
  48. package/dist/bundle/chunks/grep-QVR5G7SC.js +8 -0
  49. package/dist/bundle/chunks/{gzip-7QAS5P2Y.js → gzip-L3NDJG3F.js} +22 -22
  50. package/dist/bundle/chunks/{jq-AAWVUTC4.js → jq-3YU5HRKE.js} +1 -1
  51. package/dist/bundle/chunks/{md5sum-LJHKXLVT.js → md5sum-KLHZSRUA.js} +1 -1
  52. package/dist/bundle/chunks/rg-43HLKW4V.js +28 -0
  53. package/dist/bundle/chunks/{sha1sum-NRUZZ4Q6.js → sha1sum-WKWTIZGQ.js} +1 -1
  54. package/dist/bundle/chunks/{sha256sum-5ZGJ4NJL.js → sha256sum-IUVNMBTA.js} +1 -1
  55. package/dist/bundle/chunks/{sort-JHO22QVO.js → sort-EJUT5LXD.js} +1 -1
  56. package/dist/bundle/chunks/tar-QWBXMF7K.js +62 -0
  57. package/dist/bundle/chunks/{uniq-SEKCFR7B.js → uniq-47QVBRNC.js} +1 -1
  58. package/dist/bundle/chunks/{wc-52FZ4QGS.js → wc-DFQKWSIZ.js} +1 -1
  59. package/dist/bundle/chunks/{xan-ZHXYF6B4.js → xan-2R2APJJ4.js} +1 -1
  60. package/dist/bundle/index.js +119 -119
  61. package/dist/commands/registry.d.ts +1 -1
  62. package/dist/commands/rg/file-types.d.ts +23 -0
  63. package/dist/commands/rg/gitignore.d.ts +69 -0
  64. package/dist/commands/rg/rg-options.d.ts +47 -0
  65. package/dist/commands/rg/rg-parser.d.ts +20 -0
  66. package/dist/commands/rg/rg-search.d.ts +15 -0
  67. package/dist/commands/rg/rg.d.ts +12 -0
  68. package/dist/commands/search-engine/index.d.ts +10 -0
  69. package/dist/commands/search-engine/matcher.d.ts +57 -0
  70. package/dist/commands/search-engine/regex.d.ts +17 -0
  71. package/dist/commands/tar/archive.d.ts +107 -0
  72. package/dist/commands/tar/tar.d.ts +8 -0
  73. package/dist/index.d.ts +1 -0
  74. package/package.json +11 -5
  75. package/dist/bin/chunks/base64-RJX7MYGG.js +0 -6
  76. package/dist/bin/chunks/grep-U2RCKOEG.js +0 -15
  77. package/dist/bin/shell/chunks/base64-RJX7MYGG.js +0 -6
  78. package/dist/bin/shell/chunks/grep-U2RCKOEG.js +0 -15
  79. package/dist/bundle/chunks/base64-F5R4G5EG.js +0 -5
  80. package/dist/bundle/chunks/grep-CTJRP2G3.js +0 -14
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{a as $e,b as w,c as v,d as H,e as J}from"./chunk-UUQYHLBO.js";import{a as Ge}from"./chunk-QSDVMMYI.js";import{a as P}from"./chunk-ACRTDIBO.js";import"./chunk-NWWB2XRE.js";import{a as Re}from"./chunk-45SNFRCY.js";import"./chunk-OBH7XN5N.js";import{a as $,b as _}from"./chunk-GTNBSMZR.js";import{b as He,d as Je,e as ze,f as Ke}from"./chunk-KGOUQS5A.js";var Te={};Je(Te,{parseMoonblade:()=>V,parseNamedExpressions:()=>T});function T(e){let n=[],s=new W(e).tokenize(),r=0,o=()=>s[r]||{type:"eof",value:"",pos:0},a=()=>s[r++];for(;o().type!=="eof";){if(o().type===","&&n.length>0){a();continue}let d=[],u=0,p=r;for(;o().type!=="eof";){let i=o();if((i.type===","||i.type==="as")&&u===0)break;(i.type==="("||i.type==="["||i.type==="{")&&u++,(i.type===")"||i.type==="]"||i.type==="}")&&u--,d.push(a())}d.push({type:"eof",value:"",pos:0});let h=new U(d).parse(),c;if(o().type==="as")if(a(),o().type==="("){a();let i=[];for(;o().type!==")"&&o().type!=="eof";)(o().type==="ident"||o().type==="string")&&(i.push(o().value),a()),o().type===","&&a();o().type===")"&&a(),c=i}else if(o().type==="ident"||o().type==="string")c=o().value,a();else throw new Error(`Expected name after 'as', got ${o().type}`);else c=e.slice(s[p].pos,s[r-1]?.pos||e.length).trim(),h.type==="identifier"&&(c=h.name);n.push({expr:h,name:c})}return n}function V(e){let t=new W(e).tokenize();return new U(t).parse()}var W,O,U,j=He(()=>{"use strict";W=class{input;pos=0;tokens=[];constructor(n){this.input=n}tokenize(){for(;this.pos<this.input.length&&(this.skipWhitespace(),!(this.pos>=this.input.length));){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos<this.input.length;){let n=this.input[this.pos];if(n===" "||n===" "||n===`
2
+ import{a as $e,b as w,c as v,d as H,e as J}from"./chunk-UUQYHLBO.js";import{a as Ge}from"./chunk-QSDVMMYI.js";import{a as P}from"./chunk-ACRTDIBO.js";import"./chunk-NWWB2XRE.js";import{a as Re}from"./chunk-5WFYIUU2.js";import"./chunk-OBH7XN5N.js";import{a as $,b as _}from"./chunk-GTNBSMZR.js";import{b as He,d as Je,e as ze,f as Ke}from"./chunk-KGOUQS5A.js";var Te={};Je(Te,{parseMoonblade:()=>V,parseNamedExpressions:()=>T});function T(e){let n=[],s=new W(e).tokenize(),r=0,o=()=>s[r]||{type:"eof",value:"",pos:0},a=()=>s[r++];for(;o().type!=="eof";){if(o().type===","&&n.length>0){a();continue}let d=[],u=0,p=r;for(;o().type!=="eof";){let i=o();if((i.type===","||i.type==="as")&&u===0)break;(i.type==="("||i.type==="["||i.type==="{")&&u++,(i.type===")"||i.type==="]"||i.type==="}")&&u--,d.push(a())}d.push({type:"eof",value:"",pos:0});let h=new U(d).parse(),c;if(o().type==="as")if(a(),o().type==="("){a();let i=[];for(;o().type!==")"&&o().type!=="eof";)(o().type==="ident"||o().type==="string")&&(i.push(o().value),a()),o().type===","&&a();o().type===")"&&a(),c=i}else if(o().type==="ident"||o().type==="string")c=o().value,a();else throw new Error(`Expected name after 'as', got ${o().type}`);else c=e.slice(s[p].pos,s[r-1]?.pos||e.length).trim(),h.type==="identifier"&&(c=h.name);n.push({expr:h,name:c})}return n}function V(e){let t=new W(e).tokenize();return new U(t).parse()}var W,O,U,j=He(()=>{"use strict";W=class{input;pos=0;tokens=[];constructor(n){this.input=n}tokenize(){for(;this.pos<this.input.length&&(this.skipWhitespace(),!(this.pos>=this.input.length));){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos<this.input.length;){let n=this.input[this.pos];if(n===" "||n===" "||n===`
3
3
  `||n==="\r")this.pos++;else if(n==="#")for(;this.pos<this.input.length&&this.input[this.pos]!==`
4
4
  `;)this.pos++;else break}}nextToken(){let n=this.pos,t=this.input[this.pos];if(t>="0"&&t<="9")return this.readNumber();if(t==='"'||t==="'"||t==="`")return this.readString(t);if(t==="b"&&this.pos+1<this.input.length){let r=this.input[this.pos+1];if(r==='"'||r==="'"||r==="`")return this.pos++,this.readString(r)}if(t==="/"){let r=this.tokens[this.tokens.length-1];return r&&(r.type==="int"||r.type==="float"||r.type==="string"||r.type==="ident"||r.type===")"||r.type==="]")?this.input[this.pos+1]==="/"?(this.pos+=2,{type:"//",value:"//",pos:n}):(this.pos++,{type:"/",value:"/",pos:n}):this.readRegex()}if(this.match("not in"))return{type:"not in",value:"not in",pos:n};if(this.match("=>"))return{type:"=>",value:"=>",pos:n};if(this.match("**"))return{type:"**",value:"**",pos:n};if(this.match("++"))return{type:"++",value:"++",pos:n};if(this.match("//"))return{type:"//",value:"//",pos:n};if(this.match("=="))return{type:"==",value:"==",pos:n};if(this.match("!="))return{type:"!=",value:"!=",pos:n};if(this.match("<="))return{type:"<=",value:"<=",pos:n};if(this.match(">="))return{type:">=",value:">=",pos:n};if(this.match("&&"))return{type:"&&",value:"&&",pos:n};if(this.match("||"))return{type:"||",value:"||",pos:n};let s={"(":"(",")":")","[":"[","]":"]","{":"{","}":"}",",":",",":":":",";":";","+":"+","-":"-","*":"*","%":"%","<":"<",">":">","!":"!",".":".","|":"|","=":"="};if(t in s)return this.pos++,{type:s[t],value:t,pos:n};if(this.isIdentStart(t))return this.readIdentifier();throw new Error(`Unexpected character '${t}' at position ${this.pos}`)}match(n){if(this.input.slice(this.pos,this.pos+n.length)===n){if(/^[a-zA-Z]/.test(n)){let t=this.input[this.pos+n.length];if(t&&this.isIdentChar(t))return!1}return this.pos+=n.length,!0}return!1}isIdentStart(n){return n>="a"&&n<="z"||n>="A"&&n<="Z"||n==="_"}isIdentChar(n){return this.isIdentStart(n)||n>="0"&&n<="9"}readNumber(){let n=this.pos,t=!1,s=!1;for(;this.pos<this.input.length;){let o=this.input[this.pos];if(o>="0"&&o<="9")this.pos++;else if(o==="_")this.pos++;else if(o==="."&&!t&&!s)t=!0,this.pos++;else if((o==="e"||o==="E")&&!s)s=!0,t=!0,this.pos++,this.pos<this.input.length&&(this.input[this.pos]==="+"||this.input[this.pos]==="-")&&this.pos++;else break}let r=this.input.slice(n,this.pos).replace(/_/g,"");return{type:t?"float":"int",value:r,pos:n}}readString(n){let t=this.pos;this.pos++;let s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r===n)return this.pos++,{type:"string",value:s,pos:t};if(r==="\\"){if(this.pos++,this.pos<this.input.length){let o=this.input[this.pos];switch(o){case"n":s+=`
5
5
  `;break;case"r":s+="\r";break;case"t":s+=" ";break;case"\\":s+="\\";break;case'"':s+='"';break;case"'":s+="'";break;case"`":s+="`";break;case"0":s+="\0";break;default:s+=o}this.pos++}}else s+=r,this.pos++}throw new Error(`Unterminated string starting at position ${t}`)}readRegex(){let n=this.pos;this.pos++;let t="",s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r==="/"){for(this.pos++;this.pos<this.input.length&&this.input[this.pos]==="i";)s+=this.input[this.pos],this.pos++;return{type:"regex",value:t+(s?`/${s}`:""),pos:n}}r==="\\"?(t+=r,this.pos++,this.pos<this.input.length&&(t+=this.input[this.pos],this.pos++)):(t+=r,this.pos++)}throw new Error(`Unterminated regex starting at position ${n}`)}readIdentifier(){let n=this.pos;for(;this.pos<this.input.length&&this.isIdentChar(this.input[this.pos]);)this.pos++;let t=!1;this.pos<this.input.length&&this.input[this.pos]==="?"&&(t=!0,this.pos++);let s=this.input.slice(n,t?this.pos-1:this.pos);t&&(s+="?");let r={true:"true",false:"false",null:"null",and:"and",or:"or",eq:"eq",ne:"ne",lt:"lt",le:"le",gt:"gt",ge:"ge",in:"in",as:"as",_:"_"},o=s.replace(/\?$/,"");return o in r&&!t?{type:r[o],value:o,pos:n}:{type:"ident",value:s,pos:n}}},O={PIPE:1,OR:2,AND:3,EQUALITY:4,COMPARISON:5,ADDITIVE:6,MULTIPLICATIVE:7,POWER:8,UNARY:9,POSTFIX:10},U=class{pos=0;tokens;constructor(n){this.tokens=n}parse(){let n=this.parseExpr(0);if(this.peek().type!=="eof")throw new Error(`Unexpected token: ${this.peek().value}`);return n}parseExpr(n){let t=this.parsePrefix();for(;;){let s=this.peek(),r=this.getInfixPrec(s.type);if(r<n)break;t=this.parseInfix(t,r)}return t}parsePrefix(){let n=this.peek();switch(n.type){case"int":return this.advance(),{type:"int",value:Number.parseInt(n.value,10)};case"float":return this.advance(),{type:"float",value:Number.parseFloat(n.value)};case"string":return this.advance(),{type:"string",value:n.value};case"regex":{this.advance();let t=n.value.split("/"),s=t.length>1?t[t.length-1]:"";return{type:"regex",pattern:t.slice(0,-1).join("/")||n.value,caseInsensitive:s.includes("i")}}case"true":return this.advance(),{type:"bool",value:!0};case"false":return this.advance(),{type:"bool",value:!1};case"null":return this.advance(),{type:"null"};case"_":return this.advance(),{type:"underscore"};case"ident":{let t=n.value,s=t.endsWith("?"),r=s?t.slice(0,-1):t;if(this.advance(),this.peek().type==="(")return this.parseFunctionCall(r);if(this.peek().type==="=>"){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:[r],body:o},[r])}return{type:"identifier",name:r,unsure:s}}case"(":{this.advance();let t=[];if(this.peek().type===")"){if(this.advance(),this.peek().type==="=>"){this.advance();let r=this.parseExpr(0);return{type:"lambda",params:[],body:r}}throw new Error("Empty parentheses not allowed")}if(this.peek().type==="ident"){let r=this.peek().value;if(this.advance(),this.peek().type===","||this.peek().type===")"){for(t.push(r);this.peek().type===","&&(this.advance(),this.peek().type==="ident");)t.push(this.peek().value),this.advance();if(this.peek().type===")"&&(this.advance(),this.peek().type==="=>")){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:t,body:o},t)}this.pos-=t.length*2,t.length>1&&(this.pos=this.pos)}this.pos--}let s=this.parseExpr(0);return this.expect(")"),this.peek().type,s}case"[":return this.parseList();case"{":return this.parseMap();case"-":{this.advance();let t=this.parseExpr(O.UNARY);return t.type==="int"?{type:"int",value:-t.value}:t.type==="float"?{type:"float",value:-t.value}:{type:"func",name:"neg",args:[{expr:t}]}}case"!":return this.advance(),{type:"func",name:"not",args:[{expr:this.parseExpr(O.UNARY)}]};default:throw new Error(`Unexpected token: ${n.type} (${n.value})`)}}parseFunctionCall(n){this.expect("(");let t=[];if(this.peek().type!==")")do{t.length>0&&this.peek().type===","&&this.advance();let s;if(this.peek().type==="ident"){let o=this.peek().value,a=this.pos+1;a<this.tokens.length&&this.tokens[a].type==="="&&(s=o,this.advance(),this.advance())}let r=this.parseExpr(0);t.push({name:s,expr:r})}while(this.peek().type===",");return this.expect(")"),{type:"func",name:n.toLowerCase(),args:t}}parseList(){this.expect("[");let n=[];if(this.peek().type!=="]")do n.length>0&&this.peek().type===","&&this.advance(),n.push(this.parseExpr(0));while(this.peek().type===",");return this.expect("]"),{type:"list",elements:n}}parseMap(){this.expect("{");let n=[];if(this.peek().type!=="}")do{n.length>0&&this.peek().type===","&&this.advance();let t;if(this.peek().type==="ident")t=this.peek().value,this.advance();else if(this.peek().type==="string")t=this.peek().value,this.advance();else throw new Error(`Expected map key, got ${this.peek().type}`);this.expect(":");let s=this.parseExpr(0);n.push({key:t,value:s})}while(this.peek().type===",");return this.expect("}"),{type:"map",entries:n}}parseInfix(n,t){let s=this.peek(),r={"+":"add","-":"sub","*":"mul","/":"div","//":"idiv","%":"mod","**":"pow","++":"concat","==":"==","!=":"!=","<":"<","<=":"<=",">":">",">=":">=",eq:"eq",ne:"ne",lt:"lt",le:"le",gt:"gt",ge:"ge","&&":"and",and:"and","||":"or",or:"or"};if(s.type in r){this.advance();let o=this.parseExpr(t+(this.isRightAssoc(s.type)?0:1));return{type:"func",name:r[s.type],args:[{expr:n},{expr:o}]}}if(s.type==="|"){this.advance();let o=this.parseExpr(t);return this.handlePipe(n,o)}if(s.type===".")return this.advance(),this.handleDot(n);if(s.type==="[")return this.advance(),this.handleIndexing(n);if(s.type==="in")return this.advance(),{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]};if(s.type==="not in")return this.advance(),{type:"func",name:"not",args:[{expr:{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]}}]};throw new Error(`Unexpected infix token: ${s.type}`)}handlePipe(n,t){if(t.type==="identifier")return{type:"func",name:t.name,args:[{expr:n}]};if(t.type==="func"){let s=this.countUnderscores(t);return s===0?t:s===1?this.fillUnderscore(t,n):{type:"pipeline",exprs:[n,t]}}return this.countUnderscores(t)===1?this.fillUnderscore(t,n):t}handleDot(n){let t=this.peek();if(t.type==="ident"){let s=t.value;if(this.advance(),this.peek().type==="("){let r=this.parseFunctionCall(s);return r.type==="func"&&r.args.unshift({expr:n}),r}return{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}if(t.type==="int"){let s=Number.parseInt(t.value,10);return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"int",value:s}}]}}if(t.type==="string"){let s=t.value;return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}throw new Error(`Expected identifier, number, or string after dot, got ${t.type}`)}handleIndexing(n){if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:{type:"int",value:0}},{expr:s}]}}let t=this.parseExpr(0);if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n},{expr:t}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:t},{expr:s}]}}return this.expect("]"),{type:"func",name:"get",args:[{expr:n},{expr:t}]}}countUnderscores(n){return n.type==="underscore"?1:n.type==="func"?n.args.reduce((t,s)=>t+this.countUnderscores(s.expr),0):n.type==="list"?n.elements.reduce((t,s)=>t+this.countUnderscores(s),0):n.type==="map"?n.entries.reduce((t,s)=>t+this.countUnderscores(s.value),0):0}fillUnderscore(n,t){return n.type==="underscore"?t:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.fillUnderscore(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.fillUnderscore(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.fillUnderscore(s.value,t)}))}:n}bindLambdaArgs(n,t){return{...n,body:this.bindLambdaArgsInExpr(n.body,t)}}bindLambdaArgsInExpr(n,t){return n.type==="identifier"&&t.includes(n.name)?{type:"lambdaBinding",name:n.name}:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.bindLambdaArgsInExpr(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.bindLambdaArgsInExpr(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.bindLambdaArgsInExpr(s.value,t)}))}:n}getInfixPrec(n){switch(n){case"|":return O.PIPE;case"||":case"or":return O.OR;case"&&":case"and":return O.AND;case"==":case"!=":case"eq":case"ne":return O.EQUALITY;case"<":case"<=":case">":case">=":case"lt":case"le":case"gt":case"ge":case"in":case"not in":return O.COMPARISON;case"+":case"-":case"++":return O.ADDITIVE;case"*":case"/":case"//":case"%":return O.MULTIPLICATIVE;case"**":return O.POWER;case".":case"[":return O.POSTFIX;default:return-1}}isRightAssoc(n){return n==="**"}peek(){return this.tokens[this.pos]||{type:"eof",value:"",pos:0}}advance(){return this.tokens[this.pos++]}expect(n){let t=this.peek();if(t.type!==n)throw new Error(`Expected ${n}, got ${t.type}`);return this.advance()}}});j();function N(e,n){return n.length===0?I(e,[]):n.length===1?{type:"Pipe",left:n[0],right:I(e,[])}:{type:"Pipe",left:n[0],right:I(e,n.slice(1))}}var De={add:e=>b("+",e[0],e[1]),sub:e=>b("-",e[0],e[1]),mul:e=>b("*",e[0],e[1]),div:e=>b("/",e[0],e[1]),mod:e=>b("%",e[0],e[1]),idiv:e=>I("floor",[b("/",e[0],e[1])]),pow:e=>N("pow",e),neg:e=>({type:"UnaryOp",op:"-",operand:e[0]}),"==":e=>b("==",e[0],e[1]),"!=":e=>b("!=",e[0],e[1]),"<":e=>b("<",e[0],e[1]),"<=":e=>b("<=",e[0],e[1]),">":e=>b(">",e[0],e[1]),">=":e=>b(">=",e[0],e[1]),eq:e=>b("==",L(e[0]),L(e[1])),ne:e=>b("!=",L(e[0]),L(e[1])),lt:e=>b("<",L(e[0]),L(e[1])),le:e=>b("<=",L(e[0]),L(e[1])),gt:e=>b(">",L(e[0]),L(e[1])),ge:e=>b(">=",L(e[0]),L(e[1])),and:e=>b("and",e[0],e[1]),or:e=>b("or",e[0],e[1]),not:e=>({type:"UnaryOp",op:"not",operand:e[0]}),len:e=>N("length",e),length:e=>N("length",e),upper:e=>N("ascii_upcase",e),lower:e=>N("ascii_downcase",e),trim:e=>N("trim",e),ltrim:e=>e.length===0?I("ltrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:I("ltrimstr",[{type:"Literal",value:" "}])},rtrim:e=>e.length===0?I("rtrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:I("rtrimstr",[{type:"Literal",value:" "}])},split:e=>N("split",e),join:e=>e.length===1?I("join",[{type:"Literal",value:""}]):N("join",e),concat:e=>b("+",e[0],e[1]),startswith:e=>N("startswith",e),endswith:e=>N("endswith",e),contains:e=>N("contains",e),replace:e=>N("gsub",e),substr:e=>e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:b("+",e[1],e[2])},abs:e=>N("fabs",e),floor:e=>N("floor",e),ceil:e=>N("ceil",e),round:e=>N("round",e),sqrt:e=>N("sqrt",e),log:e=>N("log",e),log10:e=>N("log10",e),log2:e=>N("log2",e),exp:e=>N("exp",e),sin:e=>N("sin",e),cos:e=>N("cos",e),tan:e=>N("tan",e),asin:e=>N("asin",e),acos:e=>N("acos",e),atan:e=>N("atan",e),min:e=>N("min",e),max:e=>N("max",e),first:e=>e.length===0?{type:"Index",index:{type:"Literal",value:0}}:{type:"Index",index:{type:"Literal",value:0},base:e[0]},last:e=>e.length===0?{type:"Index",index:{type:"Literal",value:-1}}:{type:"Index",index:{type:"Literal",value:-1},base:e[0]},get:e=>e.length===1?{type:"Index",index:e[0]}:{type:"Index",index:e[1],base:e[0]},slice:e=>e.length===1?{type:"Slice",base:e[0]}:e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:e[2]},keys:"keys",values:"values",entries:e=>I("to_entries",e),from_entries:"from_entries",reverse:"reverse",sort:"sort",sort_by:"sort_by",group_by:"group_by",unique:"unique",unique_by:"unique_by",flatten:"flatten",map:e=>({type:"Pipe",left:e[0],right:{type:"Array",elements:e[1]}}),select:e=>I("select",e),empty:()=>I("empty",[]),count:()=>I("length",[]),sum:e=>e.length===0?I("add",[]):{type:"Pipe",left:{type:"Array",elements:e[0]},right:I("add",[])},mean:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:b("/",I("add",[]),I("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:b("/",I("add",[]),I("length",[]))},avg:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:b("/",I("add",[]),I("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:b("/",I("add",[]),I("length",[]))},type:"type",isnull:e=>e.length===0?b("==",{type:"Identity"},{type:"Literal",value:null}):b("==",e[0],{type:"Literal",value:null}),isempty:e=>e.length===0?b("==",{type:"Identity"},{type:"Literal",value:""}):b("==",e[0],{type:"Literal",value:""}),tonumber:e=>e.length===0?I("tonumber",[]):I("tonumber",e),tostring:e=>e.length===0?I("tostring",[]):I("tostring",e),if:e=>je(e[0],e[1],e[2]),coalesce:e=>{if(e.length===0)return{type:"Literal",value:null};if(e.length===1)return e[0];let[n,...t]=e,s=b("and",b("!=",n,{type:"Literal",value:null}),b("!=",n,{type:"Literal",value:""}));return je(s,n,t.length===1?t[0]:De.coalesce(t))},index:()=>({type:"Field",name:"_row_index"}),now:()=>I("now",[]),fmt:e=>I("tostring",e),format:e=>I("tostring",e)};function b(e,n,t){return{type:"BinaryOp",op:e,left:n,right:t}}function I(e,n){return{type:"Call",name:e,args:n}}var Xe="then";function je(e,n,t){let s={type:"Cond",cond:e,elifs:[],else:t||{type:"Literal",value:null}};return s[Xe]=n,s}function L(e){return{type:"Pipe",left:e,right:{type:"Call",name:"tostring",args:[]}}}function A(e,n=!0){switch(e.type){case"int":case"float":return{type:"Literal",value:e.value};case"string":return{type:"Literal",value:e.value};case"bool":return{type:"Literal",value:e.value};case"null":return{type:"Literal",value:null};case"underscore":return{type:"Index",base:{type:"Identity"},index:{type:"Literal",value:"_"}};case"identifier":return n?{type:"Field",name:e.name}:{type:"VarRef",name:e.name};case"lambdaBinding":return{type:"VarRef",name:e.name};case"func":{let t=e.args.map(r=>A(r.expr,n)),s=De[e.name];return typeof s=="function"?s(t):I(typeof s=="string"?s:e.name,t)}case"list":return e.elements.length===0?{type:"Array"}:{type:"Array",elements:e.elements.reduce((t,s,r)=>{let o=A(s,n);return r===0?o:{type:"Comma",left:t,right:o}},null)};case"map":return{type:"Object",entries:e.entries.map(t=>({key:t.key,value:A(t.value,n)}))};case"regex":return{type:"Literal",value:e.pattern};case"slice":return{type:"Slice",start:e.start?A(e.start,n):void 0,end:e.end?A(e.end,n):void 0};case"lambda":return A(e.body,n);case"pipeline":return{type:"Identity"};default:throw new Error(`Unknown moonblade expression type: ${e.type}`)}}function K(e){let n=[],t=0;for(;t<e.length;){for(;t<e.length&&(e[t]===" "||e[t]===",");)t++;if(t>=e.length)break;let s=t;for(;t<e.length&&/\w/.test(e[t]);)t++;let r=e.slice(s,t);for(;t<e.length&&e[t]===" ";)t++;if(e[t]!=="(")break;t++;let o=1,a=t;for(;t<e.length&&o>0;)e[t]==="("?o++:e[t]===")"&&o--,o>0&&t++;let d=e.slice(a,t).trim();for(t++;t<e.length&&e[t]===" ";)t++;let u="";if(e.slice(t,t+3).toLowerCase()==="as "){for(t+=3;t<e.length&&e[t]===" ";)t++;let p=t;for(;t<e.length&&/\w/.test(e[t]);)t++;u=e.slice(p,t)}u||(u=d?`${r}(${d})`:`${r}()`),n.push({func:r,expr:d,alias:u})}return n}function Ve(e){return/^\w+$/.test(e)}function z(e,n,t){let s=A(V(n)),r=P(e,s,t);return r.length>0?r[0]:null}function G(e,n,t={}){let{func:s,expr:r}=n;if(s==="count"&&!r)return e.length;let o;switch(Ve(r)?o=e.map(a=>a[r]).filter(a=>a!=null):o=e.map(a=>z(a,r,t)).filter(a=>a!=null),s){case"count":return Ve(r)?o.length:o.filter(a=>!!a).length;case"sum":return o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d))).reduce((d,u)=>d+u,0);case"mean":case"avg":{let a=o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d)));return a.length>0?a.reduce((d,u)=>d+u,0)/a.length:0}case"min":{let a=o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d)));return a.length>0?Math.min(...a):null}case"max":{let a=o.map(d=>typeof d=="number"?d:Number.parseFloat(String(d)));return a.length>0?Math.max(...a):null}case"first":return o.length>0?o[0]:null;case"last":return o.length>0?o[o.length-1]:null;case"median":{let a=o.map(u=>typeof u=="number"?u:Number.parseFloat(String(u))).filter(u=>!Number.isNaN(u)).sort((u,p)=>u-p);if(a.length===0)return null;let d=Math.floor(a.length/2);return a.length%2===0?(a[d-1]+a[d])/2:a[d]}case"mode":{let a=new Map;for(let p of o){let l=String(p);a.set(l,(a.get(l)||0)+1)}let d=0,u=null;for(let[p,l]of a)l>d&&(d=l,u=p);return u}case"cardinality":return new Set(o.map(d=>String(d))).size;case"values":return o.map(a=>String(a)).join("|");case"distinct_values":return[...new Set(o.map(d=>String(d)))].sort().join("|");case"all":{if(e.length===0)return!0;for(let a of e)if(!z(a,r,t))return!1;return!0}case"any":{for(let a of e)if(z(a,r,t))return!0;return!1}default:return null}}function We(e,n,t={}){let s={};for(let r of n)s[r.alias]=G(e,r,t);return s}async function X(e,n){let t="",s=[];for(let l of e)l.startsWith("-")||(t?s.push(l):t=l);if(!t)return{stdout:"",stderr:`xan agg: no aggregation expression