Skip to content

Commit 70fdf62

Browse files
authored
Merge pull request #30 from mkantor/update-parsing-package
Update parsing package
2 parents b11fac1 + f143d1f commit 70fdf62

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"dependencies": {
2323
"@matt.kantor/either": "^1.0.0",
2424
"@matt.kantor/option": "^1.0.0",
25-
"@matt.kantor/parsing": "^1.0.0",
25+
"@matt.kantor/parsing": "^1.1.0",
2626
"kleur": "^4.1.5"
2727
}
2828
}

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)