@shd101wyy/yo 0.0.8 → 0.0.9
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.
- package/README.md +2 -2
- package/out/cjs/index.cjs +31 -29
- package/out/cjs/yo-cli.cjs +452 -450
- package/out/esm/index.mjs +31 -29
- package/out/types/src/env.d.ts +0 -1
- package/out/types/src/evaluator/index.d.ts +3 -1
- package/out/types/src/module-manager.d.ts +8 -1
- package/out/types/src/parser.d.ts +2 -0
- package/out/types/src/token.d.ts +1 -1
- package/out/types/src/types/creators.d.ts +1 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/fmt/index.yo +74 -0
- package/std/fmt/to_string.yo +193 -0
- package/std/io/file.yo +2 -2
- package/std/libc/stdio.yo +2 -2
- package/std/libc/string.yo +2 -2
- package/std/libc/unistd.yo +2 -2
- package/std/prelude.yo +70 -101
- package/std/string/string.yo +55 -4
package/README.md
CHANGED
|
@@ -50,10 +50,10 @@ Check the `./tests` and `./std` folders for code examples.
|
|
|
50
50
|
### Hello World
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
|
-
|
|
53
|
+
{ println } :: import "std/fmt";
|
|
54
54
|
|
|
55
55
|
main :: (fn() -> unit) {
|
|
56
|
-
|
|
56
|
+
println("Hello, world!");
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
export main;
|
package/out/cjs/index.cjs
CHANGED
|
@@ -1,51 +1,53 @@
|
|
|
1
|
-
var
|
|
2
|
-
${
|
|
1
|
+
var nt=Object.create;var j=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var it=Object.getPrototypeOf,at=Object.prototype.hasOwnProperty;var st=(e,t)=>{for(var n in t)j(e,n,{get:t[n],enumerable:!0})},Ie=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ot(t))!at.call(e,i)&&i!==n&&j(e,i,{get:()=>t[i],enumerable:!(o=rt(t,i))||o.enumerable});return e};var lt=(e,t,n)=>(n=e!=null?nt(it(e)):{},Ie(t||!e||!e.__esModule?j(n,"default",{value:e,enumerable:!0}):n,e)),ut=e=>Ie(j({},"__esModule",{value:!0}),e);var Ut={};st(Ut,{IdentifierRegex:()=>H,Operators:()=>G,PlaceholderToken:()=>O,RAIIToken:()=>pt,TokenType:()=>S,charIsOperator:()=>I,clearAllGlobalImplState:()=>Je,clearGenericImplsFromModule:()=>Ze,clearImplsFromModule:()=>Qe,findMatchingBracketTokenIndex:()=>se,generateExprFromCode:()=>K,stringIsOperator:()=>ae,tokenize:()=>le});module.exports=ut(Ut);var At=require("node:fs"),Pt=lt(require("path"));var C=class{constructor({characterIndex:t,message:n}){this.characterIndex=t,this.message=n}},W=class{constructor(t,n,o){this.tokenAndErrorList=[];this.tokenAndErrorList=t,this.isAssertionError=n||!1,this.kind=o}toString(){return this.tokenAndErrorList.map(({token:n,errorMessage:o})=>`Error: ${o}
|
|
2
|
+
${Ae({token:n})}`).join(`
|
|
3
3
|
|
|
4
|
-
`)}};function
|
|
5
|
-
`)[i];return`${
|
|
4
|
+
`)}};function Ae({token:e}){let{position:t,modulePath:n,inputString:o}=e,{row:i,column:r}=t,s=o.split(`
|
|
5
|
+
`)[i];return`${n}:${i+1}:${r+1}:
|
|
6
6
|
${s}
|
|
7
|
-
${" ".repeat(r+Math.floor(e.value.length/2))}^`}function
|
|
7
|
+
${" ".repeat(r+Math.floor(e.value.length/2))}^`}function m({token:e,errorMessage:t,cause:n,isAssertionError:o,kind:i}){let r=`${t.trim()}
|
|
8
8
|
|
|
9
|
-
${
|
|
10
|
-
`+
|
|
11
|
-
`:case"\r":{let
|
|
12
|
-
`||e[
|
|
13
|
-
`&&(o++,i=
|
|
14
|
-
`&&
|
|
15
|
-
`&&(i=
|
|
16
|
-
|
|
9
|
+
${Ae({token:e})}`;return new W([{token:e,errorMessage:r+(n!=null&&n.message?`
|
|
10
|
+
`+n.message:"")}],o,i)}var S=(g=>(g.Operator="operator",g.Dot=".",g.LParen="(",g.RParen=")",g.LBracket="[",g.RBracket="]",g.LCurlyBracket="{",g.RCurlyBracket="}",g.Char="char",g.String="string",g.Identifier="identifier",g.Integer="integer",g.Float="float",g.Bool="bool",g.Semicolon=";",g.Comma=",",g.SingleLineComment="single_line_comment",g.MultiLineComment="multi_line_comment",g.Whitespace="whitespace",g.TemplateString="template_string",g))(S||{}),O={modulePath:"_",inputString:"_",type:"identifier",value:"_",position:{row:0,column:0,character:0}},pt={modulePath:"drop",inputString:"drop",type:"identifier",value:"drop",position:{row:0,column:0,character:0}},G=["=","+","-","*","/","<",">","@","$","~","&","%","|","!","?","^",".",":","\\","#"];function I(e){return G.includes(e)}function ae(e){let t=!0;for(let n=0;n<e.length;n++){let o=e[n];if(!I(o)){t=!1;break}}return t}var H=/^[_a-zA-Z\xA0-\uFFFF][_a-zA-Z0-9\xA0-\uFFFF]*[!?]?$/;function se(e,t){let n=")";if(!e[t])return-1;let o=e[t].type;if(o==="{")n="}";else if(o==="(")n=")";else if(o==="[")n="]";else throw this.formatErrorMessage(e[t],"Expected '{', '(' or '['");t=t+1;let i=1,r=-1;for(;;){let p=e[t];if(!p)return-1;if(p.type===n){if(i=i-1,i===0){r=t;break}}else p.type===o&&(i=i+1);t=t+1}return r}function le(e,t){let n=[],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(;I(e[c])&&e[c]!==".";)f+=e[c],c=c+1;if(f&&!f.startsWith("//")&&!f.startsWith("/*")){n.push({type:f==="."?".":"operator",value:f,position:{row:o,column:s,character:u},modulePath:t,inputString:e}),r=c-1;continue}switch(p){case" ":case" ":case`
|
|
11
|
+
`:case"\r":{let a="",l=r,y=o;for(;e[l]===" "||e[l]===" "||e[l]===`
|
|
12
|
+
`||e[l]==="\r";)a+=e[l],e[l]===`
|
|
13
|
+
`&&(o++,i=l+1),l=l+1;n.push({type:"whitespace",value:a,position:{row:y,column:s,character:u},modulePath:t,inputString:e}),r=l-1;break}case"/":if(e[r+1]==="/"){let a="",l=r;for(;e[l]!==`
|
|
14
|
+
`&&l<e.length;)a+=e[l],l=l+1;n.push({type:"single_line_comment",value:a,position:{row:o,column:s,character:u},modulePath:t,inputString:e}),r=l-1}else if(e[r+1]==="*"){let a=r,l="",y=o,d=1;for(l+=e[a],a++,l+=e[a],a++;d>0&&a<e.length;){if(e[a]===`
|
|
15
|
+
`&&(i=a+1,o++),e[a]==="/"&&e[a+1]==="*"){d++,l+="/*",a+=2;continue}if(e[a]==="*"&&e[a+1]==="/"){d--,l+="*/",a+=2;continue}l+=e[a],a++}if(d>0)throw new C({message:"Unterminated multi-line comment",characterIndex:e.length-1});n.push({type:"multi_line_comment",value:l,position:{row:y,column:s,character:u},modulePath:t,inputString:e}),r=a-1}else throw new C({message:`Unexpected character ${p}`,characterIndex:r+1});break;case"(":n.push({type:"(",value:p,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break;case")":n.push({type:")",value:p,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break;case"[":n.push({type:"[",value:p,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break;case"]":n.push({type:"]",value:p,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break;case"{":n.push({type:"{",value:p,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break;case"}":n.push({type:"}",value:p,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break;case"'":{let a="";for(let l=r+1;l<e.length;l++){if(e[l]==="\\"){a+=e[l],l=l+1,a+=e[l];continue}if(e[l]==="'"){r=l;break}a+=e[l]}if(a.length===1||a.length===2&&a[0]==="\\")n.push({type:"char",value:`'${a}'`,position:{row:o,column:s,character:u},modulePath:t,inputString:e});else throw new C({message:`Invalid char '${a}', expected char to have length 1.`,characterIndex:r});break}case'"':{let a="";for(let l=r+1;l<e.length;l++){if(e[l]==="\\"){a+=e[l],l=l+1,a+=e[l];continue}if(e[l]==='"'){r=l;break}a+=e[l]}n.push({type:"string",value:`"${a}"`,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break}case"`":{let a="",l=0,y=r+1;for(;y<e.length;){if(e[y]==="\\"&&y+1<e.length){let d=e[y+1];if(d==="$"){a+="\\$",y=y+2;continue}else{switch(y=y+1,d){case"n":a+=`
|
|
16
|
+
`;break;case"t":a+=" ";break;case"r":a+="\r";break;case"\\":a+="\\";break;case'"':a+='"';break;case"'":a+="'";break;case"`":a+="`";break;case"0":a+="\0";break;case"b":a+="\b";break;case"f":a+="\f";break;case"v":a+="\v";break;default:a+="\\",a+=d;break}y=y+1;continue}}if(l===0&&e[y]==="$"&&e[y+1]==="{"){a+="${",y=y+2,l=1;continue}if(l>0){e[y]==="{"?l=l+1:e[y]==="}"&&(l=l-1),a+=e[y],y=y+1;continue}if(e[y]==="`"){r=y;break}e[y]===`
|
|
17
|
+
`&&(o++,i=y+1),a+=e[y],y=y+1}if(y>=e.length&&e[y]!=="`")throw new C({message:"Unterminated template string",characterIndex:r});n.push({type:"template_string",value:a,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break}case",":n.push({type:",",value:p,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break;case";":n.push({type:";",value:p,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break;default:if(/[0-9]/.test(p)){let a=r,l=p;r=r+1;let y=/[0-9_]/;for(e[r-1]==="0"&&typeof e[r]=="string"&&(e[r]==="x"||e[r]==="X"?(l+=e[r],r=r+1,y=/[0-9A-Fa-f]/):e[r]==="b"||e[r]==="B"?(l+=e[r],r=r+1,y=/[01]/):(e[r]==="o"||e[r]==="O")&&(l+=e[r],r=r+1,y=/[0-7]/));typeof e[r]=="string"&&y.test(e[r]);)l+=e[r],r=r+1;if(e[r]==="."&&e[a-1]!=="."&&(e[r+1]??"").match(/[0-9]/)){for(l+=e[r],r=r+1;typeof e[r]=="string"&&/[0-9_]/.test(e[r]);)l+=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(l+=e[r],r=r+1,(e[r]==="+"||e[r]==="-")&&(l+=e[r],r=r+1);typeof e[r]=="string"&&/[0-9_]/.test(e[r]);)l+=e[r],r=r+1;n.push({type:"float",value:l,position:{row:o,column:s,character:u},modulePath:t,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(l+=e[r],r=r+1,(e[r]==="+"||e[r]==="-")&&(l+=e[r],r=r+1);typeof e[r]=="string"&&/[0-9_]/.test(e[r]);)l+=e[r],r=r+1;n.push({type:"integer",value:l,position:{row:o,column:s,character:u},modulePath:t,inputString:e}),r=r-1}}else if(/[_a-zA-Z\xA0-\uFFFF]/.test(p)){let a=p,l=r;for(r=r+1;typeof e[r]=="string"&&/[_a-zA-Z0-9\xA0-\uFFFF]/.test(e[r]);)a+=e[r],r=r+1;if(r=r-1,(e[r+1]==="!"||e[r+1]==="?")&&H.test(a+e[r+1])&&(r=r+1,a+=e[r]),H.test(a))switch(a){case"true":case"false":n.push({type:"bool",value:a,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break;default:n.push({type:"identifier",value:a,position:{row:o,column:s,character:u},modulePath:t,inputString:e});break}else throw new C({message:`Invalid identifier ${a}`,characterIndex:l})}else throw new C({message:`Unexpected character ${p}`,characterIndex:r});break}}return n}var B=class e{constructor({modulePath:t,inputString:n}){this.hasTemplateString=!1;this.modulePath=t,this.inputString=n,this.tokens=le(n,t),this.program=[],this.parse(this.tokens)}skipWhitespace(t,n){for(;t[n]&&(t[n].type==="whitespace"||t[n].type==="single_line_comment"||t[n].type==="multi_line_comment");)n=n+1;return n}skipWhitespaceBackward(t,n){for(;t[n]&&(t[n].type==="whitespace"||t[n].type==="single_line_comment"||t[n].type==="multi_line_comment");)n=n-1;return n}isParenthesizedExpression(t,n,o){return n=this.skipWhitespace(t,n),o=this.skipWhitespaceBackward(t,o),!!t[n]&&t[n].type==="("&&!!t[o]&&t[o].type===")"&&se(t,n)===o}parseTemplateString({token:t,index:n}){this.hasTemplateString=!0;let o=t.value,i=[],r="",p=0;for(;p<o.length;){if(o[p]==="\\"&&o[p+1]==="$"){r+="$",p+=2;continue}if(o[p]==="$"&&o[p+1]==="{"){r.length>0&&(i.push({type:"string",value:r}),r="");let u=1,f=p+2,c=f;for(;c<o.length&&u>0;)o[c]==="{"?u++:o[c]==="}"&&u--,u>0&&c++;let a=o.substring(f,c);i.push({type:"expr",value:a}),p=c+1;continue}r+=o[p],p++}r.length>0&&i.push({type:"string",value:r}),i.length===0&&i.push({type:"string",value:""});let s=null;for(let u of i){let f;if(u.type==="string"){let c={type:"string",value:JSON.stringify(u.value),position:t.position,modulePath:t.modulePath,inputString:t.inputString},a={tag:"Atom",token:c},l={tag:"FuncCall",func:{tag:"Atom",token:{type:".",value:".",position:t.position,modulePath:t.modulePath,inputString:t.inputString}},args:[a,{tag:"Atom",token:{type:"identifier",value:"to_string",position:t.position,modulePath:t.modulePath,inputString:t.inputString}}],isInfix:!0,token:t};f={tag:"FuncCall",func:l,args:[],token:t}}else{let a=new e({modulePath:t.modulePath,inputString:u.value}).getProgram();if(a.length===0)throw m({token:t,errorMessage:"Empty expression in template string interpolation"});let l=a[0],y={tag:"FuncCall",func:{tag:"Atom",token:{type:".",value:".",position:t.position,modulePath:t.modulePath,inputString:t.inputString}},args:[l,{tag:"Atom",token:{type:"identifier",value:"to_string",position:t.position,modulePath:t.modulePath,inputString:t.inputString}}],isInfix:!0,token:t};f={tag:"FuncCall",func:y,args:[],token:t}}if(s===null)s=f;else{let c={tag:"FuncCall",func:{tag:"Atom",token:{type:".",value:".",position:t.position,modulePath:t.modulePath,inputString:t.inputString}},args:[s,{tag:"Atom",token:{type:"operator",value:"+",position:t.position,modulePath:t.modulePath,inputString:t.inputString}}],isInfix:!0,token:t};s={tag:"FuncCall",func:c,args:[f],token:t}}}return{expr:s,index:n+1}}parseParenExpr({tokens:t,index:n}){var p;let o=n;if(t[n].type!=="(")throw m({token:t[n],errorMessage:"Expected left paren"});if(((p=t[n+1])==null?void 0:p.type)===")")return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:_.tuple,position:t[n].position,modulePath:this.modulePath,inputString:this.inputString}},args:[],token:t[n]},index:n+2};let i=this.parseExpression({tokens:t,index:n+1}),r=i.expr;if(n=i.index,t[n].type===")")return{expr:r,index:n+1};{let s,u=[r];for(;;){if(!t[n])throw m({token:t[n-1],errorMessage:"Expected ) or , for tuple"});if(t[n].type===","){if(!s||s===",")s=",";else throw m({token:t[n],errorMessage:'Cannot mix "," with ";" as separator in (...)'});n=n+1}else if(t[n].type===";"){if(!s||s===";")s=";";else throw m({token:t[n],errorMessage:'Cannot mix ";" with "," as separator in (...)'});n=n+1}if(n=this.skipWhitespace(t,n),t[n].type===")")break;let{expr:c,index:a}=this.parseExpression({tokens:t,index:n});u.push(c),n=a}let f=s===";"||!s;return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:f?_.Tuple[0]:_.tuple,position:t[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:u,token:t[o]},index:n+1}}}parseArrayExpr({tokens:t,index:n}){let o=n;if(t[n].type!=="[")throw m({token:t[n],errorMessage:"Expected left bracket"});n=n+1;let i,r=[];for(;;){if(!t[n])throw m({token:t[n-1],errorMessage:"Expected ] or , for array"});if(t[n].type===","){if(!i||i===",")i=",";else throw m({token:t[n],errorMessage:'Cannot mix "," with ";" as separator in [...]'});n=n+1}else if(t[n].type===";"){if(!i||i===";")i=";";else throw m({token:t[n],errorMessage:'Cannot mix ";" with "," as separator in [...]'});n=n+1}if(t[n].type==="]")break;let{expr:f,index:c}=this.parseExpression({tokens:t,index:n});r.push(f),n=c}let p=i===";"||!i;if(p&&r.length>2)throw m({token:t[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:t[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:r,token:t[o]},index:n+1}}parseCurlyBracketExpr({tokens:t,index:n}){let o=n;if(t[n].type!=="{")throw m({token:t[n],errorMessage:"Expected left curly bracket"});let i=[],r;for(n=n+1;;){if(n=this.skipWhitespace(t,n),!t[n])throw m({token:t[n-1],errorMessage:'Unexpected end of curly bracket. Expected "}" or "," or ";"'});if(t[n].type===","){if(!r||r===",")r=",";else throw m({token:t[n],errorMessage:'Cannot mix "," with ";" as separator in {...}'});n=n+1}else if(t[n].type===";"){if(!r||r===";")r=";";else throw m({token:t[n],errorMessage:'Cannot mix ";" with "," as separator in {...}'});n=n+1}if(n=this.skipWhitespace(t,n),t[n].type==="}"){let u=t[this.skipWhitespaceBackward(t,n-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:t,index:n});i.push(p),n=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:t[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:t[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:i,token:t[o]},index:n+1}}else return{expr:{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:_.begin[0],position:t[o].position,modulePath:this.modulePath,inputString:this.inputString}},args:i,token:t[o]},index:n+1}}parsePrimary({tokens:t,index:n}){n=this.skipWhitespace(t,n);let o=t[n];if(!o)throw m({token:O,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:n+1};break}case"(":{i=this.parseParenExpr({tokens:t,index:n});break}case"[":{i=this.parseArrayExpr({tokens:t,index:n});break}case"{":{i=this.parseCurlyBracketExpr({tokens:t,index:n});break}case".":{i={expr:{tag:"Atom",token:o},index:n+1};break}case"template_string":{i=this.parseTemplateString({token:o,index:n});break}default:throw m({token:o,errorMessage:`Unexpected token "${o.type}"`})}return i}isOperatorAtLineStart(t,n){for(let o=t.length-1;o>=0;o--){let i=t[o];if(i.type==="whitespace"&&i.value.includes(`
|
|
18
|
+
`))return t.slice(o+1).every(s=>s.type==="whitespace");if(i.type!=="whitespace")return!1}return t.every(o=>o.type==="whitespace")}parseLeftAssociativeOperator({primaryExpr:t,operatorToken:n,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:n},args:[t,p],isInfix:!0,token:n};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:n},args:[t,o],isInfix:!0,token:n},tokens:i,index:r})}getExprMinimumColumnNumber(t){return k(t)?t.token.position.column:Math.min(this.getExprMinimumColumnNumber(t.func),...t.args.map(n=>this.getExprMinimumColumnNumber(n)))}parsePrimaryEnd({primaryExpr:t,tokens:n,index:o}){var f,c,a,l,y;let i=this.skipWhitespace(n,o),r=i!==o,p=((f=n[o-1])==null?void 0:f.type)==="whitespace";o=i;let s=n[i];if(!s||s.type===";"||s.type===","||s.type===")"||s.type==="]"||s.type==="}")return{expr:t,index:o};let u=t.tag==="Atom"&&t.token.type===".";if(u||s.type==="."&&!r&&!p&&((c=n[i+1])==null?void 0:c.type)!=="whitespace"){let{expr:d,index:v}=this.parsePrimary({tokens:n,index:u?o:o+1});o=v;let E={expr:{tag:"FuncCall",func:{tag:"Atom",token:u?t.token:s},args:u?[d]:[t,d],isInfix:!u,token:u?t.token:s},index:o};for(;n[o]&&n[o].type===".";){let{expr:L,index:re}=this.parsePrimary({tokens:n,index:o+1});E={expr:{tag:"FuncCall",func:{tag:"Atom",token:s},args:[E.expr,L],isInfix:!0,token:s},index:re},o=re}return this.parsePrimaryEnd({primaryExpr:E.expr,tokens:n,index:E.index})}else if((s.type==="operator"||s.type==="."&&!r)&&((a=n[o+1])==null?void 0:a.type)!=="("){let d=this.skipWhitespace(n,o+1),{expr:v,index:E}=this.parseExpression({tokens:n,index:d});if(v.tag==="FuncCall"&&v.isInfix&&v.func.tag==="Atom"&&v.func.token.type!=="."&&!this.isParenthesizedExpression(n,d,E-1)){let L=`Ambiguous operator precedence.
|
|
17
19
|
Please use parentheses to clarify:
|
|
18
20
|
|
|
19
|
-
${T(
|
|
21
|
+
${T(t)} ${s.value} (${T(v)})
|
|
20
22
|
// or
|
|
21
|
-
(${T(
|
|
23
|
+
(${T(t)} ${s.value} ${T(v.args[0])}) ${T(v.func)} ${T(v.args[1])}
|
|
22
24
|
|
|
23
25
|
Or use newline after "${s.value}" to confirm the right-associativity.
|
|
24
|
-
`,
|
|
25
|
-
`)),
|
|
26
|
-
`));if(!(
|
|
27
|
-
or ) to end the function call`})}}}parseFunctionCall({func:
|
|
28
|
-
`)}parse(
|
|
26
|
+
`,et=n.slice(o+1,d).some(we=>we.type==="whitespace"&&we.value.includes(`
|
|
27
|
+
`)),g=n.slice(0,o),oe=this.isOperatorAtLineStart(g,o),ie=n.slice(o+1,d),tt=oe&&ie.length>0&&((l=ie[0])==null?void 0:l.type)==="whitespace"&&((y=ie[0])==null?void 0:y.value.includes(`
|
|
28
|
+
`));if(!(et&&!oe)){if(!tt){if(oe)return this.parseLeftAssociativeOperator({primaryExpr:t,operatorToken:s,rhs:v,tokens:n,index:E});throw m({token:s,errorMessage:L})}}}return this.parsePrimaryEnd({primaryExpr:{tag:"FuncCall",func:{tag:"Atom",token:s},args:[t,v],isInfix:!0,token:s},tokens:n,index:E})}else if(!r&&s.type==="("){let d=this.parseFunctionCall({func:t,tokens:n,index:o+1,hasWhitespace:!1});return this.parsePrimaryEnd({primaryExpr:d.expr,tokens:n,index:d.index})}else{let d=this.parseFunctionCall({func:t,tokens:n,index:o,hasWhitespace:!0});return this.parsePrimaryEnd({primaryExpr:d.expr,tokens:n,index:d.index})}}parseFunctionArguments({tokens:t,index:n,hasWhitespace:o}){var r;let i=[];if(n=this.skipWhitespace(t,n),!o&&((r=t[n])==null?void 0:r.type)===")")return{args:i,index:n+1};for(;;){let{expr:p,index:s}=this.parseExpression({tokens:t,index:n});i.push(p),n=s;let u=t[n];if((u==null?void 0:u.type)===",")n=n+1;else{if(!u||u.type===";"||u.type==="]"||u.type==="}")return{args:i,index:n};if(u.type===")")return{args:i,index:o?n:n+1};throw m({token:u,errorMessage:o?"Expected ; to end the function call":`Expected , to separate arguments
|
|
29
|
+
or ) to end the function call`})}}}parseFunctionCall({func:t,tokens:n,index:o,hasWhitespace:i}){let{args:r,index:p}=this.parseFunctionArguments({tokens:n,index:o,hasWhitespace:i});return o=p,{expr:{tag:"FuncCall",func:t,args:r,token:t.token},index:o}}parseExpression({tokens:t,index:n}){n=this.skipWhitespace(t,n);let{expr:o,index:i}=this.parsePrimary({tokens:t,index:n});return this.parsePrimaryEnd({primaryExpr:o,tokens:t,index:i})}programToString(){return this.program.map(n=>T(n)).join(`;
|
|
30
|
+
`)}parse(t){let n=0,o=[];for(;n<t.length;){switch(t[n].type){case"whitespace":case";":case"single_line_comment":case"multi_line_comment":{n=n+1;continue}}if(n>=t.length)break;try{let{expr:p,index:s}=this.parseExpression({tokens:t,index:n});o.push(p),n=s}catch(p){this.parserError=p;break}}let i=t[this.skipWhitespaceBackward(t,t.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.hasTemplateString?[{tag:"FuncCall",func:{tag:"Atom",token:{type:"identifier",value:_.import[0],position:{row:0,column:0,character:0},modulePath:this.modulePath,inputString:this.inputString}},args:[{tag:"Atom",token:{type:"string",value:JSON.stringify("std/fmt/to_string"),position:{row:0,column:0,character:0},modulePath:this.modulePath,inputString:this.inputString}}],token:{type:"identifier",value:_.import[0],position:{row:0,column:0,character:0},modulePath:this.modulePath,inputString:this.inputString}},...this.program]:this.program}getParserError(){return this.parserError}getTokens(){return this.tokens}};function K(e){let t=new B({modulePath:`auto-generated://
|
|
29
31
|
// === START auto-generated code ===
|
|
30
32
|
${e}
|
|
31
33
|
// === END auto-generated code ===
|
|
32
|
-
`,inputString:e});if(
|
|
33
|
-
${
|
|
34
|
+
`,inputString:e});if(t.getParserError())throw t.getParserError();let n=t.getProgram();if(n.length!==1)throw new Error(`Expected exactly one expression from parsed code, got ${n.length}: "${e}"
|
|
35
|
+
${n.map(o=>T(o)).join(`
|
|
34
36
|
`)}
|
|
35
|
-
`);return
|
|
37
|
+
`);return n[0]}var Re=require("crypto");function Ne(e){return"yo"+(0,Re.createHash)("sha1").update(e).digest("hex").slice(0,8)}var Oe=new Map;function ge(e){let t=Oe.get(e);return t===void 0&&(t=0),Oe.set(e,t+1),`${Ne(e)}_id_${t}`}var Be=new Map;function Te(e,t){let n="";for(let r=0;r<t.length;r++)if(I(t[r])){let p=G.indexOf(t[r]);n+=`${p}`}else n+=t[r];let o=Ne(e)+"_"+n,i=Be.get(o);return i===void 0?i=0:i++,Be.set(o,i),o+(i==0?"":`_${i}`)}var he="__yo_self";var ir=`(fn(${he} : Self) -> unit)`,ar=`(fn(${he} : Self) -> unit)`,sr=`(fn(${he} : Self) -> Self)`;var be=null;function je(){if(be)return be;let e=Ge(),t=We(e),n={id:"unit",tag:"unit",module:t};return t.receiverType=n,be=n,n}function We(e){return{id:`module_${ge(e.modulePath)}`,tag:"Module",fields:[],env:e,module:void 0}}function w(e){return(e==null?void 0:e.tag)==="FuncCall"}function k(e){return(e==null?void 0:e.tag)==="Atom"}function P(e){return e.tag==="Atom"&&e.token.type==="operator"}function z(e,t,n){if(e.tag!=="FuncCall"||e.func.tag!=="Atom")return!1;let o=e.func.token.value;return e.tag==="FuncCall"&&e.func.tag==="Atom"&&(typeof t=="string"?o===t:t.includes(o))&&(n===void 0||e.args.length===n)}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 U(e){return!!(e.tag==="FuncCall"&&e.isInfix&&e.func.tag==="Atom"&&e.func.token.type==="operator"&&e.args.length===2)}function T(e,t){let o={...{prettyPrint:!1,indentSize:2,maxLineLength:80,indentLevel:0},...t};return o.prettyPrint?h(e,o):b(e)}function b(e){let t="";switch(e.tag){case"Atom":{t=e.token.value;break}case"FuncCall":{if(e.func.tag==="Atom"&&(e.func.token.type==="operator"||e.func.token.type===".")){if(e.args.length===1){e.func.token.value==="."?t=`${e.func.token.value}${b(e.args[0])}`:t=`${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=U(e.args[0])||P(e.args[0])?`(${i})`:i,r=U(e.args[1])||P(e.args[1])?`(${r})`:r,e.func.token.value==="."?t=`(${i}.${r})`:t=`${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?t=`(${b(e.args[0])},)`:t=`(${e.args.map(i=>b(i)).join(", ").trim()})`;break}let n=b(e.func);n=U(e.func)||P(e.func)?`(${n})`:n;let o=e.args.map(i=>b(i)).join(", ").trim();t=`${n}(${o})`;break}}return t}function h(e,t){let n=" ".repeat(t.indentLevel*t.indentSize),o={...t,indentLevel:t.indentLevel+1},i=" ".repeat(o.indentLevel*t.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===".")){if(e.args.length===1){if(e.func.token.value===".")return`${e.func.token.value}${h(e.args[0],t)}`;{let f=h(e.args[0],t);return`${e.func.token.value}(${f})`}}else if(e.args.length===2&&e.isInfix){let f=h(e.args[0],t),c=h(e.args[1],t);return f=U(e.args[0])||P(e.args[0])?`(${f})`:f,c=U(e.args[1])||P(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],t)},)`;{let f=e.args.map(a=>h(a,t)),c=`(${f.join(", ")})`;return c.length<=t.maxLineLength?c:`(
|
|
36
38
|
${i}${f.join(`,
|
|
37
39
|
${i}`)}
|
|
38
|
-
${
|
|
40
|
+
${n})`}}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,t);if(s=U(e.func)||P(e.func)?`(${s})`:s,e.args.length===0)return`${s}()`;if(!p){let f=e.args.map(a=>h(a,t)),c=`${s}(${f.join(", ")})`;if(c.length<=t.maxLineLength)return c}if(p){if(r===_.begin[0]){if(e.args.length===1){let c=h(e.args[0],t);if(c.length<=t.maxLineLength&&!c.includes(`
|
|
39
41
|
`))return`${s}(${c})`}let f=e.args.map(c=>h(c,o));return`${s}(
|
|
40
42
|
${i}${f.join(`,
|
|
41
43
|
${i}`)}
|
|
42
|
-
${
|
|
43
|
-
`)){let v=
|
|
44
|
+
${n})`}else if(r===_.cond[0]){let f=e.args.map(c=>{if(w(c)&&c.isInfix&&z(c,"=>")){let a=c.args[0],l=h(c.args[1],o),y=h(a,t);if(w(a)&&a.isInfix&&!z(a,"=>")&&(y=`(${y})`),l.includes(`
|
|
45
|
+
`)){let v=l.split(`
|
|
44
46
|
`).map((E,L)=>L===0?E:`${i}${E}`).join(`
|
|
45
|
-
`);return`${
|
|
47
|
+
`);return`${y} => ${v}`}else return`${y} => ${l}`}return h(c,o)});return`${s}(
|
|
46
48
|
${i}${f.join(`,
|
|
47
49
|
${i}`)}
|
|
48
|
-
${
|
|
50
|
+
${n})`}}let u=e.args.map(f=>h(f,o));return`${s}(
|
|
49
51
|
${i}${u.join(`,
|
|
50
52
|
${i}`)}
|
|
51
|
-
${
|
|
53
|
+
${n})`}}return b(e)}var Ft={tag:"Unit",type:je()};var Me=new Map,te=new Map,ne=new Map;function Ze(e){for(let[t,n]of te.entries()){let o=n.filter(i=>i.sourceModulePath!==e);o.length===0?te.delete(t):te.set(t,o)}}function It(e){for(let[t,n]of ne.entries()){let o=n.filter(i=>i.modulePath!==e);o.length===0?ne.delete(t):ne.set(t,o)}}function Je(){Me.clear(),te.clear(),ne.clear()}function Qe(e){let t=Me.get(e);if(t){for(let n of t)n.fields=n.fields.filter(o=>o.sourceModulePath!==e);Me.delete(e),It(e)}}function Xe({modulePath:e,inputString:t}){return{functionDeclarationFrameLevel:-1,frames:[],freeVariables:[],modulePath:e,inputString:t}}function Ge(){let e=Xe({modulePath:"",inputString:""});return q(e)}function q(e,t={id:Te(e.modulePath,"frame"),variables:[],isBeginBlockFrame:!1},n){let o=n?{...t,isBeginBlockFrame:!0}:t;return{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,freeVariables:e.freeVariables,frames:[...e.frames,o],modulePath:e.modulePath,inputString:e.inputString}}var Ga=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});
|