@shd101wyy/yo 0.0.5 → 0.0.7

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 (37) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +40 -11
  3. package/out/cjs/index.cjs +14 -14
  4. package/out/cjs/yo-cli.cjs +454 -403
  5. package/out/esm/index.mjs +22 -22
  6. package/out/types/src/codegen/expressions/index.d.ts +0 -1
  7. package/out/types/src/codegen/utils/index.d.ts +5 -3
  8. package/out/types/src/env.d.ts +7 -6
  9. package/out/types/src/error.d.ts +6 -3
  10. package/out/types/src/evaluator/async/await-analysis-types.d.ts +1 -1
  11. package/out/types/src/evaluator/builtins/arc_fns.d.ts +20 -0
  12. package/out/types/src/evaluator/builtins/array_fns.d.ts +8 -0
  13. package/out/types/src/evaluator/builtins/type_fns.d.ts +2 -2
  14. package/out/types/src/evaluator/builtins/var_fns.d.ts +1 -1
  15. package/out/types/src/evaluator/calls/numeric_type.d.ts +4 -0
  16. package/out/types/src/evaluator/types/utils.d.ts +10 -10
  17. package/out/types/src/evaluator/utils.d.ts +1 -1
  18. package/out/types/src/expr.d.ts +9 -4
  19. package/out/types/src/types/creators.d.ts +1 -1
  20. package/out/types/src/types/definitions.d.ts +1 -1
  21. package/out/types/src/types/guards.d.ts +1 -1
  22. package/out/types/src/types/utils.d.ts +3 -2
  23. package/out/types/src/utils.d.ts +3 -1
  24. package/out/types/src/value.d.ts +4 -4
  25. package/out/types/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +15 -2
  27. package/scripts/check-liburing.js +51 -39
  28. package/std/collections/array_list.yo +2 -2
  29. package/std/prelude.yo +272 -189
  30. package/out/types/src/codegen/expressions/array.d.ts +0 -4
  31. package/out/types/src/evaluator/utils/array-utils.d.ts +0 -15
  32. package/out/types/src/tests/codegen.test.d.ts +0 -1
  33. package/out/types/src/tests/module-manager.test.d.ts +0 -1
  34. package/out/types/src/tests/parser.test.d.ts +0 -1
  35. package/out/types/src/tests/sample.test.d.ts +0 -0
  36. package/out/types/src/tests/std.test.d.ts +0 -1
  37. package/std/monad.yo +0 -152
package/LICENSE.md CHANGED
@@ -14,4 +14,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
14
14
  Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
15
15
  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution.
16
16
  Neither the names of Yiyi Wang, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission.
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Yo
2
2
 
3
- `Work in Progress`
3
+ **Work in Progress. Not Ready!**
4
4
 
5
5
  A multi-paradigm, general-purpose, compiled programming language.
6
6
  Yo aims to be **Simple** and **Fast** (around 0% - 15% slower than C).
@@ -11,30 +11,54 @@ Yo aims to be **Simple** and **Fast** (around 0% - 15% slower than C).
11
11
 
12
12
  - First-class types.
13
13
  - Compile-time evaluation.
14
- - Homoiconicity and metaprogramming (**Yo** is just a combination of **Lisp** and **C**).
14
+ - Homoiconicity and metaprogramming (**Yo** syntax is inspired by the **Lisp** S expression).
15
15
  - Closure.
16
- - [Async/await](./ASYNC_AWAIT.md) (Stackless coroutine & Cooperative multi-tasking).
17
- - `object` type with [Non-atomic Reference Counting and Thread-Local Cycle Collection](./CYCLE_COLLECTION.md).
18
- - [Compile-time Reference Counting with Ownership and Lifetime Analysis](./COMPILE_TIME_RC_WITH_OWNERSHIP_ANALYSIS.md).
19
- - Thread-per-core parallelism model (see [PARALLEL.md](./PARALLEL.md)).
16
+ - [Async/await](./docs/ASYNC_AWAIT.md) (Stackless coroutine & Cooperative multi-tasking).
17
+ - `object` type with [Non-atomic Reference Counting and Thread-Local Cycle Collection](./docs/CYCLE_COLLECTION.md).
18
+ - [Compile-time Reference Counting with Ownership and Lifetime Analysis](./docs/COMPILE_TIME_RC_WITH_OWNERSHIP_ANALYSIS.md).
19
+ - Thread-per-core parallelism model (see [PARALLELISM.md](./docs/PARALLELISM.md)).
20
20
  - **C** interop.
21
- - etc
21
+ - etc.
22
+
23
+ [Screencast From 2026-01-09 23-05-16.webm](https://github.com/user-attachments/assets/a6e47931-1b5f-431a-b4e4-6dbed627f695)
22
24
 
23
25
  ## Language Design
24
26
 
25
- For design of the language, please refer to the [DESIGN.md](./DESIGN.md).
27
+ For the design of the language, please refer to [DESIGN.md](./docs/DESIGN.md).
26
28
 
27
29
  ## Installation
28
30
 
29
31
  The `Yo` language is currently distributed as an `npm` package:
30
32
 
31
33
  ```bash
32
- $ npm install -g @shd101wyy/yo # Install yo compiler globally
34
+ $ npm install -g @shd101wyy/yo # Install yo compiler globally
35
+ $ yarn global add @shd101wyy/yo # Or using yarn
36
+ $ pnpm add -g @shd101wyy/yo # Or using pnpm
37
+ $ bun install --global @shd101wyy/yo # Or using bun
33
38
  ```
34
39
 
35
40
  It exposes the `yo` command in your terminal.
41
+
36
42
  There is also an alias `yo-cli` for `yo` command in case of naming conflicts.
37
43
 
44
+ Run `yo --help` or `yo-cli --help` to see available commands.
45
+
46
+ ## Code examples
47
+
48
+ Check the `./tests` and `./std` folders for code examples.
49
+
50
+ ### Hello World
51
+
52
+ ```typescript
53
+ open import "std/libc/stdio";
54
+
55
+ main :: (fn() -> unit) {
56
+ printf("Hello, World!\n");
57
+ };
58
+
59
+ export main;
60
+ ```
61
+
38
62
  ## Development
39
63
 
40
64
  The `Yo` compiler is written in [TypeScript](https://www.typescriptlang.org/) and uses [Bun](https://bun.sh/) as the runtime.
@@ -64,13 +88,18 @@ Run the following command to build the project:
64
88
  $ bun run build
65
89
  ```
66
90
 
67
- Test some local yo-cli:
91
+ Test the local yo-cli:
68
92
 
69
93
  ```bash
70
94
  $ bun run src/yo-cli.ts compile src/tests/examples/fixme.yo
95
+
96
+ # There is also a `yo-cli` script in the project root for testing:
97
+ $ ./yo-cli compile src/tests/examples/fixme.yo
71
98
  ```
72
99
 
73
- ## Editor support
100
+ ## Editor Support
101
+
102
+ - A VS Code extension is available [here](https://marketplace.visualstudio.com/items?itemName=shd101wyy.yolang) that supports basic syntax highlighting. No LSP yet.
74
103
 
75
104
  - Vim / Neovim: a minimal syntax file and a usage README are available in `vscode-extension/syntaxes/`.
76
105
  See [vscode-extension/syntaxes/README.md](./vscode-extension/syntaxes/README.md) for installation steps, `ftdetect` examples and `home-manager` snippets.
package/out/cjs/index.cjs CHANGED
@@ -1,19 +1,19 @@
1
- var Je=Object.create;var W=Object.defineProperty;var Xe=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var tt=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty;var rt=(e,n)=>{for(var t in n)W(e,t,{get:n[t],enumerable:!0})},Se=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of et(n))!nt.call(e,i)&&i!==t&&W(e,i,{get:()=>n[i],enumerable:!(o=Xe(n,i))||o.enumerable});return e};var ot=(e,n,t)=>(t=e!=null?Je(tt(e)):{},Se(n||!e||!e.__esModule?W(t,"default",{value:e,enumerable:!0}):t,e)),it=e=>Se(W({},"__esModule",{value:!0}),e);var Ut={};rt(Ut,{IdentifierRegex:()=>O,Operators:()=>K,PlaceholderToken:()=>B,RAIIToken:()=>at,TokenType:()=>M,charIsOperator:()=>w,clearAllGlobalImplState:()=>He,clearGenericImplsFromModule:()=>We,clearImplsFromModule:()=>Ke,findMatchingBracketTokenIndex:()=>ce,generateExprFromCode:()=>Z,stringIsOperator:()=>pe,tokenize:()=>fe});module.exports=it(Ut);var It=require("node:fs"),At=ot(require("path"));var C=class{constructor({characterIndex:n,message:t}){this.characterIndex=n,this.message=t}},H=class{constructor(n,t){this.tokenAndErrorList=[];this.tokenAndErrorList=n,this.isAssertionError=t||!1}toString(){return this.tokenAndErrorList.map(({token:t,errorMessage:o})=>`Error: ${o}
2
- ${Me({token:t})}`).join(`
1
+ var tt=Object.create;var W=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var ot=Object.getPrototypeOf,it=Object.prototype.hasOwnProperty;var at=(e,n)=>{for(var t in n)W(e,t,{get:n[t],enumerable:!0})},we=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of rt(n))!it.call(e,i)&&i!==t&&W(e,i,{get:()=>n[i],enumerable:!(o=nt(n,i))||o.enumerable});return e};var st=(e,n,t)=>(t=e!=null?tt(ot(e)):{},we(n||!e||!e.__esModule?W(t,"default",{value:e,enumerable:!0}):t,e)),lt=e=>we(W({},"__esModule",{value:!0}),e);var zt={};at(zt,{IdentifierRegex:()=>O,Operators:()=>H,PlaceholderToken:()=>B,RAIIToken:()=>ut,TokenType:()=>M,charIsOperator:()=>w,clearAllGlobalImplState:()=>Ze,clearGenericImplsFromModule:()=>Ye,clearImplsFromModule:()=>Qe,findMatchingBracketTokenIndex:()=>oe,generateExprFromCode:()=>K,stringIsOperator:()=>re,tokenize:()=>ie});module.exports=lt(zt);var At=require("node:fs"),Ut=st(require("path"));var C=class{constructor({characterIndex:n,message:t}){this.characterIndex=n,this.message=t}},G=class{constructor(n,t,o){this.tokenAndErrorList=[];this.tokenAndErrorList=n,this.isAssertionError=t||!1,this.kind=o}toString(){return this.tokenAndErrorList.map(({token:t,errorMessage:o})=>`Error: ${o}
2
+ ${Ie({token:t})}`).join(`
3
3
 
4
- `)}};function Me({token:e}){let{position:n,modulePath:t,inputString:o}=e,{row:i,column:r}=n,s=o.split(`
4
+ `)}};function Ie({token:e}){let{position:n,modulePath:t,inputString:o}=e,{row:i,column:r}=n,s=o.split(`
5
5
  `)[i];return`${t}:${i+1}:${r+1}:
6
6
  ${s}
7
- ${" ".repeat(r+Math.floor(e.value.length/2))}^`}function y({token:e,errorMessage:n,cause:t,isAssertionError:o}){let i=`${n.trim()}
7
+ ${" ".repeat(r+Math.floor(e.value.length/2))}^`}function y({token:e,errorMessage:n,cause:t,isAssertionError:o,kind:i}){let r=`${n.trim()}
8
8
 
9
- ${Me({token:e})}`;return new H([{token:e,errorMessage:i+(t!=null&&t.message?`
10
- `+t.message:"")}],o)}var M=(m=>(m.Operator="operator",m.Dot=".",m.LParen="(",m.RParen=")",m.LBracket="[",m.RBracket="]",m.LCurlyBracket="{",m.RCurlyBracket="}",m.Char="char",m.String="string",m.Identifier="identifier",m.Integer="integer",m.Float="float",m.Bool="bool",m.Semicolon=";",m.Comma=",",m.SingleLineComment="single_line_comment",m.MultiLineComment="multi_line_comment",m.Whitespace="whitespace",m.BacktickIdentifier="backtick_identifier",m))(M||{}),B={modulePath:"_",inputString:"_",type:"identifier",value:"_",position:{row:0,column:0,character:0}},at={modulePath:"drop",inputString:"drop",type:"identifier",value:"drop",position:{row:0,column:0,character:0}},K=["=","+","-","*","/","<",">","@","$","~","&","%","|","!","?","^",".",":","\\","#"];function w(e){return K.includes(e)}function pe(e){let n=!0;for(let t=0;t<e.length;t++){let o=e[t];if(!w(o)){n=!1;break}}return n}var O=/^[_a-zA-Z\xA0-\uFFFF][_a-zA-Z0-9\xA0-\uFFFF]*[!?]?$/;function ce(e,n){let t=")";if(!e[n])return-1;let o=e[n].type;if(o==="{")t="}";else if(o==="(")t=")";else if(o==="[")t="]";else throw this.formatErrorMessage(e[n],"Expected '{', '(' or '['");n=n+1;let i=1,r=-1;for(;;){let p=e[n];if(!p)return-1;if(p.type===t){if(i=i-1,i===0){r=n;break}}else p.type===o&&(i=i+1);n=n+1}return r}function fe(e,n){let t=[],o=0,i=0;for(let r=0;r<e.length;r++){let p=e[r],s=r-i,u=r,f="",c=r;if(e[c]===".")for(;e[c]===".";)f+=e[c],c=c+1;else for(;w(e[c])&&e[c]!==".";)f+=e[c],c=c+1;if(f&&!f.startsWith("//")&&!f.startsWith("/*")){t.push({type:f==="."?".":"operator",value:f,position:{row:o,column:s,character:u},modulePath:n,inputString:e}),r=c-1;continue}switch(p){case" ":case" ":case`
9
+ ${Ie({token:e})}`;return new G([{token:e,errorMessage:r+(t!=null&&t.message?`
10
+ `+t.message:"")}],o,i)}var M=(m=>(m.Operator="operator",m.Dot=".",m.LParen="(",m.RParen=")",m.LBracket="[",m.RBracket="]",m.LCurlyBracket="{",m.RCurlyBracket="}",m.Char="char",m.String="string",m.Identifier="identifier",m.Integer="integer",m.Float="float",m.Bool="bool",m.Semicolon=";",m.Comma=",",m.SingleLineComment="single_line_comment",m.MultiLineComment="multi_line_comment",m.Whitespace="whitespace",m.BacktickIdentifier="backtick_identifier",m))(M||{}),B={modulePath:"_",inputString:"_",type:"identifier",value:"_",position:{row:0,column:0,character:0}},ut={modulePath:"drop",inputString:"drop",type:"identifier",value:"drop",position:{row:0,column:0,character:0}},H=["=","+","-","*","/","<",">","@","$","~","&","%","|","!","?","^",".",":","\\","#"];function w(e){return H.includes(e)}function re(e){let n=!0;for(let t=0;t<e.length;t++){let o=e[t];if(!w(o)){n=!1;break}}return n}var O=/^[_a-zA-Z\xA0-\uFFFF][_a-zA-Z0-9\xA0-\uFFFF]*[!?]?$/;function oe(e,n){let t=")";if(!e[n])return-1;let o=e[n].type;if(o==="{")t="}";else if(o==="(")t=")";else if(o==="[")t="]";else throw this.formatErrorMessage(e[n],"Expected '{', '(' or '['");n=n+1;let i=1,r=-1;for(;;){let p=e[n];if(!p)return-1;if(p.type===t){if(i=i-1,i===0){r=n;break}}else p.type===o&&(i=i+1);n=n+1}return r}function ie(e,n){let t=[],o=0,i=0;for(let r=0;r<e.length;r++){let p=e[r],s=r-i,u=r,f="",c=r;if(e[c]===".")for(;e[c]===".";)f+=e[c],c=c+1;else for(;w(e[c])&&e[c]!==".";)f+=e[c],c=c+1;if(f&&!f.startsWith("//")&&!f.startsWith("/*")){t.push({type:f==="."?".":"operator",value:f,position:{row:o,column:s,character:u},modulePath:n,inputString:e}),r=c-1;continue}switch(p){case" ":case" ":case`
11
11
  `:case"\r":{let l="",a=r,g=o;for(;e[a]===" "||e[a]===" "||e[a]===`
12
12
  `||e[a]==="\r";)l+=e[a],e[a]===`
13
13
  `&&(o++,i=a+1),a=a+1;t.push({type:"whitespace",value:l,position:{row:g,column:s,character:u},modulePath:n,inputString:e}),r=a-1;break}case"/":if(e[r+1]==="/"){let l="",a=r;for(;e[a]!==`
14
14
  `&&a<e.length;)l+=e[a],a=a+1;t.push({type:"single_line_comment",value:l,position:{row:o,column:s,character:u},modulePath:n,inputString:e}),r=a-1}else if(e[r+1]==="*"){let l=r,a="",g=o,d=1;for(a+=e[l],l++,a+=e[l],l++;d>0&&l<e.length;){if(e[l]===`
15
- `&&(i=l+1,o++),e[l]==="/"&&e[l+1]==="*"){d++,a+="/*",l+=2;continue}if(e[l]==="*"&&e[l+1]==="/"){d--,a+="*/",l+=2;continue}a+=e[l],l++}if(d>0)throw new C({message:"Unterminated multi-line comment",characterIndex:e.length-1});t.push({type:"multi_line_comment",value:a,position:{row:g,column:s,character:u},modulePath:n,inputString:e}),r=l-1}else throw new C({message:`Unexpected character ${p}`,characterIndex:r+1});break;case"(":t.push({type:"(",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case")":t.push({type:")",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case"[":t.push({type:"[",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case"]":t.push({type:"]",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case"{":t.push({type:"{",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case"}":t.push({type:"}",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case"'":{let l="";for(let a=r+1;a<e.length;a++){if(e[a]==="\\"){l+=e[a],a=a+1,l+=e[a];continue}if(e[a]==="'"){r=a;break}l+=e[a]}if(l.length===1||l.length===2&&l[0]==="\\")t.push({type:"char",value:`'${l}'`,position:{row:o,column:s,character:u},modulePath:n,inputString:e});else throw new C({message:`Invalid char '${l}', expected char to have length 1.`,characterIndex:r});break}case'"':{let l="";for(let a=r+1;a<e.length;a++){if(e[a]==="\\"){l+=e[a],a=a+1,l+=e[a];continue}if(e[a]==='"'){r=a;break}l+=e[a]}t.push({type:"string",value:`"${l}"`,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break}case"`":{let l="";for(let a=r+1;a<e.length;a++){if(e[a]==="\\"){l+=e[a],a=a+1,l+=e[a];continue}if(e[a]==="`"){r=a;break}l+=e[a]}if(!O.test(l))throw new C({message:`Invalid backtick identifier \`${l}\``,characterIndex:r});t.push({type:"backtick_identifier",value:`\`${l}\``,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break}case",":t.push({type:",",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case";":t.push({type:";",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;default:if(/[0-9]/.test(p)){let l=r,a=p;r=r+1;let g=/[0-9_]/;for(e[r-1]==="0"&&typeof e[r]=="string"&&(e[r]==="x"||e[r]==="X"?(a+=e[r],r=r+1,g=/[0-9A-Fa-f]/):e[r]==="b"||e[r]==="B"?(a+=e[r],r=r+1,g=/[01]/):(e[r]==="o"||e[r]==="O")&&(a+=e[r],r=r+1,g=/[0-7]/));typeof e[r]=="string"&&g.test(e[r]);)a+=e[r],r=r+1;if(e[r]==="."&&e[l-1]!=="."&&(e[r+1]??"").match(/[0-9]/)){for(a+=e[r],r=r+1;typeof e[r]=="string"&&/[0-9_]/.test(e[r]);)a+=e[r],r=r+1;if((e[r]==="e"||e[r]==="E")&&typeof e[r+1]=="string"&&(e[r+1]==="+"||e[r+1]==="-"||/[0-9]/.test(e[r+1])))for(a+=e[r],r=r+1,(e[r]==="+"||e[r]==="-")&&(a+=e[r],r=r+1);typeof e[r]=="string"&&/[0-9_]/.test(e[r]);)a+=e[r],r=r+1;t.push({type:"float",value:a,position:{row:o,column:s,character:u},modulePath:n,inputString:e}),r=r-1}else{if((e[r]==="e"||e[r]==="E")&&typeof e[r+1]=="string"&&(e[r+1]==="+"||e[r+1]==="-"||/[0-9]/.test(e[r+1])))for(a+=e[r],r=r+1,(e[r]==="+"||e[r]==="-")&&(a+=e[r],r=r+1);typeof e[r]=="string"&&/[0-9_]/.test(e[r]);)a+=e[r],r=r+1;t.push({type:"integer",value:a,position:{row:o,column:s,character:u},modulePath:n,inputString:e}),r=r-1}}else if(/[_a-zA-Z\xA0-\uFFFF]/.test(p)){let l=p,a=r;for(r=r+1;typeof e[r]=="string"&&/[_a-zA-Z0-9\xA0-\uFFFF]/.test(e[r]);)l+=e[r],r=r+1;if(r=r-1,(e[r+1]==="!"||e[r+1]==="?")&&O.test(l+e[r+1])&&(r=r+1,l+=e[r]),O.test(l))switch(l){case"true":case"false":t.push({type:"bool",value:l,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;default:t.push({type:"identifier",value:l,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break}else throw new C({message:`Invalid identifier ${l}`,characterIndex:a})}else throw new C({message:`Unexpected character ${p}`,characterIndex:r});break}}return t}var N=class{constructor({modulePath:n,inputString:t}){this.modulePath=n,this.inputString=t,this.tokens=fe(t,n),this.program=[],this.parse(this.tokens)}skipWhitespace(n,t){for(;n[t]&&(n[t].type==="whitespace"||n[t].type==="single_line_comment"||n[t].type==="multi_line_comment");)t=t+1;return t}skipWhitespaceBackward(n,t){for(;n[t]&&(n[t].type==="whitespace"||n[t].type==="single_line_comment"||n[t].type==="multi_line_comment");)t=t-1;return t}isParenthesizedExpression(n,t,o){return t=this.skipWhitespace(n,t),o=this.skipWhitespaceBackward(n,o),!!n[t]&&n[t].type==="("&&!!n[o]&&n[o].type===")"&&ce(n,t)===o}parseParenExpr({tokens:n,index:t}){var p;let o=t;if(n[t].type!=="(")throw y({token:n[t],errorMessage:"Expected left paren"});if(((p=n[t+1])==null?void 0:p.type)===")")return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:_.tuple,position:n[t].position,modulePath:this.modulePath,inputString:this.inputString}},args:[],token:n[t]},index:t+2};let i=this.parseExpression({tokens:n,index:t+1}),r=i.expr;if(t=i.index,n[t].type===")")return{expr:r,index:t+1};{let s,u=[r];for(;;){if(!n[t])throw y({token:n[t-1],errorMessage:"Expected ) or , for tuple"});if(n[t].type===","){if(!s||s===",")s=",";else throw y({token:n[t],errorMessage:'Cannot mix "," with ";" as separator in (...)'});t=t+1}else if(n[t].type===";"){if(!s||s===";")s=";";else throw y({token:n[t],errorMessage:'Cannot mix ";" with "," as separator in (...)'});t=t+1}if(t=this.skipWhitespace(n,t),n[t].type===")")break;let{expr:c,index:l}=this.parseExpression({tokens:n,index:t});u.push(c),t=l}let f=s===";"||!s;return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:f?_.Tuple[0]:_.tuple,position:n[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:u,token:n[o]},index:t+1}}}parseArrayExpr({tokens:n,index:t}){let o=t;if(n[t].type!=="[")throw y({token:n[t],errorMessage:"Expected left bracket"});t=t+1;let i,r=[];for(;;){if(!n[t])throw y({token:n[t-1],errorMessage:"Expected ] or , for array"});if(n[t].type===","){if(!i||i===",")i=",";else throw y({token:n[t],errorMessage:'Cannot mix "," with ";" as separator in [...]'});t=t+1}else if(n[t].type===";"){if(!i||i===";")i=";";else throw y({token:n[t],errorMessage:'Cannot mix ";" with "," as separator in [...]'});t=t+1}if(n[t].type==="]")break;let{expr:f,index:c}=this.parseExpression({tokens:n,index:t});r.push(f),t=c}let p=i===";"||!i;if(p&&r.length>2)throw y({token:n[o],errorMessage:`Expected at 2 arguments for Array type, or 1 argument for Slice type, got ${r.length}`});let s=p&&r.length===2,u=p&&r.length===1;return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:s?_.Array[0]:u?_.Slice[0]:_.array,position:n[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:r,token:n[o]},index:t+1}}parseCurlyBracketExpr({tokens:n,index:t}){let o=t;if(n[t].type!=="{")throw y({token:n[t],errorMessage:"Expected left curly bracket"});let i=[],r;for(t=t+1;;){if(t=this.skipWhitespace(n,t),!n[t])throw y({token:n[t-1],errorMessage:'Unexpected end of curly bracket. Expected "}" or "," or ";"'});if(n[t].type===","){if(!r||r===",")r=",";else throw y({token:n[t],errorMessage:'Cannot mix "," with ";" as separator in {...}'});t=t+1}else if(n[t].type===";"){if(!r||r===";")r=";";else throw y({token:n[t],errorMessage:'Cannot mix ";" with "," as separator in {...}'});t=t+1}if(t=this.skipWhitespace(n,t),n[t].type==="}"){let u=n[this.skipWhitespaceBackward(n,t-1)];if(r===";"&&u&&(u.type===";"||u.type==="{")){let f={type:"identifier",value:_.tuple,position:u.position,modulePath:this.modulePath,inputString:this.inputString};i.push({tag:"FuncCall",func:{tag:"Atom",token:f},args:[],token:f})}break}let{expr:p,index:s}=this.parseExpression({tokens:n,index:t});i.push(p),t=s}if(r===","||!r){for(let s=0;s<i.length;s++){let u=i[s];if(k(u)){let f={type:"operator",value:":",position:n[o].position,modulePath:this.modulePath,inputString:this.inputString},c={tag:"FuncCall",func:{tag:"Atom",token:f},isInfix:!0,args:[u,u],token:f};i[s]=c}}return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:"_",position:n[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:i,token:n[o]},index:t+1}}else return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:_.begin[0],position:n[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:i,token:n[o]},index:t+1}}parsePrimary({tokens:n,index:t}){t=this.skipWhitespace(n,t);let o=n[t];if(!o)throw y({token:B,errorMessage:"Unexpected end of input"});let i=null;switch(o.type){case"identifier":case"operator":case"bool":case"integer":case"float":case"string":case"char":{i={expr:{tag:"Atom",token:o},index:t+1};break}case"(":{i=this.parseParenExpr({tokens:n,index:t});break}case"[":{i=this.parseArrayExpr({tokens:n,index:t});break}case"{":{i=this.parseCurlyBracketExpr({tokens:n,index:t});break}case".":{i={expr:{tag:"Atom",token:o},index:t+1};break}default:throw y({token:o,errorMessage:`Unexpected token "${o.type}"`})}return i}isOperatorAtLineStart(n,t){for(let o=n.length-1;o>=0;o--){let i=n[o];if(i.type==="whitespace"&&i.value.includes(`
16
- `))return n.slice(o+1).every(s=>s.type==="whitespace");if(i.type!=="whitespace")return!1}return n.every(o=>o.type==="whitespace")}parseLeftAssociativeOperator({primaryExpr:n,operatorToken:t,rhs:o,tokens:i,index:r}){if(o.tag==="FuncCall"&&o.isInfix&&o.func.tag==="Atom"&&o.func.token.type!=="."){let p=o.args[0],s=o.args[1],u=o.func,f={tag:"FuncCall",func:{tag:"Atom",token:t},args:[n,p],isInfix:!0,token:t};return this.parsePrimaryEnd({primaryExpr:{tag:"FuncCall",func:u,args:[f,s],isInfix:!0,token:u.token},tokens:i,index:r})}else return this.parsePrimaryEnd({primaryExpr:{tag:"FuncCall",func:{tag:"Atom",token:t},args:[n,o],isInfix:!0,token:t},tokens:i,index:r})}getExprMinimumColumnNumber(n){return k(n)?n.token.position.column:Math.min(this.getExprMinimumColumnNumber(n.func),...n.args.map(t=>this.getExprMinimumColumnNumber(t)))}parsePrimaryEnd({primaryExpr:n,tokens:t,index:o}){var f,c,l,a,g;let i=this.skipWhitespace(t,o),r=i!==o,p=((f=t[o-1])==null?void 0:f.type)==="whitespace";o=i;let s=t[i];if(!s||s.type===";"||s.type===","||s.type===")"||s.type==="]"||s.type==="}")return{expr:n,index:o};let u=n.tag==="Atom"&&n.token.type===".";if(u||s.type==="."&&!r&&!p&&((c=t[i+1])==null?void 0:c.type)!=="whitespace"){let{expr:d,index:v}=this.parsePrimary({tokens:t,index:u?o:o+1});o=v;let E={expr:{tag:"FuncCall",func:{tag:"Atom",token:u?n.token:s},args:u?[d]:[n,d],isInfix:!u,token:u?n.token:s},index:o};for(;t[o]&&t[o].type===".";){let{expr:L,index:se}=this.parsePrimary({tokens:t,index:o+1});E={expr:{tag:"FuncCall",func:{tag:"Atom",token:s},args:[E.expr,L],isInfix:!0,token:s},index:se},o=se}return this.parsePrimaryEnd({primaryExpr:E.expr,tokens:t,index:E.index})}else if((s.type==="operator"||s.type==="."&&!r||s.type==="backtick_identifier")&&((l=t[o+1])==null?void 0:l.type)!=="("){let d=this.skipWhitespace(t,o+1),{expr:v,index:E}=this.parseExpression({tokens:t,index:d});if(v.tag==="FuncCall"&&v.isInfix&&v.func.tag==="Atom"&&v.func.token.type!=="."&&!this.isParenthesizedExpression(t,d,E-1)){let L=`Ambiguous operator precedence.
15
+ `&&(i=l+1,o++),e[l]==="/"&&e[l+1]==="*"){d++,a+="/*",l+=2;continue}if(e[l]==="*"&&e[l+1]==="/"){d--,a+="*/",l+=2;continue}a+=e[l],l++}if(d>0)throw new C({message:"Unterminated multi-line comment",characterIndex:e.length-1});t.push({type:"multi_line_comment",value:a,position:{row:g,column:s,character:u},modulePath:n,inputString:e}),r=l-1}else throw new C({message:`Unexpected character ${p}`,characterIndex:r+1});break;case"(":t.push({type:"(",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case")":t.push({type:")",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case"[":t.push({type:"[",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case"]":t.push({type:"]",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case"{":t.push({type:"{",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case"}":t.push({type:"}",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case"'":{let l="";for(let a=r+1;a<e.length;a++){if(e[a]==="\\"){l+=e[a],a=a+1,l+=e[a];continue}if(e[a]==="'"){r=a;break}l+=e[a]}if(l.length===1||l.length===2&&l[0]==="\\")t.push({type:"char",value:`'${l}'`,position:{row:o,column:s,character:u},modulePath:n,inputString:e});else throw new C({message:`Invalid char '${l}', expected char to have length 1.`,characterIndex:r});break}case'"':{let l="";for(let a=r+1;a<e.length;a++){if(e[a]==="\\"){l+=e[a],a=a+1,l+=e[a];continue}if(e[a]==='"'){r=a;break}l+=e[a]}t.push({type:"string",value:`"${l}"`,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break}case"`":{let l="";for(let a=r+1;a<e.length;a++){if(e[a]==="\\"){l+=e[a],a=a+1,l+=e[a];continue}if(e[a]==="`"){r=a;break}l+=e[a]}if(!O.test(l))throw new C({message:`Invalid backtick identifier \`${l}\``,characterIndex:r});t.push({type:"backtick_identifier",value:`\`${l}\``,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break}case",":t.push({type:",",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;case";":t.push({type:";",value:p,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;default:if(/[0-9]/.test(p)){let l=r,a=p;r=r+1;let g=/[0-9_]/;for(e[r-1]==="0"&&typeof e[r]=="string"&&(e[r]==="x"||e[r]==="X"?(a+=e[r],r=r+1,g=/[0-9A-Fa-f]/):e[r]==="b"||e[r]==="B"?(a+=e[r],r=r+1,g=/[01]/):(e[r]==="o"||e[r]==="O")&&(a+=e[r],r=r+1,g=/[0-7]/));typeof e[r]=="string"&&g.test(e[r]);)a+=e[r],r=r+1;if(e[r]==="."&&e[l-1]!=="."&&(e[r+1]??"").match(/[0-9]/)){for(a+=e[r],r=r+1;typeof e[r]=="string"&&/[0-9_]/.test(e[r]);)a+=e[r],r=r+1;if((e[r]==="e"||e[r]==="E")&&typeof e[r+1]=="string"&&(e[r+1]==="+"||e[r+1]==="-"||/[0-9]/.test(e[r+1])))for(a+=e[r],r=r+1,(e[r]==="+"||e[r]==="-")&&(a+=e[r],r=r+1);typeof e[r]=="string"&&/[0-9_]/.test(e[r]);)a+=e[r],r=r+1;t.push({type:"float",value:a,position:{row:o,column:s,character:u},modulePath:n,inputString:e}),r=r-1}else{if((e[r]==="e"||e[r]==="E")&&typeof e[r+1]=="string"&&(e[r+1]==="+"||e[r+1]==="-"||/[0-9]/.test(e[r+1])))for(a+=e[r],r=r+1,(e[r]==="+"||e[r]==="-")&&(a+=e[r],r=r+1);typeof e[r]=="string"&&/[0-9_]/.test(e[r]);)a+=e[r],r=r+1;t.push({type:"integer",value:a,position:{row:o,column:s,character:u},modulePath:n,inputString:e}),r=r-1}}else if(/[_a-zA-Z\xA0-\uFFFF]/.test(p)){let l=p,a=r;for(r=r+1;typeof e[r]=="string"&&/[_a-zA-Z0-9\xA0-\uFFFF]/.test(e[r]);)l+=e[r],r=r+1;if(r=r-1,(e[r+1]==="!"||e[r+1]==="?")&&O.test(l+e[r+1])&&(r=r+1,l+=e[r]),O.test(l))switch(l){case"true":case"false":t.push({type:"bool",value:l,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break;default:t.push({type:"identifier",value:l,position:{row:o,column:s,character:u},modulePath:n,inputString:e});break}else throw new C({message:`Invalid identifier ${l}`,characterIndex:a})}else throw new C({message:`Unexpected character ${p}`,characterIndex:r});break}}return t}var R=class{constructor({modulePath:n,inputString:t}){this.modulePath=n,this.inputString=t,this.tokens=ie(t,n),this.program=[],this.parse(this.tokens)}skipWhitespace(n,t){for(;n[t]&&(n[t].type==="whitespace"||n[t].type==="single_line_comment"||n[t].type==="multi_line_comment");)t=t+1;return t}skipWhitespaceBackward(n,t){for(;n[t]&&(n[t].type==="whitespace"||n[t].type==="single_line_comment"||n[t].type==="multi_line_comment");)t=t-1;return t}isParenthesizedExpression(n,t,o){return t=this.skipWhitespace(n,t),o=this.skipWhitespaceBackward(n,o),!!n[t]&&n[t].type==="("&&!!n[o]&&n[o].type===")"&&oe(n,t)===o}parseParenExpr({tokens:n,index:t}){var p;let o=t;if(n[t].type!=="(")throw y({token:n[t],errorMessage:"Expected left paren"});if(((p=n[t+1])==null?void 0:p.type)===")")return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:_.tuple,position:n[t].position,modulePath:this.modulePath,inputString:this.inputString}},args:[],token:n[t]},index:t+2};let i=this.parseExpression({tokens:n,index:t+1}),r=i.expr;if(t=i.index,n[t].type===")")return{expr:r,index:t+1};{let s,u=[r];for(;;){if(!n[t])throw y({token:n[t-1],errorMessage:"Expected ) or , for tuple"});if(n[t].type===","){if(!s||s===",")s=",";else throw y({token:n[t],errorMessage:'Cannot mix "," with ";" as separator in (...)'});t=t+1}else if(n[t].type===";"){if(!s||s===";")s=";";else throw y({token:n[t],errorMessage:'Cannot mix ";" with "," as separator in (...)'});t=t+1}if(t=this.skipWhitespace(n,t),n[t].type===")")break;let{expr:c,index:l}=this.parseExpression({tokens:n,index:t});u.push(c),t=l}let f=s===";"||!s;return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:f?_.Tuple[0]:_.tuple,position:n[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:u,token:n[o]},index:t+1}}}parseArrayExpr({tokens:n,index:t}){let o=t;if(n[t].type!=="[")throw y({token:n[t],errorMessage:"Expected left bracket"});t=t+1;let i,r=[];for(;;){if(!n[t])throw y({token:n[t-1],errorMessage:"Expected ] or , for array"});if(n[t].type===","){if(!i||i===",")i=",";else throw y({token:n[t],errorMessage:'Cannot mix "," with ";" as separator in [...]'});t=t+1}else if(n[t].type===";"){if(!i||i===";")i=";";else throw y({token:n[t],errorMessage:'Cannot mix ";" with "," as separator in [...]'});t=t+1}if(n[t].type==="]")break;let{expr:f,index:c}=this.parseExpression({tokens:n,index:t});r.push(f),t=c}let p=i===";"||!i;if(p&&r.length>2)throw y({token:n[o],errorMessage:`Expected at 2 arguments for Array type, or 1 argument for Slice type, got ${r.length}`});let s=p&&r.length===2,u=p&&r.length===1;return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:s?_.Array[0]:u?_.Slice[0]:_.array,position:n[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:r,token:n[o]},index:t+1}}parseCurlyBracketExpr({tokens:n,index:t}){let o=t;if(n[t].type!=="{")throw y({token:n[t],errorMessage:"Expected left curly bracket"});let i=[],r;for(t=t+1;;){if(t=this.skipWhitespace(n,t),!n[t])throw y({token:n[t-1],errorMessage:'Unexpected end of curly bracket. Expected "}" or "," or ";"'});if(n[t].type===","){if(!r||r===",")r=",";else throw y({token:n[t],errorMessage:'Cannot mix "," with ";" as separator in {...}'});t=t+1}else if(n[t].type===";"){if(!r||r===";")r=";";else throw y({token:n[t],errorMessage:'Cannot mix ";" with "," as separator in {...}'});t=t+1}if(t=this.skipWhitespace(n,t),n[t].type==="}"){let u=n[this.skipWhitespaceBackward(n,t-1)];if(r===";"&&u&&(u.type===";"||u.type==="{")){let f={type:"identifier",value:_.tuple,position:u.position,modulePath:this.modulePath,inputString:this.inputString};i.push({tag:"FuncCall",func:{tag:"Atom",token:f},args:[],token:f})}break}let{expr:p,index:s}=this.parseExpression({tokens:n,index:t});i.push(p),t=s}if(r===","||!r){for(let s=0;s<i.length;s++){let u=i[s];if(k(u)){let f={type:"operator",value:":",position:n[o].position,modulePath:this.modulePath,inputString:this.inputString},c={tag:"FuncCall",func:{tag:"Atom",token:f},isInfix:!0,args:[u,u],token:f};i[s]=c}}return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:"_",position:n[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:i,token:n[o]},index:t+1}}else return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:_.begin[0],position:n[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:i,token:n[o]},index:t+1}}parsePrimary({tokens:n,index:t}){t=this.skipWhitespace(n,t);let o=n[t];if(!o)throw y({token:B,errorMessage:"Unexpected end of input"});let i=null;switch(o.type){case"identifier":case"operator":case"bool":case"integer":case"float":case"string":case"char":{i={expr:{tag:"Atom",token:o},index:t+1};break}case"(":{i=this.parseParenExpr({tokens:n,index:t});break}case"[":{i=this.parseArrayExpr({tokens:n,index:t});break}case"{":{i=this.parseCurlyBracketExpr({tokens:n,index:t});break}case".":{i={expr:{tag:"Atom",token:o},index:t+1};break}default:throw y({token:o,errorMessage:`Unexpected token "${o.type}"`})}return i}isOperatorAtLineStart(n,t){for(let o=n.length-1;o>=0;o--){let i=n[o];if(i.type==="whitespace"&&i.value.includes(`
16
+ `))return n.slice(o+1).every(s=>s.type==="whitespace");if(i.type!=="whitespace")return!1}return n.every(o=>o.type==="whitespace")}parseLeftAssociativeOperator({primaryExpr:n,operatorToken:t,rhs:o,tokens:i,index:r}){if(o.tag==="FuncCall"&&o.isInfix&&o.func.tag==="Atom"&&o.func.token.type!=="."){let p=o.args[0],s=o.args[1],u=o.func,f={tag:"FuncCall",func:{tag:"Atom",token:t},args:[n,p],isInfix:!0,token:t};return this.parsePrimaryEnd({primaryExpr:{tag:"FuncCall",func:u,args:[f,s],isInfix:!0,token:u.token},tokens:i,index:r})}else return this.parsePrimaryEnd({primaryExpr:{tag:"FuncCall",func:{tag:"Atom",token:t},args:[n,o],isInfix:!0,token:t},tokens:i,index:r})}getExprMinimumColumnNumber(n){return k(n)?n.token.position.column:Math.min(this.getExprMinimumColumnNumber(n.func),...n.args.map(t=>this.getExprMinimumColumnNumber(t)))}parsePrimaryEnd({primaryExpr:n,tokens:t,index:o}){var f,c,l,a,g;let i=this.skipWhitespace(t,o),r=i!==o,p=((f=t[o-1])==null?void 0:f.type)==="whitespace";o=i;let s=t[i];if(!s||s.type===";"||s.type===","||s.type===")"||s.type==="]"||s.type==="}")return{expr:n,index:o};let u=n.tag==="Atom"&&n.token.type===".";if(u||s.type==="."&&!r&&!p&&((c=t[i+1])==null?void 0:c.type)!=="whitespace"){let{expr:d,index:v}=this.parsePrimary({tokens:t,index:u?o:o+1});o=v;let E={expr:{tag:"FuncCall",func:{tag:"Atom",token:u?n.token:s},args:u?[d]:[n,d],isInfix:!u,token:u?n.token:s},index:o};for(;t[o]&&t[o].type===".";){let{expr:L,index:ee}=this.parsePrimary({tokens:t,index:o+1});E={expr:{tag:"FuncCall",func:{tag:"Atom",token:s},args:[E.expr,L],isInfix:!0,token:s},index:ee},o=ee}return this.parsePrimaryEnd({primaryExpr:E.expr,tokens:t,index:E.index})}else if((s.type==="operator"||s.type==="."&&!r||s.type==="backtick_identifier")&&((l=t[o+1])==null?void 0:l.type)!=="("){let d=this.skipWhitespace(t,o+1),{expr:v,index:E}=this.parseExpression({tokens:t,index:d});if(v.tag==="FuncCall"&&v.isInfix&&v.func.tag==="Atom"&&v.func.token.type!=="."&&!this.isParenthesizedExpression(t,d,E-1)){let L=`Ambiguous operator precedence.
17
17
  Please use parentheses to clarify:
18
18
 
19
19
  ${T(n)} ${s.value} (${T(v)})
@@ -21,18 +21,18 @@ ${T(n)} ${s.value} (${T(v)})
21
21
  (${T(n)} ${s.value} ${T(v.args[0])}) ${T(v.func)} ${T(v.args[1])}
22
22
 
23
23
  Or use newline after "${s.value}" to confirm the right-associativity.
24
- `,Ye=t.slice(o+1,d).some(xe=>xe.type==="whitespace"&&xe.value.includes(`
25
- `)),m=t.slice(0,o),le=this.isOperatorAtLineStart(m,o),ue=t.slice(o+1,d),Qe=le&&ue.length>0&&((a=ue[0])==null?void 0:a.type)==="whitespace"&&((g=ue[0])==null?void 0:g.value.includes(`
26
- `));if(!(Ye&&!le)){if(!Qe){if(le)return this.parseLeftAssociativeOperator({primaryExpr:n,operatorToken:s,rhs:v,tokens:t,index:E});throw y({token:s,errorMessage:L})}}}return this.parsePrimaryEnd({primaryExpr:{tag:"FuncCall",func:{tag:"Atom",token:s},args:[n,v],isInfix:!0,token:s},tokens:t,index:E})}else if(!r&&s.type==="("){let d=this.parseFunctionCall({func:n,tokens:t,index:o+1,hasWhitespace:!1});return this.parsePrimaryEnd({primaryExpr:d.expr,tokens:t,index:d.index})}else{let d=this.parseFunctionCall({func:n,tokens:t,index:o,hasWhitespace:!0});return this.parsePrimaryEnd({primaryExpr:d.expr,tokens:t,index:d.index})}}parseFunctionArguments({tokens:n,index:t,hasWhitespace:o}){var r;let i=[];if(t=this.skipWhitespace(n,t),!o&&((r=n[t])==null?void 0:r.type)===")")return{args:i,index:t+1};for(;;){let{expr:p,index:s}=this.parseExpression({tokens:n,index:t});i.push(p),t=s;let u=n[t];if((u==null?void 0:u.type)===",")t=t+1;else{if(!u||u.type===";"||u.type==="]"||u.type==="}")return{args:i,index:t};if(u.type===")")return{args:i,index:o?t:t+1};throw y({token:u,errorMessage:o?"Expected ; to end the function call":`Expected , to separate arguments
24
+ `,Xe=t.slice(o+1,d).some(Me=>Me.type==="whitespace"&&Me.value.includes(`
25
+ `)),m=t.slice(0,o),te=this.isOperatorAtLineStart(m,o),ne=t.slice(o+1,d),et=te&&ne.length>0&&((a=ne[0])==null?void 0:a.type)==="whitespace"&&((g=ne[0])==null?void 0:g.value.includes(`
26
+ `));if(!(Xe&&!te)){if(!et){if(te)return this.parseLeftAssociativeOperator({primaryExpr:n,operatorToken:s,rhs:v,tokens:t,index:E});throw y({token:s,errorMessage:L})}}}return this.parsePrimaryEnd({primaryExpr:{tag:"FuncCall",func:{tag:"Atom",token:s},args:[n,v],isInfix:!0,token:s},tokens:t,index:E})}else if(!r&&s.type==="("){let d=this.parseFunctionCall({func:n,tokens:t,index:o+1,hasWhitespace:!1});return this.parsePrimaryEnd({primaryExpr:d.expr,tokens:t,index:d.index})}else{let d=this.parseFunctionCall({func:n,tokens:t,index:o,hasWhitespace:!0});return this.parsePrimaryEnd({primaryExpr:d.expr,tokens:t,index:d.index})}}parseFunctionArguments({tokens:n,index:t,hasWhitespace:o}){var r;let i=[];if(t=this.skipWhitespace(n,t),!o&&((r=n[t])==null?void 0:r.type)===")")return{args:i,index:t+1};for(;;){let{expr:p,index:s}=this.parseExpression({tokens:n,index:t});i.push(p),t=s;let u=n[t];if((u==null?void 0:u.type)===",")t=t+1;else{if(!u||u.type===";"||u.type==="]"||u.type==="}")return{args:i,index:t};if(u.type===")")return{args:i,index:o?t:t+1};throw y({token:u,errorMessage:o?"Expected ; to end the function call":`Expected , to separate arguments
27
27
  or ) to end the function call`})}}}parseFunctionCall({func:n,tokens:t,index:o,hasWhitespace:i}){let{args:r,index:p}=this.parseFunctionArguments({tokens:t,index:o,hasWhitespace:i});return o=p,{expr:{tag:"FuncCall",func:n,args:r,token:n.token},index:o}}parseExpression({tokens:n,index:t}){t=this.skipWhitespace(n,t);let{expr:o,index:i}=this.parsePrimary({tokens:n,index:t});return this.parsePrimaryEnd({primaryExpr:o,tokens:n,index:i})}programToString(){return this.program.map(t=>T(t)).join(`;
28
- `)}parse(n){let t=0,o=[];for(;t<n.length;){switch(n[t].type){case"whitespace":case";":case"single_line_comment":case"multi_line_comment":{t=t+1;continue}}if(t>=n.length)break;try{let{expr:p,index:s}=this.parseExpression({tokens:n,index:t});o.push(p),t=s}catch(p){this.parserError=p;break}}let i=n[this.skipWhitespaceBackward(n,n.length-1)];if(i&&i.type===";"){let r={type:"identifier",value:_.tuple,position:i.position,modulePath:this.modulePath,inputString:this.inputString};o.push({tag:"FuncCall",func:{tag:"Atom",token:r},args:[],token:r})}this.program=o}getProgram(){return this.program}getParserError(){return this.parserError}getTokens(){return this.tokens}};function Z(e){let n=new N({modulePath:`auto-generated://
28
+ `)}parse(n){let t=0,o=[];for(;t<n.length;){switch(n[t].type){case"whitespace":case";":case"single_line_comment":case"multi_line_comment":{t=t+1;continue}}if(t>=n.length)break;try{let{expr:p,index:s}=this.parseExpression({tokens:n,index:t});o.push(p),t=s}catch(p){this.parserError=p;break}}let i=n[this.skipWhitespaceBackward(n,n.length-1)];if(i&&i.type===";"){let r={type:"identifier",value:_.tuple,position:i.position,modulePath:this.modulePath,inputString:this.inputString};o.push({tag:"FuncCall",func:{tag:"Atom",token:r},args:[],token:r})}this.program=o}getProgram(){return this.program}getParserError(){return this.parserError}getTokens(){return this.tokens}};function K(e){let n=new R({modulePath:`auto-generated://
29
29
  // === START auto-generated code ===
30
30
  ${e}
31
31
  // === END auto-generated code ===
32
32
  `,inputString:e});if(n.getParserError())throw n.getParserError();let t=n.getProgram();if(t.length!==1)throw new Error(`Expected exactly one expression from parsed code, got ${t.length}: "${e}"
33
33
  ${t.map(o=>T(o)).join(`
34
34
  `)}
35
- `);return t[0]}var Be=require("crypto");var mt=0;function Oe(){return`id${mt++}`}function dt(e){return"yo"+(0,Be.createHash)("sha1").update(e).digest("hex").slice(0,8)}var Le=new Map;function Te(e,n){let t="";for(let r=0;r<n.length;r++)if(w(n[r])){let p=K.indexOf(n[r]);t+=`${p}`}else t+=n[r];let o=dt(e)+"_"+t,i=Le.get(o);return i===void 0?i=0:i++,Le.set(o,i),o+(i==0?"":`_${i}`)}var he=null;function Ne(){if(he)return he;let e=Re(),n=De(e),t={id:"unit",tag:"unit",module:n};return n.receiverType=t,he=t,t}function De(e){return{id:`module_${Oe()}`,tag:"Module",fields:[],env:e,module:void 0}}function S(e){return(e==null?void 0:e.tag)==="FuncCall"}function k(e){return(e==null?void 0:e.tag)==="Atom"}function U(e){return e.tag==="Atom"&&e.token.type==="operator"}function P(e,n,t){if(e.tag!=="FuncCall"||e.func.tag!=="Atom")return!1;let o=e.func.token.value;return e.func.token.type==="backtick_identifier"&&(o=o.slice(1,-1)),e.tag==="FuncCall"&&e.func.tag==="Atom"&&(typeof n=="string"?o===n:n.includes(o))&&(t===void 0||e.args.length===t)}var _={compt:["compt"],ref:["ref"],forall:["forall","\u2200"],where:["where"],quote:["quote",":"],unquote:["unquote","#"],unquote_splicing:["unquote_splicing","...#"],return:["return"],recur:["recur"],fn:["fn"],unsafe_fn:["unsafe_fn"],extern:["extern"],cond:["cond"],type:["type"],match:["match"],test:["test"],struct:["struct"],object:["object"],newtype:["newtype"],enum:["enum"],union:["union"],module:["module"],impl:["impl"],Impl:["Impl"],begin:["begin"],module_begin:["module_begin"],import:["import"],export:["export"],open:["open"],clone:["clone","%"],break:["break"],continue:["continue"],while:["while"],if:["if"],op_and:["&&"],op_or:["||"],not:["not"],gensym:["gensym"],dyn:["dyn"],Dyn:["Dyn"],Fn:["Fn"],c_include:["c_include"],undefined:["undefined"],null:["null"],true:["true"],false:["false"],unique:["unique","^"],Ptr:["*"],Iso:["Iso"],Tuple:["Tuple"],Array:["Array"],Slice:["Slice"],Future:["Future"],Concrete:["Concrete"],Type:["Type"],Module:["Module"],ComptList:["ComptList"],tuple:"tuple",array:"array",compt_list:"compt_list"};function z(e){return!!(e.tag==="FuncCall"&&e.isInfix&&e.func.tag==="Atom"&&(e.func.token.type==="operator"||e.func.token.type==="backtick_identifier")&&e.args.length===2)}function T(e,n){let o={...{prettyPrint:!1,indentSize:2,maxLineLength:80,indentLevel:0},...n};return o.prettyPrint?h(e,o):b(e)}function b(e){let n="";switch(e.tag){case"Atom":{n=e.token.value;break}case"FuncCall":{if(e.func.tag==="Atom"&&(e.func.token.type==="operator"||e.func.token.type==="."||e.func.token.type==="backtick_identifier")){if(e.args.length===1){e.func.token.value==="."?n=`${e.func.token.value}${b(e.args[0])}`:n=`${e.func.token.value}(${b(e.args[0])})`;break}else if(e.args.length===2&&e.isInfix){let i=b(e.args[0]),r=b(e.args[1]);i=z(e.args[0])||U(e.args[0])?`(${i})`:i,r=z(e.args[1])||U(e.args[1])?`(${r})`:r,e.func.token.value==="."?n=`(${i}.${r})`:n=`${i} ${e.func.token.value} ${r}`;break}}if(e.func.tag==="Atom"&&e.func.token.type==="identifier"&&e.func.token.value===_.tuple){e.args.length===1?n=`(${b(e.args[0])},)`:n=`(${e.args.map(i=>b(i)).join(", ").trim()})`;break}let t=b(e.func);t=z(e.func)||U(e.func)?`(${t})`:t;let o=e.args.map(i=>b(i)).join(", ").trim();n=`${t}(${o})`;break}}return n}function h(e,n){let t=" ".repeat(n.indentLevel*n.indentSize),o={...n,indentLevel:n.indentLevel+1},i=" ".repeat(o.indentLevel*n.indentSize);switch(e.tag){case"Atom":return e.token.value;case"FuncCall":{if(e.func.tag==="Atom"&&(e.func.token.type==="operator"||e.func.token.type==="."||e.func.token.type==="backtick_identifier")){if(e.args.length===1){if(e.func.token.value===".")return`${e.func.token.value}${h(e.args[0],n)}`;{let f=h(e.args[0],n);return`${e.func.token.value}(${f})`}}else if(e.args.length===2&&e.isInfix){let f=h(e.args[0],n),c=h(e.args[1],n);return f=z(e.args[0])||U(e.args[0])?`(${f})`:f,c=z(e.args[1])||U(e.args[1])?`(${c})`:c,e.func.token.value==="."?`(${f}.${c})`:`${f} ${e.func.token.value} ${c}`}}if(e.func.tag==="Atom"&&e.func.token.type==="identifier"&&e.func.token.value===_.tuple){if(e.args.length===0)return"()";if(e.args.length===1)return`(${h(e.args[0],n)},)`;{let f=e.args.map(l=>h(l,n)),c=`(${f.join(", ")})`;return c.length<=n.maxLineLength?c:`(
35
+ `);return t[0]}var Oe=require("crypto");function Re(e){return"yo"+(0,Oe.createHash)("sha1").update(e).digest("hex").slice(0,8)}var Le=new Map;function de(e){let n=Le.get(e);return n===void 0&&(n=0),Le.set(e,n+1),`${Re(e)}_id_${n}`}var Be=new Map;function ge(e,n){let t="";for(let r=0;r<n.length;r++)if(w(n[r])){let p=H.indexOf(n[r]);t+=`${p}`}else t+=n[r];let o=Re(e)+"_"+t,i=Be.get(o);return i===void 0?i=0:i++,Be.set(o,i),o+(i==0?"":`_${i}`)}var Te="__yo_self";var or=`(fn(${Te} : Self) -> unit)`,ir=`(fn(${Te} : Self) -> unit)`,ar=`(fn(${Te} : Self) -> Self)`;var Ee=null;function qe(){if(Ee)return Ee;let e=We(),n=je(e),t={id:"unit",tag:"unit",module:n};return n.receiverType=t,Ee=t,t}function je(e){return{id:`module_${de(e.modulePath)}`,tag:"Module",fields:[],env:e,module:void 0}}function S(e){return(e==null?void 0:e.tag)==="FuncCall"}function k(e){return(e==null?void 0:e.tag)==="Atom"}function U(e){return e.tag==="Atom"&&e.token.type==="operator"}function P(e,n,t){if(e.tag!=="FuncCall"||e.func.tag!=="Atom")return!1;let o=e.func.token.value;return e.func.token.type==="backtick_identifier"&&(o=o.slice(1,-1)),e.tag==="FuncCall"&&e.func.tag==="Atom"&&(typeof n=="string"?o===n:n.includes(o))&&(t===void 0||e.args.length===t)}var _={compt:["compt"],ref:["ref"],forall:["forall","\u2200"],where:["where"],quote:["quote",":"],unquote:["unquote","#"],unquote_splicing:["unquote_splicing","...#"],return:["return"],recur:["recur"],fn:["fn"],unsafe_fn:["unsafe_fn"],extern:["extern"],cond:["cond"],type:["type"],match:["match"],test:["test"],struct:["struct"],object:["object"],newtype:["newtype"],enum:["enum"],union:["union"],module:["module"],impl:["impl"],Impl:["Impl"],begin:["begin"],module_begin:["module_begin"],import:["import"],export:["export"],open:["open"],clone:["clone","%"],break:["break"],continue:["continue"],while:["while"],if:["if"],op_and:["&&"],op_or:["||"],not:["not"],gensym:["gensym"],dyn:["dyn"],Dyn:["Dyn"],Fn:["Fn"],c_include:["c_include"],undefined:["undefined"],null:["null"],true:["true"],false:["false"],unique:["unique","^"],Ptr:["*"],Iso:["Iso"],Tuple:["Tuple"],Array:["Array"],Slice:["Slice"],Future:["Future"],Concrete:["Concrete"],Type:["Type"],Module:["Module"],ComptList:["ComptList"],tuple:"tuple",array:"array",compt_list:"compt_list"};function z(e){return!!(e.tag==="FuncCall"&&e.isInfix&&e.func.tag==="Atom"&&(e.func.token.type==="operator"||e.func.token.type==="backtick_identifier")&&e.args.length===2)}function T(e,n){let o={...{prettyPrint:!1,indentSize:2,maxLineLength:80,indentLevel:0},...n};return o.prettyPrint?h(e,o):b(e)}function b(e){let n="";switch(e.tag){case"Atom":{n=e.token.value;break}case"FuncCall":{if(e.func.tag==="Atom"&&(e.func.token.type==="operator"||e.func.token.type==="."||e.func.token.type==="backtick_identifier")){if(e.args.length===1){e.func.token.value==="."?n=`${e.func.token.value}${b(e.args[0])}`:n=`${e.func.token.value}(${b(e.args[0])})`;break}else if(e.args.length===2&&e.isInfix){let i=b(e.args[0]),r=b(e.args[1]);i=z(e.args[0])||U(e.args[0])?`(${i})`:i,r=z(e.args[1])||U(e.args[1])?`(${r})`:r,e.func.token.value==="."?n=`(${i}.${r})`:n=`${i} ${e.func.token.value} ${r}`;break}}if(e.func.tag==="Atom"&&e.func.token.type==="identifier"&&e.func.token.value===_.tuple){e.args.length===1?n=`(${b(e.args[0])},)`:n=`(${e.args.map(i=>b(i)).join(", ").trim()})`;break}let t=b(e.func);t=z(e.func)||U(e.func)?`(${t})`:t;let o=e.args.map(i=>b(i)).join(", ").trim();n=`${t}(${o})`;break}}return n}function h(e,n){let t=" ".repeat(n.indentLevel*n.indentSize),o={...n,indentLevel:n.indentLevel+1},i=" ".repeat(o.indentLevel*n.indentSize);switch(e.tag){case"Atom":return e.token.value;case"FuncCall":{if(e.func.tag==="Atom"&&(e.func.token.type==="operator"||e.func.token.type==="."||e.func.token.type==="backtick_identifier")){if(e.args.length===1){if(e.func.token.value===".")return`${e.func.token.value}${h(e.args[0],n)}`;{let f=h(e.args[0],n);return`${e.func.token.value}(${f})`}}else if(e.args.length===2&&e.isInfix){let f=h(e.args[0],n),c=h(e.args[1],n);return f=z(e.args[0])||U(e.args[0])?`(${f})`:f,c=z(e.args[1])||U(e.args[1])?`(${c})`:c,e.func.token.value==="."?`(${f}.${c})`:`${f} ${e.func.token.value} ${c}`}}if(e.func.tag==="Atom"&&e.func.token.type==="identifier"&&e.func.token.value===_.tuple){if(e.args.length===0)return"()";if(e.args.length===1)return`(${h(e.args[0],n)},)`;{let f=e.args.map(l=>h(l,n)),c=`(${f.join(", ")})`;return c.length<=n.maxLineLength?c:`(
36
36
  ${i}${f.join(`,
37
37
  ${i}`)}
38
38
  ${t})`}}let r=e.func.tag==="Atom"?e.func.token.value:null,p=r&&[..._.begin,..._.cond,..._.match,..._.fn,..._.if,..._.while].includes(r),s=h(e.func,n);if(s=z(e.func)||U(e.func)?`(${s})`:s,e.args.length===0)return`${s}()`;if(!p){let f=e.args.map(l=>h(l,n)),c=`${s}(${f.join(", ")})`;if(c.length<=n.maxLineLength)return c}if(p){if(r===_.begin[0]){if(e.args.length===1){let c=h(e.args[0],n);if(c.length<=n.maxLineLength&&!c.includes(`
@@ -48,4 +48,4 @@ ${i}`)}
48
48
  ${t})`}}let u=e.args.map(f=>h(f,o));return`${s}(
49
49
  ${i}${u.join(`,
50
50
  ${i}`)}
51
- ${t})`}}return b(e)}var Ft={tag:"Unit",type:Ne()};var ke=new Map,ae=new Map,wt=new Map;function We(e){for(let[n,t]of ae.entries()){let o=t.filter(i=>i.sourceModulePath!==e);o.length===0?ae.delete(n):ae.set(n,o)}}function He(){ke.clear(),ae.clear(),wt.clear()}function Ke(e){let n=ke.get(e);if(n){for(let t of n)t.fields=t.fields.filter(o=>o.sourceModulePath!==e);ke.delete(e)}}function Ze({modulePath:e,inputString:n}){return{functionDeclarationFrameLevel:-1,frames:[],freeVariables:[],modulePath:e,inputString:n}}function Re(){let e=Ze({modulePath:"",inputString:""});return j(e)}function j(e,n={id:Te(e.modulePath,"frame"),variables:[],isBeginBlockFrame:!1},t){let o=t?{...n,isBeginBlockFrame:!0}:n;return{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,freeVariables:e.freeVariables,frames:[...e.frames,o],modulePath:e.modulePath,inputString:e.inputString}}var Ba=process.env.YO_SKIP_PRELUDE==="1"||process.env.YO_SKIP_PRELUDE==="true";0&&(module.exports={IdentifierRegex,Operators,PlaceholderToken,RAIIToken,TokenType,charIsOperator,clearAllGlobalImplState,clearGenericImplsFromModule,clearImplsFromModule,findMatchingBracketTokenIndex,generateExprFromCode,stringIsOperator,tokenize});
51
+ ${t})`}}return b(e)}var Ft={tag:"Unit",type:qe()};var Se=new Map,X=new Map,It=new Map;function Ye(e){for(let[n,t]of X.entries()){let o=t.filter(i=>i.sourceModulePath!==e);o.length===0?X.delete(n):X.set(n,o)}}function Ze(){Se.clear(),X.clear(),It.clear()}function Qe(e){let n=Se.get(e);if(n){for(let t of n)t.fields=t.fields.filter(o=>o.sourceModulePath!==e);Se.delete(e)}}function Je({modulePath:e,inputString:n}){return{functionDeclarationFrameLevel:-1,frames:[],freeVariables:[],modulePath:e,inputString:n}}function We(){let e=Je({modulePath:"",inputString:""});return j(e)}function j(e,n={id:ge(e.modulePath,"frame"),variables:[],isBeginBlockFrame:!1},t){let o=t?{...n,isBeginBlockFrame:!0}:n;return{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,freeVariables:e.freeVariables,frames:[...e.frames,o],modulePath:e.modulePath,inputString:e.inputString}}var ja=process.env.YO_SKIP_PRELUDE==="1"||process.env.YO_SKIP_PRELUDE==="true";0&&(module.exports={IdentifierRegex,Operators,PlaceholderToken,RAIIToken,TokenType,charIsOperator,clearAllGlobalImplState,clearGenericImplsFromModule,clearImplsFromModule,findMatchingBracketTokenIndex,generateExprFromCode,stringIsOperator,tokenize});