@@ -18,16 +18,7 @@ import {
1818 type LookupExpression ,
1919 type SemanticGraph ,
2020} from '../semantics.js'
21-
22- export const dot = kleur . dim ( '.' )
23- export const quote = kleur . dim ( '"' )
24- export const colon = kleur . dim ( ':' )
25- export const comma = kleur . dim ( ',' )
26- export const openBrace = kleur . dim ( '{' )
27- export const closeBrace = kleur . dim ( '}' )
28- export const openParenthesis = kleur . dim ( '(' )
29- export const closeParenthesis = kleur . dim ( ')' )
30- export const arrow = kleur . dim ( '=>' )
21+ import { punctuation } from './unparsing-utilities.js'
3122
3223export const moleculeUnparser =
3324 (
@@ -73,6 +64,7 @@ export const moleculeAsKeyValuePairStrings = (
7364 unparseAtomOrMolecule : UnparseAtomOrMolecule ,
7465 options : { readonly ordinalKeys : 'omit' | 'preserve' } ,
7566) : Either < UnserializableValueError , readonly string [ ] > => {
67+ const { colon } = punctuation ( kleur )
7668 const entries = Object . entries ( value )
7769
7870 const keyValuePairsAsStrings : string [ ] = [ ]
@@ -110,6 +102,7 @@ export const unparseAtom = (atom: string): Right<string> =>
110102 )
111103
112104const quoteAtomIfNecessary = ( value : string ) : string => {
105+ const { quote } = punctuation ( kleur )
113106 const unquotedAtomResult = parsing . parse ( unquotedAtomParser , value )
114107 if ( either . isLeft ( unquotedAtomResult ) ) {
115108 return quote . concat ( escapeStringContents ( value ) ) . concat ( quote )
@@ -119,6 +112,7 @@ const quoteAtomIfNecessary = (value: string): string => {
119112}
120113
121114const quoteKeyPathComponentIfNecessary = ( value : string ) : string => {
115+ const { quote } = punctuation ( kleur )
122116 const unquotedAtomResult = parsing . parse ( unquotedAtomParser , value )
123117 if ( either . isLeft ( unquotedAtomResult ) || value . includes ( '.' ) ) {
124118 return quote . concat ( escapeStringContents ( value ) ) . concat ( quote )
@@ -145,6 +139,7 @@ const unparseSugaredApply = (
145139 expression : ApplyExpression ,
146140 unparseAtomOrMolecule : UnparseAtomOrMolecule ,
147141) => {
142+ const { closeParenthesis, openParenthesis } = punctuation ( kleur )
148143 const functionUnparseResult = either . map (
149144 either . flatMap (
150145 serializeIfNeeded ( expression . function ) ,
@@ -182,7 +177,11 @@ const unparseSugaredFunction = (
182177) =>
183178 either . flatMap ( serializeIfNeeded ( expression . body ) , serializedBody =>
184179 either . map ( unparseAtomOrMolecule ( serializedBody ) , bodyAsString =>
185- [ kleur . cyan ( expression . parameter ) , arrow , bodyAsString ] . join ( ' ' ) ,
180+ [
181+ kleur . cyan ( expression . parameter ) ,
182+ punctuation ( kleur ) . arrow ,
183+ bodyAsString ,
184+ ] . join ( ' ' ) ,
186185 ) ,
187186 )
188187
@@ -223,6 +222,8 @@ const unparseSugaredIndex = (
223222 } )
224223 }
225224
225+ const { dot } = punctuation ( kleur )
226+
226227 return either . makeRight (
227228 objectUnparseResult . value
228229 . concat ( dot )
@@ -235,5 +236,9 @@ const unparseSugaredLookup = (
235236 _unparseAtomOrMolecule : UnparseAtomOrMolecule ,
236237) =>
237238 either . makeRight (
238- kleur . cyan ( colon . concat ( quoteKeyPathComponentIfNecessary ( expression . key ) ) ) ,
239+ kleur . cyan (
240+ punctuation ( kleur ) . colon . concat (
241+ quoteKeyPathComponentIfNecessary ( expression . key ) ,
242+ ) ,
243+ ) ,
239244 )
0 commit comments