File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 1+ import { either } from '../../adts.js'
12import type { Atom , Molecule } from '../parsing.js'
3+ import { unparse } from '../unparsing.js'
4+ import { prettyPlz } from '../unparsing/pretty-plz.js'
25
36export const functionParameter = Symbol ( 'functionParameter' )
47export const functionReturn = Symbol ( 'functionReturn' )
@@ -15,7 +18,14 @@ export type KeyPath = readonly (
1518) [ ]
1619
1720export const stringifyKeyPathForEndUser = ( keyPath : KeyPath ) : string =>
18- JSON . stringify ( keyPath )
21+ either . match (
22+ // TODO: Use single-line plz notation.
23+ unparse ( keyPathToMolecule ( keyPath ) , prettyPlz ) ,
24+ {
25+ right : stringifiedOutput => stringifiedOutput ,
26+ left : error => `(unserializable key path: ${ error . message } )` ,
27+ } ,
28+ )
1929
2030export const keyPathToMolecule = ( keyPath : KeyPath ) : Molecule =>
2131 Object . fromEntries (
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ import type {
66} from '../errors.js'
77import type { Atom , Molecule } from '../parsing.js'
88import type { Canonicalized } from '../parsing/syntax-tree.js'
9+ import { unparse } from '../unparsing.js'
10+ import { prettyPlz } from '../unparsing/pretty-plz.js'
911import { serializeFunctionNode , type FunctionNode } from './function-node.js'
1012import { stringifyKeyPathForEndUser , type KeyPath } from './key-path.js'
1113import {
@@ -174,7 +176,17 @@ export const serialize = (
174176
175177export const stringifySemanticGraphForEndUser = (
176178 graph : SemanticGraph ,
177- ) : string => JSON . stringify ( serialize ( graph ) )
179+ ) : string =>
180+ either . match (
181+ either . flatMap ( serialize ( graph ) , output =>
182+ // TODO: Use single-line plz notation.
183+ unparse ( output , prettyPlz ) ,
184+ ) ,
185+ {
186+ right : stringifiedOutput => stringifiedOutput ,
187+ left : error => `(unserializable value: ${ error . message } )` ,
188+ } ,
189+ )
178190
179191export const isSemanticGraph = (
180192 value :
You can’t perform that action at this time.
0 commit comments