Skip to content

Commit f143d1f

Browse files
committed
Adopt new parse utility from @matt.kantor/parsing
1 parent 538aaf2 commit f143d1f

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/language/parsing/parser.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import either, { type Either } from '@matt.kantor/either'
2+
import parsing from '@matt.kantor/parsing'
23
import type { ParseError } from '../errors.js'
34
import { type SyntaxTree, syntaxTreeParser } from './syntax-tree.js'
45

56
export 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+
}))

src/language/unparsing/plz-utilities.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import either, { type Either, type Right } from '@matt.kantor/either'
2+
import parsing from '@matt.kantor/parsing'
23
import kleur from 'kleur'
34
import type { UnserializableValueError } from '../errors.js'
45
import type { Atom, Molecule } from '../parsing.js'
@@ -63,11 +64,8 @@ export const moleculeUnparser =
6364
}
6465

6566
export 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

0 commit comments

Comments
 (0)