| 1468 | } |
| 1469 | |
| 1470 | const decode = <A>(input: string, f: (parser: YamlParser) => A): Result.Result<A, EncodingError> => { |
| 1471 | try { |
| 1472 | const raws = (input.includes("\r") ? input.replace(/\r\n?/g, "\n") : input).split("\n") |
| 1473 | const lines = new Array<Line>(raws.length) |
| 1474 | for (let index = 0; index < raws.length; index++) lines[index] = makeLine(raws[index], index + 1) |
| 1475 | return Result.succeed(f(new YamlParser(lines))) |
| 1476 | } catch (e) { |
| 1477 | return Result.fail( |
| 1478 | new EncodingError({ |
| 1479 | module: "Yaml", |
| 1480 | kind: "Decode", |
| 1481 | input, |
| 1482 | message: e instanceof Error ? e.message : "Invalid input" |
| 1483 | }) |
| 1484 | ) |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | /** |
| 1489 | * Parses a single YAML document into JavaScript values. |