Fixing bugs. escaping things when pretty printing. adding reflect host function. getting further with tree view
This commit is contained in:
parent
f27b946790
commit
fec18486d8
5 changed files with 165 additions and 73 deletions
|
|
@ -129,6 +129,31 @@ export const _rt = {
|
|||
return { _tag: 'Ok' };
|
||||
},
|
||||
|
||||
reflect: (value: any): any => {
|
||||
if (value === null || value === undefined) return { _tag: 'NoneValue' };
|
||||
if (typeof value === 'number') return { _tag: 'NumberValue', _0: value };
|
||||
if (typeof value === 'string') return { _tag: 'StringValue', _0: value };
|
||||
if (Array.isArray(value)) return { _tag: 'ListValue', _0: value.map(_rt.reflect) };
|
||||
if (typeof value === 'function') {
|
||||
const source = value._astId !== undefined && astRegistry.get(value._astId)
|
||||
? prettyPrint(astRegistry.get(value._astId)!)
|
||||
: '<native>';
|
||||
return { _tag: 'FunctionValue', _0: source };
|
||||
}
|
||||
if (typeof value === 'object' && value._tag) {
|
||||
if ('_0' in value) return { _tag: 'ConstructorValue', _0: { tag: value._tag, value: _rt.reflect(value._0) } };
|
||||
return { _tag: 'ConstructorValue', _0: { tag: value._tag } };
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
const entries = Object.entries(value).map(([k, v]) => ({
|
||||
key: k,
|
||||
value: _rt.reflect(v)
|
||||
}));
|
||||
return { _tag: 'RecordValue', _0: entries };
|
||||
}
|
||||
return { _tag: 'NoneValue' };
|
||||
},
|
||||
|
||||
eval: (code: string) => {
|
||||
const trimmed = code.trim();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue