From 4340d7df47e504e3d354047d529056b465fd79e8 Mon Sep 17 00:00:00 2001 From: Vladislav Mamon Date: Sat, 22 Jan 2022 17:07:42 +0500 Subject: [PATCH] refactor: remove `lazy` parser The `defer` parser is superior to it at every aspect. BREAKING CHANGE: This parser can no longer be used. --- src/internal/parsers/lazy.ts | 9 --------- src/parsers.ts | 1 - tests/internal/parsers/lazy.spec.ts | 22 ---------------------- 3 files changed, 32 deletions(-) delete mode 100644 src/internal/parsers/lazy.ts delete mode 100644 tests/internal/parsers/lazy.spec.ts diff --git a/src/internal/parsers/lazy.ts b/src/internal/parsers/lazy.ts deleted file mode 100644 index 53256da..0000000 --- a/src/internal/parsers/lazy.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { State, Parser } from '../state' - -export function lazy(thunk: () => Parser): Parser { - return { - parse(state: State) { - return thunk().parse(state) - } - } -} diff --git a/src/parsers.ts b/src/parsers.ts index f210cfa..0560878 100644 --- a/src/parsers.ts +++ b/src/parsers.ts @@ -2,7 +2,6 @@ export * from './internal/parsers/defer' export * from './internal/parsers/eof' export * from './internal/parsers/float' export * from './internal/parsers/integer' -export * from './internal/parsers/lazy' export * from './internal/parsers/letter' export * from './internal/parsers/newline' export * from './internal/parsers/nothing' diff --git a/tests/internal/parsers/lazy.spec.ts b/tests/internal/parsers/lazy.spec.ts deleted file mode 100644 index a9ed213..0000000 --- a/tests/internal/parsers/lazy.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { string } from '@lib/internal/parsers/string' -import { lazy } from '@lib/internal/parsers/lazy' - -import { run, result, should } from '@tests/@helpers' - -describe(lazy, () => { - it(`should succeed with value of the lazily evaluated parser`, () => { - const parser = lazy(() => string('lazy-loaded')) - const actual = run(parser, 'lazy-loaded') - const expected = result('success', 'lazy-loaded') - - should.matchState(actual, expected) - }) - - it(`should fail with expectation of the lazily evaluated parser`, () => { - const parser = lazy(() => string('spok!')) - const actual = run(parser, 'speak!') - const expected = result('failure', 'spok!') - - should.matchState(actual, expected) - }) -})