File tree Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Original file line number Diff line number Diff line change 11import either , { type Either } from '@matt.kantor/either'
2+ import parsing from '@matt.kantor/parsing'
23import type { ParseError } from '../errors.js'
34import { type SyntaxTree , syntaxTreeParser } from './syntax-tree.js'
45
56export const parse = ( input : string ) : Either < ParseError , SyntaxTree > =>
6- either . match ( syntaxTreeParser ( input . trim ( ) ) , {
7- left : error => either . makeLeft ( { ...error , kind : 'badSyntax' } ) ,
8- right : ( { remainingInput, output } ) =>
9- remainingInput . length !== 0
10- ? either . makeLeft ( {
11- kind : 'badSyntax' ,
12- message : 'excess content followed valid input' ,
13- remainingInput,
14- } )
15- : either . makeRight ( output ) ,
16- } )
7+ either . mapLeft ( parsing . parse ( syntaxTreeParser , input . trim ( ) ) , error => ( {
8+ ...error ,
9+ kind : 'badSyntax' ,
10+ } ) )
Original file line number Diff line number Diff line change 11import either , { type Either , type Right } from '@matt.kantor/either'
2+ import parsing from '@matt.kantor/parsing'
23import kleur from 'kleur'
34import type { UnserializableValueError } from '../errors.js'
45import type { Atom , Molecule } from '../parsing.js'
@@ -63,11 +64,8 @@ export const moleculeUnparser =
6364 }
6465
6566export const quoteIfNecessary = ( value : string ) : string => {
66- const unquotedAtomResult = unquotedAtomParser ( value )
67- if (
68- either . isLeft ( unquotedAtomResult ) ||
69- unquotedAtomResult . value . remainingInput . length !== 0
70- ) {
67+ const unquotedAtomResult = parsing . parse ( unquotedAtomParser , value )
68+ if ( either . isLeft ( unquotedAtomResult ) ) {
7169 return quote . concat ( escapeStringContents ( value ) ) . concat ( quote )
7270 } else {
7371 return value
You can’t perform that action at this time.
0 commit comments