From 538aaf2becbfea4acbb8c373eb1bef5cdb08992f Mon Sep 17 00:00:00 2001 From: Matt Kantor Date: Mon, 3 Feb 2025 10:44:57 -0500 Subject: [PATCH 1/2] Update @matt.kantor/parsing --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 46a07e1..d6d66f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@matt.kantor/either": "^1.0.0", "@matt.kantor/option": "^1.0.0", - "@matt.kantor/parsing": "^1.0.0", + "@matt.kantor/parsing": "^1.1.0", "kleur": "^4.1.5" }, "bin": { @@ -53,9 +53,9 @@ "license": "MIT" }, "node_modules/@matt.kantor/parsing": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@matt.kantor/parsing/-/parsing-1.0.0.tgz", - "integrity": "sha512-JRv4fjHGkDJJpimlsetUhJv6p2DQra0H/HrzqtN/zkY42fSOkA31nCQZSi1hs7ihBKDQl6VmnLN4ZWsyRdE5nA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@matt.kantor/parsing/-/parsing-1.1.0.tgz", + "integrity": "sha512-K0BJNtgklB/gwPkOrwFvFsM5jTt3uM/uDWboP4Y9Xjaax8GcVAyD2SqvZ1P2GZt8GWdFTf6vjCAnAmZ1sakw7Q==", "license": "MIT", "dependencies": { "@matt.kantor/either": "^1.0.0" diff --git a/package.json b/package.json index 4907613..8e00219 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "dependencies": { "@matt.kantor/either": "^1.0.0", "@matt.kantor/option": "^1.0.0", - "@matt.kantor/parsing": "^1.0.0", + "@matt.kantor/parsing": "^1.1.0", "kleur": "^4.1.5" } } From f143d1fe414397be17550827e15dddb69b9e9ecf Mon Sep 17 00:00:00 2001 From: Matt Kantor Date: Mon, 3 Feb 2025 10:47:54 -0500 Subject: [PATCH 2/2] Adopt new parse utility from @matt.kantor/parsing --- src/language/parsing/parser.ts | 16 +++++----------- src/language/unparsing/plz-utilities.ts | 8 +++----- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/language/parsing/parser.ts b/src/language/parsing/parser.ts index 9e90504..82d9f9f 100644 --- a/src/language/parsing/parser.ts +++ b/src/language/parsing/parser.ts @@ -1,16 +1,10 @@ import either, { type Either } from '@matt.kantor/either' +import parsing from '@matt.kantor/parsing' import type { ParseError } from '../errors.js' import { type SyntaxTree, syntaxTreeParser } from './syntax-tree.js' export const parse = (input: string): Either => - either.match(syntaxTreeParser(input.trim()), { - left: error => either.makeLeft({ ...error, kind: 'badSyntax' }), - right: ({ remainingInput, output }) => - remainingInput.length !== 0 - ? either.makeLeft({ - kind: 'badSyntax', - message: 'excess content followed valid input', - remainingInput, - }) - : either.makeRight(output), - }) + either.mapLeft(parsing.parse(syntaxTreeParser, input.trim()), error => ({ + ...error, + kind: 'badSyntax', + })) diff --git a/src/language/unparsing/plz-utilities.ts b/src/language/unparsing/plz-utilities.ts index 3b80222..d91db36 100644 --- a/src/language/unparsing/plz-utilities.ts +++ b/src/language/unparsing/plz-utilities.ts @@ -1,4 +1,5 @@ import either, { type Either, type Right } from '@matt.kantor/either' +import parsing from '@matt.kantor/parsing' import kleur from 'kleur' import type { UnserializableValueError } from '../errors.js' import type { Atom, Molecule } from '../parsing.js' @@ -63,11 +64,8 @@ export const moleculeUnparser = } export const quoteIfNecessary = (value: string): string => { - const unquotedAtomResult = unquotedAtomParser(value) - if ( - either.isLeft(unquotedAtomResult) || - unquotedAtomResult.value.remainingInput.length !== 0 - ) { + const unquotedAtomResult = parsing.parse(unquotedAtomParser, value) + if (either.isLeft(unquotedAtomResult)) { return quote.concat(escapeStringContents(value)).concat(quote) } else { return value