Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 15x 141x 69517x 11024x 15x 28076x | import { Option } from 'effect'
import type { ParseResult, Parser } from './types'
/**
* Build a Parser from a parse function. A parse that throws on malformed text reads as no match.
* A caution, if given, goes with every result.
*/
export const makeParser = (
label: string,
parse: (text: string) => Option.Option<Omit<ParseResult, 'maybeCaution'>>,
maybeCaution: Option.Option<string> = Option.none(),
): Parser => ({
label,
parse: text =>
Option.map(
Option.flatten(Option.liftThrowable(parse)(text.trim())),
result => ({ ...result, maybeCaution }),
),
})
/** Text with all whitespace removed and letters upper-cased, the form grid references are compared in. */
export const compact = (text: string): string =>
text.replace(/\s+/g, '').toUpperCase()
|