change the way text suggestions are rendered + option to disable syntactic sugar

This commit is contained in:
Joeri Exelmans 2025-05-15 22:22:45 +02:00
parent ea8c015eff
commit 2d81e42447
12 changed files with 357 additions and 291 deletions

View file

@ -1,4 +1,4 @@
import {getType, getInst, getSymbol, Double, Int, symbolFunction, symbolProduct, symbolSum, symbolDict, symbolSet, symbolList, eqType, match, getLeft, getRight, dict, Bool, set} from "dope2";
import {getType, getInst, getSymbol, Double, Int, symbolFunction, symbolProduct, symbolSum, symbolDict, symbolSet, symbolList, eqType, match, getLeft, getRight, dict, Bool, set, Unit} from "dope2";
import "./Value.css";
@ -14,6 +14,9 @@ export function Value({dynamic}) {
if (eqType(type)(Bool)) {
return <ValueBool val={inst}/>;
}
if (eqType(type)(Unit)) {
return <ValueUnit/>;
}
const symbol = getSymbol(type);
switch (symbol) {
@ -47,9 +50,6 @@ function ValueFunction() {
function ValueBool({val}) {
return <span className="valuePrimitive">{val.toString()}</span>;
}
// function Sum({val, elemType}) {
// return
// }
function ValueList({val, elemType}) {
return <span className="listType">[{val.map((v, i) => <Value key={i} dynamic={{i:v, t:elemType}}/>)}]</span>;
}
@ -57,9 +57,10 @@ function ValueSet({val, elemType}) {
return <span className="setType">{'{'}{set.fold(acc => elem => acc.concat([elem]))([])(val).map((v, i) => <Value key={i} dynamic={{i:v, t:elemType}}/>)}{'}'}</span>;
}
function ValueDict({val, keyType, valueType}) {
return <span className="dictType">{'{'}{set.fold(acc => key => value => acc.concat([[key,value]]))([])(val).map(([key, value], i) => <span key={i}>
<Value key={i} dynamic={{i:key, t:keyType}}/>
<Value key={i} dynamic={{i:value, t:valueType}}/>
return <span className="dictType">{'{'}{dict.fold(acc => key => value => acc.concat([[key,value]]))([])(val).map(([key, value], i) => <span key={i}>
<Value dynamic={{i:key, t:keyType}}/>
&rArr;
<Value dynamic={{i:value, t:valueType}}/>
</span>)}{'}'}</span>;
}
function ValueSum({val, leftType, rightType}) {
@ -70,23 +71,6 @@ function ValueSum({val, leftType, rightType}) {
function ValueProduct({val, leftType, rightType}) {
return <span className="productType">(<Value dynamic={{i:getLeft(val), t:leftType}}/>,&nbsp;<Value dynamic={{i:getRight(val), t:rightType}} />)</span>;
}
// function ValueDict({val, keyType, valueType}) {
// let i=0;
// return <span className="dictType">{'{'}<>{
// dict.fold
// (acc => key => value => {
// console.log({acc, key, value});
// return acc.concat([<>
// <Value key={i++} dynamic={{i: key, t: keyType}}/>
// &rArr;
// <Value key={i++} dynamic={{i: value, t: valueType}}/>
// </>]);
// })
// ([])
// (val)
// .map(result => {
// console.log(result);
// return result;
// })
// }</>{'}'}</span>;
// }
function ValueUnit() {
return <>{'()'}</>;
}