@thomasfosterau/effect-parse 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +40 -14
  2. package/dist/Ascii.d.ts +11 -4
  3. package/dist/Ascii.d.ts.map +1 -1
  4. package/dist/Ascii.js +7 -1
  5. package/dist/Ascii.js.map +1 -1
  6. package/dist/Binary.d.ts.map +1 -1
  7. package/dist/Binary.js +64 -35
  8. package/dist/Binary.js.map +1 -1
  9. package/dist/Bits.d.ts.map +1 -1
  10. package/dist/Bits.js +7 -4
  11. package/dist/Bits.js.map +1 -1
  12. package/dist/Compiler.d.ts +74 -2
  13. package/dist/Compiler.d.ts.map +1 -1
  14. package/dist/Compiler.js +78 -1
  15. package/dist/Compiler.js.map +1 -1
  16. package/dist/Expression.d.ts.map +1 -1
  17. package/dist/Expression.js +86 -74
  18. package/dist/Expression.js.map +1 -1
  19. package/dist/Input.d.ts +37 -4
  20. package/dist/Input.d.ts.map +1 -1
  21. package/dist/Input.js +42 -0
  22. package/dist/Input.js.map +1 -1
  23. package/dist/Nom.d.ts +5 -15
  24. package/dist/Nom.d.ts.map +1 -1
  25. package/dist/Nom.js.map +1 -1
  26. package/dist/ParseError.d.ts +2 -2
  27. package/dist/ParseError.d.ts.map +1 -1
  28. package/dist/ParseError.js +1 -1
  29. package/dist/ParseError.js.map +1 -1
  30. package/dist/Parser.d.ts +370 -28
  31. package/dist/Parser.d.ts.map +1 -1
  32. package/dist/Parser.js +390 -19
  33. package/dist/Parser.js.map +1 -1
  34. package/dist/ParserSchema.js +2 -2
  35. package/dist/ParserSchema.js.map +1 -1
  36. package/dist/ParserStream.d.ts +3 -2
  37. package/dist/ParserStream.d.ts.map +1 -1
  38. package/dist/ParserStream.js +15 -10
  39. package/dist/ParserStream.js.map +1 -1
  40. package/dist/Syntax.d.ts +23 -5
  41. package/dist/Syntax.d.ts.map +1 -1
  42. package/dist/Syntax.js.map +1 -1
  43. package/dist/Text.d.ts.map +1 -1
  44. package/dist/Text.js +9 -9
  45. package/dist/Text.js.map +1 -1
  46. package/dist/Token.d.ts +55 -10
  47. package/dist/Token.d.ts.map +1 -1
  48. package/dist/Token.js +59 -21
  49. package/dist/Token.js.map +1 -1
  50. package/dist/internal/compiler/closure.d.ts.map +1 -1
  51. package/dist/internal/compiler/closure.js +257 -97
  52. package/dist/internal/compiler/closure.js.map +1 -1
  53. package/dist/internal/compiler/entries.d.ts +3 -1
  54. package/dist/internal/compiler/entries.d.ts.map +1 -1
  55. package/dist/internal/compiler/entries.js +3 -2
  56. package/dist/internal/compiler/entries.js.map +1 -1
  57. package/dist/internal/compiler/first.d.ts.map +1 -1
  58. package/dist/internal/compiler/first.js +7 -1
  59. package/dist/internal/compiler/first.js.map +1 -1
  60. package/dist/internal/compiler/graph.d.ts +17 -0
  61. package/dist/internal/compiler/graph.d.ts.map +1 -0
  62. package/dist/internal/compiler/graph.js +56 -0
  63. package/dist/internal/compiler/graph.js.map +1 -0
  64. package/dist/internal/compiler/jit.d.ts +5 -0
  65. package/dist/internal/compiler/jit.d.ts.map +1 -1
  66. package/dist/internal/compiler/jit.js +185 -96
  67. package/dist/internal/compiler/jit.js.map +1 -1
  68. package/dist/internal/compiler/registry.d.ts +10 -2
  69. package/dist/internal/compiler/registry.d.ts.map +1 -1
  70. package/dist/internal/compiler/registry.js.map +1 -1
  71. package/dist/internal/compiler/search.d.ts +32 -0
  72. package/dist/internal/compiler/search.d.ts.map +1 -0
  73. package/dist/internal/compiler/search.js +68 -0
  74. package/dist/internal/compiler/search.js.map +1 -0
  75. package/dist/internal/compiler/sets.d.ts.map +1 -1
  76. package/dist/internal/compiler/sets.js +1 -1
  77. package/dist/internal/compiler/sets.js.map +1 -1
  78. package/dist/internal/compiler/wasm.d.ts +8 -0
  79. package/dist/internal/compiler/wasm.d.ts.map +1 -0
  80. package/dist/internal/compiler/wasm.js +2769 -0
  81. package/dist/internal/compiler/wasm.js.map +1 -0
  82. package/dist/internal/compiler/wasmAsm.d.ts +199 -0
  83. package/dist/internal/compiler/wasmAsm.d.ts.map +1 -0
  84. package/dist/internal/compiler/wasmAsm.js +427 -0
  85. package/dist/internal/compiler/wasmAsm.js.map +1 -0
  86. package/dist/internal/entries.d.ts +3 -1
  87. package/dist/internal/entries.d.ts.map +1 -1
  88. package/dist/internal/entries.js +1 -2
  89. package/dist/internal/entries.js.map +1 -1
  90. package/dist/internal/node.d.ts +58 -2
  91. package/dist/internal/node.d.ts.map +1 -1
  92. package/dist/internal/node.js +13 -3
  93. package/dist/internal/node.js.map +1 -1
  94. package/dist/internal/numbers.d.ts.map +1 -1
  95. package/dist/internal/numbers.js.map +1 -1
  96. package/dist/internal/run.d.ts +12 -0
  97. package/dist/internal/run.d.ts.map +1 -1
  98. package/dist/internal/run.js +51 -11
  99. package/dist/internal/run.js.map +1 -1
  100. package/dist/internal/stack.d.ts +6 -0
  101. package/dist/internal/stack.d.ts.map +1 -1
  102. package/dist/internal/stack.js +8 -2
  103. package/dist/internal/stack.js.map +1 -1
  104. package/dist/internal/syntax.d.ts +4 -4
  105. package/dist/internal/syntax.d.ts.map +1 -1
  106. package/dist/internal/syntax.js +18 -10
  107. package/dist/internal/syntax.js.map +1 -1
  108. package/dist/internal/text.d.ts +32 -0
  109. package/dist/internal/text.d.ts.map +1 -1
  110. package/dist/internal/text.js +68 -14
  111. package/dist/internal/text.js.map +1 -1
  112. package/dist/internal/tokens.d.ts +13 -0
  113. package/dist/internal/tokens.d.ts.map +1 -1
  114. package/dist/internal/tokens.js +59 -39
  115. package/dist/internal/tokens.js.map +1 -1
  116. package/package.json +5 -4
  117. package/src/Ascii.ts +42 -9
  118. package/src/Binary.ts +151 -71
  119. package/src/Bits.ts +12 -6
  120. package/src/Compiler.ts +101 -10
  121. package/src/Expression.ts +94 -81
  122. package/src/Input.ts +65 -6
  123. package/src/Nom.ts +15 -5
  124. package/src/ParseError.ts +9 -4
  125. package/src/Parser.ts +682 -129
  126. package/src/ParserSchema.ts +1 -1
  127. package/src/ParserStream.ts +40 -19
  128. package/src/Syntax.ts +60 -36
  129. package/src/Text.ts +16 -15
  130. package/src/Token.ts +138 -29
  131. package/src/internal/compiler/closure.ts +362 -135
  132. package/src/internal/compiler/entries.ts +4 -2
  133. package/src/internal/compiler/first.ts +10 -0
  134. package/src/internal/compiler/graph.ts +68 -0
  135. package/src/internal/compiler/jit.ts +284 -154
  136. package/src/internal/compiler/registry.ts +10 -2
  137. package/src/internal/compiler/search.ts +68 -0
  138. package/src/internal/compiler/sets.ts +7 -3
  139. package/src/internal/compiler/wasm.ts +3203 -0
  140. package/src/internal/compiler/wasmAsm.ts +484 -0
  141. package/src/internal/entries.ts +10 -4
  142. package/src/internal/node.ts +54 -4
  143. package/src/internal/numbers.ts +3 -1
  144. package/src/internal/run.ts +71 -12
  145. package/src/internal/stack.ts +8 -1
  146. package/src/internal/syntax.ts +39 -18
  147. package/src/internal/text.ts +97 -9
  148. package/src/internal/tokens.ts +96 -14
@@ -1 +1 @@
1
- {"version":3,"file":"Expression.js","names":["makeParser"],"sources":["../src/Expression.ts"],"sourcesContent":["/**\n * Operator-precedence expression parsing with a Pratt parser (from\n * `nom-language`'s `precedence`, and winnow's expression parser).\n *\n * Describe the operand parser and a table of prefix, postfix and infix\n * operators with their precedence (higher binds tighter) and associativity.\n * Each operator carries a function that folds its operands into a result.\n *\n * @example\n * ```ts\n * import { Ascii, Expression, Parser, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const op = (s: string) => Parser.delimited(Ascii.space0, Token.literal(s), Ascii.space0)\n *\n * const arithmetic: Parser.Parser<number, string> = Expression.make({\n * operand: Parser.alt(\n * Ascii.decInt,\n * Parser.delimited(op(\"(\"), Parser.suspend(() => arithmetic), op(\")\"))\n * ),\n * operators: [\n * Expression.prefix(op(\"-\"), 4, (_, x) => -x),\n * Expression.postfix(op(\"!\"), 5, (x) => factorial(x)),\n * Expression.infixRight(op(\"^\"), 3, (l, _, r) => l ** r),\n * Expression.infixLeft(op(\"*\"), 2, (l, _, r) => l * r),\n * Expression.infixLeft(op(\"/\"), 2, (l, _, r) => l / r),\n * Expression.infixLeft(op(\"+\"), 1, (l, _, r) => l + r),\n * Expression.infixLeft(op(\"-\"), 1, (l, _, r) => l - r)\n * ]\n * })\n *\n * declare const factorial: (n: number) => number\n * Parser.parse(arithmetic, \"1 + 2 * 3 ^ 2\") // Result.succeed(19)\n * ```\n *\n * @since 0.1.0\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type { Input, State } from \"./Input.js\"\nimport { Fail } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport { make as makeParser } from \"./Parser.js\"\nimport { TiedFailures } from \"./internal/ties.js\"\n\n/**\n * An operator in an expression grammar.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Operator<A, E = never, R = never, I extends Input = string> =\n | Prefix<A, E, R, I>\n | Postfix<A, E, R, I>\n | Infix<A, E, R, I>\n\ninterface OperatorBase<E, R, I extends Input> {\n readonly parser: Parser<unknown, E, R, I>\n readonly precedence: number\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Prefix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Prefix\"\n readonly fold: (op: any, operand: A) => A\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Postfix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Postfix\"\n readonly fold: (operand: A, op: any) => A\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Infix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Infix\"\n readonly associativity: \"left\" | \"right\"\n readonly fold: (left: A, op: any, right: A) => A\n}\n\n/**\n * A prefix operator, e.g. unary minus.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const prefix = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (op: O, operand: A) => A\n): Prefix<A, E, R, I> => ({ _tag: \"Prefix\", parser, precedence, fold })\n\n/**\n * A postfix operator, e.g. factorial or a function call suffix.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const postfix = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (operand: A, op: O) => A\n): Postfix<A, E, R, I> => ({ _tag: \"Postfix\", parser, precedence, fold })\n\n/**\n * A left-associative infix operator: `a - b - c` is `(a - b) - c`.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const infixLeft = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (left: A, op: O, right: A) => A\n): Infix<A, E, R, I> => ({ _tag: \"Infix\", associativity: \"left\", parser, precedence, fold })\n\n/**\n * A right-associative infix operator: `a ^ b ^ c` is `a ^ (b ^ c)`.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const infixRight = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (left: A, op: O, right: A) => A\n): Infix<A, E, R, I> => ({ _tag: \"Infix\", associativity: \"right\", parser, precedence, fold })\n\ntype OpError<Op> = Op extends OperatorBase<infer E, infer _R, infer _I> ? E : never\ntype OpServices<Op> = Op extends OperatorBase<infer _E, infer R, infer _I> ? R : never\ntype OpInput<Op> = [Op] extends [never] ? Input : [Op] extends [OperatorBase<infer _E, infer _R, infer I>] ? I : never\n\n/**\n * Builds an expression parser from an operand parser and an operator table.\n *\n * Precedences are compared numerically: higher binds tighter. A prefix\n * operator applies to everything that binds tighter than it, so with `-`\n * at precedence 4 and `^` at 3, `-2 ^ 2` parses as `(-2) ^ 2`.\n *\n * When several operators of the same kind match, the first one in the\n * table wins, so list longer operators (`<=`) before their prefixes (`<`).\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const make = <A, E, R, I extends Input, const Ops extends ReadonlyArray<Operator<A, any, any, any>>>(options: {\n readonly operand: Parser<A, E, R, I>\n readonly operators: Ops\n}): Parser<A, E | OpError<Ops[number]>, R | OpServices<Ops[number]>, I & OpInput<Ops[number]>> => {\n const operand = options.operand.step\n const prefixes = options.operators.filter((o): o is Prefix<A, any, any, any> => Predicate.isTagged(o, \"Prefix\"))\n const postfixes = options.operators.filter((o): o is Postfix<A, any, any, any> => Predicate.isTagged(o, \"Postfix\"))\n const infixes = options.operators.filter((o): o is Infix<A, any, any, any> => Predicate.isTagged(o, \"Infix\"))\n\n // Attempts each operator in turn. Returns the index of the first match\n // (with its output in `matched`), -1 if none matched, or -2 on a fatal\n // failure. Failed attempts are folded into `failures`, merged only when\n // read (#44): a round in which an operator matches discards them unmerged.\n // Like `matched`, it is shared by nested expressions, which clear it.\n let matched: unknown\n const failures = new TiedFailures()\n const tryOps = (state: State<any>, ops: ReadonlyArray<OperatorBase<any, any, any>>, mustConsume: boolean): number => {\n const start = state.pos\n for (let i = 0; i < ops.length; i++) {\n const out = ops[i].parser.step(state)\n if (out !== Fail) {\n // A prefix or postfix operator matching nothing would apply forever\n if (mustConsume && state.pos === start) {\n state.failMessage(\"Cut\", \"Assert\", \"prefix and postfix operators must always consume\")\n return -2\n }\n matched = out\n return i\n }\n if (state.mode !== \"Backtrack\") return -2\n state.rewind(start)\n failures.add(state)\n }\n return -1\n }\n\n const expr = (state: State<any>, minPower: number): A | Fail => {\n let lhs: A | Fail\n failures.clear()\n const p = tryOps(state, prefixes, true)\n if (p === -2) return Fail\n if (p >= 0) {\n const op = prefixes[p]\n const opOut = matched\n const operandValue = expr(state, op.precedence * 2)\n if (operandValue === Fail) return Fail\n lhs = op.fold(opOut, operandValue)\n } else {\n const prefixFailure = failures.failure\n const prefixTie1 = failures.tie1\n const prefixTie2 = failures.tie2\n lhs = operand(state)\n if (lhs === Fail) {\n if (prefixFailure !== undefined && state.mode === \"Backtrack\") {\n // The operand may have parsed nested expressions, which reuse `failures`\n failures.failure = prefixFailure\n failures.tie1 = prefixTie1\n failures.tie2 = prefixTie2\n failures.add(state)\n failures.fail(state)\n }\n return Fail\n }\n }\n\n while (true) {\n const start = state.pos\n failures.clear()\n const q = tryOps(state, postfixes, true)\n if (q === -2) return Fail\n if (q >= 0) {\n const op = postfixes[q]\n if (op.precedence * 2 < minPower) {\n state.rewind(start)\n break\n }\n lhs = op.fold(lhs, matched)\n continue\n }\n // The infix attempts are folded on top of the postfix ones\n const i = tryOps(state, infixes, false)\n if (i === -2) return Fail\n if (i < 0) {\n failures.hint(state)\n break\n }\n const op = infixes[i]\n const leftPower = op.precedence * 2\n if (leftPower < minPower) {\n state.rewind(start)\n break\n }\n const opOut = matched\n const rhs = expr(state, op.associativity === \"left\" ? leftPower + 1 : leftPower)\n if (rhs === Fail) return Fail\n lhs = op.fold(lhs, opOut, rhs)\n }\n return lhs\n }\n\n return makeParser((state: State<any>) => expr(state, 0), \"expression\")\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,MAAa,UACX,QACA,YACA,UACwB;CAAE,MAAM;CAAU;CAAQ;CAAY;AAAK;;;;;;;AAQrE,MAAa,WACX,QACA,YACA,UACyB;CAAE,MAAM;CAAW;CAAQ;CAAY;AAAK;;;;;;;AAQvE,MAAa,aACX,QACA,YACA,UACuB;CAAE,MAAM;CAAS,eAAe;CAAQ;CAAQ;CAAY;AAAK;;;;;;;AAQ1F,MAAa,cACX,QACA,YACA,UACuB;CAAE,MAAM;CAAS,eAAe;CAAS;CAAQ;CAAY;AAAK;;;;;;;;;;;;;;AAmB3F,MAAa,QAA+F,YAGV;CAChG,MAAM,UAAU,QAAQ,QAAQ;CAChC,MAAM,WAAW,QAAQ,UAAU,QAAQ,MAAqC,UAAU,SAAS,GAAG,QAAQ,CAAC;CAC/G,MAAM,YAAY,QAAQ,UAAU,QAAQ,MAAsC,UAAU,SAAS,GAAG,SAAS,CAAC;CAClH,MAAM,UAAU,QAAQ,UAAU,QAAQ,MAAoC,UAAU,SAAS,GAAG,OAAO,CAAC;CAO5G,IAAI;CACJ,MAAM,WAAW,I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V,MAAM,KAAK,UAAU;IACrB,IAAI,GAAG,aAAa,IAAI,UAAU;KAChC,MAAM,OAAO,KAAK;KAClB;IACF;IACA,MAAM,GAAG,KAAK,KAAK,OAAO;IAC1B;GACF;GAEA,MAAM,IAAI,OAAO,OAAO,SAAS,KAAK;GACtC,IAAI,MAAM,IAAI,OAAO;GACrB,IAAI,IAAI,GAAG;IACT,SAAS,KAAK,KAAK;IACnB;GACF;GACA,MAAM,KAAK,QAAQ;GACnB,MAAM,YAAY,GAAG,aAAa;GAClC,IAAI,YAAY,UAAU;IACxB,MAAM,OAAO,KAAK;IAClB;GACF;GACA,MAAM,QAAQ;GACd,MAAM,MAAM,KAAK,OAAO,GAAG,kBAAkB,SAAS,YAAY,IAAI,SAAS;GAC/E,IAAI,QAAQ,MAAM,OAAO;GACzB,MAAM,GAAG,KAAK,KAAK,OAAO,GAAG;EAC/B;EACA,OAAO;CACT;CAEA,OAAOA,QAAY,UAAsB,KAAK,OAAO,CAAC,GAAG,YAAY;AACvE"}
1
+ {"version":3,"file":"Expression.js","names":[],"sources":["../src/Expression.ts"],"sourcesContent":["/**\n * Operator-precedence expression parsing with a Pratt parser (from\n * `nom-language`'s `precedence`, and winnow's expression parser).\n *\n * Describe the operand parser and a table of prefix, postfix and infix\n * operators with their precedence (higher binds tighter) and associativity.\n * Each operator carries a function that folds its operands into a result.\n *\n * @example\n * ```ts\n * import { Ascii, Expression, Parser, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const op = (s: string) => Parser.delimited(Ascii.space0, Token.literal(s), Ascii.space0)\n *\n * const arithmetic: Parser.Parser<number, string> = Expression.make({\n * operand: Parser.alt(\n * Ascii.decInt,\n * Parser.delimited(op(\"(\"), Parser.suspend(() => arithmetic), op(\")\"))\n * ),\n * operators: [\n * Expression.prefix(op(\"-\"), 4, (_, x) => -x),\n * Expression.postfix(op(\"!\"), 5, (x) => factorial(x)),\n * Expression.infixRight(op(\"^\"), 3, (l, _, r) => l ** r),\n * Expression.infixLeft(op(\"*\"), 2, (l, _, r) => l * r),\n * Expression.infixLeft(op(\"/\"), 2, (l, _, r) => l / r),\n * Expression.infixLeft(op(\"+\"), 1, (l, _, r) => l + r),\n * Expression.infixLeft(op(\"-\"), 1, (l, _, r) => l - r)\n * ]\n * })\n *\n * declare const factorial: (n: number) => number\n * Parser.parse(arithmetic, \"1 + 2 * 3 ^ 2\") // Result.succeed(19)\n * ```\n *\n * @since 0.1.0\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type { Input, State } from \"./Input.js\"\nimport { Fail } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport { combinator } from \"./Parser.js\"\n\n/** A parser's step, interpreted or compiled. */\ntype Step = (state: State<any>) => unknown\nimport { TiedFailures } from \"./internal/ties.js\"\n\n/**\n * An operator in an expression grammar.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Operator<A, E = never, R = never, I extends Input = string> =\n | Prefix<A, E, R, I>\n | Postfix<A, E, R, I>\n | Infix<A, E, R, I>\n\ninterface OperatorBase<E, R, I extends Input> {\n readonly parser: Parser<unknown, E, R, I>\n readonly precedence: number\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Prefix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Prefix\"\n readonly fold: (op: any, operand: A) => A\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Postfix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Postfix\"\n readonly fold: (operand: A, op: any) => A\n}\n\n/**\n * @since 0.1.0\n * @category models\n */\nexport interface Infix<A, E = never, R = never, I extends Input = string> extends OperatorBase<E, R, I> {\n readonly _tag: \"Infix\"\n readonly associativity: \"left\" | \"right\"\n readonly fold: (left: A, op: any, right: A) => A\n}\n\n/**\n * A prefix operator, e.g. unary minus.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const prefix = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (op: O, operand: A) => A\n): Prefix<A, E, R, I> => ({ _tag: \"Prefix\", parser, precedence, fold })\n\n/**\n * A postfix operator, e.g. factorial or a function call suffix.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const postfix = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (operand: A, op: O) => A\n): Postfix<A, E, R, I> => ({ _tag: \"Postfix\", parser, precedence, fold })\n\n/**\n * A left-associative infix operator: `a - b - c` is `(a - b) - c`.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const infixLeft = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (left: A, op: O, right: A) => A\n): Infix<A, E, R, I> => ({ _tag: \"Infix\", associativity: \"left\", parser, precedence, fold })\n\n/**\n * A right-associative infix operator: `a ^ b ^ c` is `a ^ (b ^ c)`.\n *\n * @since 0.1.0\n * @category operators\n */\nexport const infixRight = <O, E, R, I extends Input, A>(\n parser: Parser<O, E, R, I>,\n precedence: number,\n fold: (left: A, op: O, right: A) => A\n): Infix<A, E, R, I> => ({ _tag: \"Infix\", associativity: \"right\", parser, precedence, fold })\n\ntype OpError<Op> = Op extends OperatorBase<infer E, infer _R, infer _I> ? E : never\ntype OpServices<Op> = Op extends OperatorBase<infer _E, infer R, infer _I> ? R : never\ntype OpInput<Op> = [Op] extends [never] ? Input : [Op] extends [OperatorBase<infer _E, infer _R, infer I>] ? I : never\n\n/**\n * Builds an expression parser from an operand parser and an operator table.\n *\n * Precedences are compared numerically: higher binds tighter. A prefix\n * operator applies to everything that binds tighter than it, so with `-`\n * at precedence 4 and `^` at 3, `-2 ^ 2` parses as `(-2) ^ 2`.\n *\n * When several operators of the same kind match, the first one in the\n * table wins, so list longer operators (`<=`) before their prefixes (`<`).\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const make = <A, E, R, I extends Input, const Ops extends ReadonlyArray<Operator<A, any, any, any>>>(options: {\n readonly operand: Parser<A, E, R, I>\n readonly operators: Ops\n}): Parser<A, E | OpError<Ops[number]>, R | OpServices<Ops[number]>, I & OpInput<Ops[number]>> => {\n const prefixes = options.operators.filter((o): o is Prefix<A, any, any, any> => Predicate.isTagged(o, \"Prefix\"))\n const postfixes = options.operators.filter((o): o is Postfix<A, any, any, any> => Predicate.isTagged(o, \"Postfix\"))\n const infixes = options.operators.filter((o): o is Infix<A, any, any, any> => Predicate.isTagged(o, \"Infix\"))\n const operators = [...prefixes, ...postfixes, ...infixes]\n const parsers = [options.operand, ...operators.map((o) => o.parser)]\n // Builds the step from the operand's and the operators' steps, in that\n // order: their own steps when interpreted, compiled ones when compiled\n const build = (steps: ReadonlyArray<Step>) => {\n const operand = steps[0]\n const prefixSteps = steps.slice(1, 1 + prefixes.length)\n const postfixSteps = steps.slice(1 + prefixes.length, 1 + prefixes.length + postfixes.length)\n const infixSteps = steps.slice(1 + prefixes.length + postfixes.length)\n\n // Attempts each operator in turn. Returns the index of the first match\n // (with its output in `matched`), -1 if none matched, or -2 on a fatal\n // failure. Failed attempts are folded into `failures`, merged only when\n // read (#44): a round in which an operator matches discards them unmerged.\n // Like `matched`, it is shared by nested expressions, which clear it.\n let matched: unknown\n const failures = new TiedFailures()\n const tryOps = (state: State<any>, ops: ReadonlyArray<Step>, mustConsume: boolean): number => {\n const start = state.pos\n for (let i = 0; i < ops.length; i++) {\n const out = ops[i](state)\n if (out !== Fail) {\n // A prefix or postfix operator matching nothing would apply forever\n if (mustConsume && state.pos === start) {\n state.failMessage(\"Cut\", \"Assert\", \"prefix and postfix operators must always consume\")\n return -2\n }\n matched = out\n return i\n }\n if (state.mode !== \"Backtrack\") return -2\n state.rewind(start)\n failures.add(state)\n }\n return -1\n }\n\n const expr = (state: State<any>, minPower: number): A | Fail => {\n let lhs: A | Fail\n failures.clear()\n const p = tryOps(state, prefixSteps, true)\n if (p === -2) return Fail\n if (p >= 0) {\n const op = prefixes[p]\n const opOut = matched\n const operandValue = expr(state, op.precedence * 2)\n if (operandValue === Fail) return Fail\n lhs = op.fold(opOut, operandValue)\n } else {\n const prefixFailure = failures.failure\n const prefixTie1 = failures.tie1\n const prefixTie2 = failures.tie2\n // SAFETY: the operand's step, interpreted or compiled, returns its output (an `A`) or `Fail`\n lhs = operand(state) as A | Fail\n if (lhs === Fail) {\n if (prefixFailure !== undefined && state.mode === \"Backtrack\") {\n // The operand may have parsed nested expressions, which reuse `failures`\n failures.failure = prefixFailure\n failures.tie1 = prefixTie1\n failures.tie2 = prefixTie2\n failures.add(state)\n failures.fail(state)\n }\n return Fail\n }\n }\n\n while (true) {\n const start = state.pos\n failures.clear()\n const q = tryOps(state, postfixSteps, true)\n if (q === -2) return Fail\n if (q >= 0) {\n const op = postfixes[q]\n if (op.precedence * 2 < minPower) {\n state.rewind(start)\n break\n }\n lhs = op.fold(lhs, matched)\n continue\n }\n // The infix attempts are folded on top of the postfix ones\n const i = tryOps(state, infixSteps, false)\n if (i === -2) return Fail\n if (i < 0) {\n failures.hint(state)\n break\n }\n const op = infixes[i]\n const leftPower = op.precedence * 2\n if (leftPower < minPower) {\n state.rewind(start)\n break\n }\n const opOut = matched\n const rhs = expr(state, op.associativity === \"left\" ? leftPower + 1 : leftPower)\n if (rhs === Fail) return Fail\n lhs = op.fold(lhs, opOut, rhs)\n }\n return lhs\n }\n return (state: State<any>) => expr(state, 0)\n }\n return combinator(parsers, build, \"expression\")\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,MAAa,UACX,QACA,YACA,UACwB;CAAE,MAAM;CAAU;CAAQ;CAAY;AAAK;;;;;;;AAQrE,MAAa,WACX,QACA,YACA,UACyB;CAAE,MAAM;CAAW;CAAQ;CAAY;AAAK;;;;;;;AAQvE,MAAa,aACX,QACA,YACA,UACuB;CAAE,MAAM;CAAS,eAAe;CAAQ;CAAQ;CAAY;AAAK;;;;;;;AAQ1F,MAAa,cACX,QACA,YACA,UACuB;CAAE,MAAM;CAAS,eAAe;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KAAK,OAAO,GAAG;GAC/B;GACA,OAAO;EACT;EACA,QAAQ,UAAsB,KAAK,OAAO,CAAC;CAC7C;CACA,OAAO,WAAW,SAAS,OAAO,YAAY;AAChD"}
package/dist/Input.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { AsciiRun } from "./internal/text.js";
1
2
  import * as Context from "effect/Context";
2
3
  import { ErrorKind } from "./ParseError.js";
3
4
  import { Builder } from "./internal/syntax.js";
@@ -35,6 +36,16 @@ export type BinaryInput = ArrayBufferLike | ArrayBufferView;
35
36
  * @category models
36
37
  */
37
38
  export type Source<I> = I | ([I] extends [Uint8Array] ? BinaryInput : never);
39
+ /**
40
+ * The overloads of {@link fromSource}.
41
+ *
42
+ * @since 0.5.0
43
+ * @category constructors
44
+ */
45
+ export interface FromSourceFn {
46
+ (source: BinaryInput): Uint8Array;
47
+ <I extends Input>(source: Source<I>): I;
48
+ }
38
49
  /**
39
50
  * Converts a {@link Source} to the input parsers read: binary data becomes a
40
51
  * `Uint8Array` view of the same memory, everything else is returned as is.
@@ -49,10 +60,7 @@ export type Source<I> = I | ([I] extends [Uint8Array] ? BinaryInput : never);
49
60
  * @since 0.1.0
50
61
  * @category constructors
51
62
  */
52
- export declare const fromSource: {
53
- (source: BinaryInput): Uint8Array;
54
- <I extends Input>(source: Source<I>): I;
55
- };
63
+ export declare const fromSource: FromSourceFn;
56
64
  /**
57
65
  * The type of a single token of an input.
58
66
  *
@@ -245,6 +253,31 @@ export declare class State<I extends Input = Input> {
245
253
  * @internal
246
254
  */
247
255
  syntax: Builder | undefined;
256
+ /**
257
+ * Where the stop characters of compiled `takeTill`s next occur in this
258
+ * state's input, by search site; created on first use. It lives as long
259
+ * as the state (whose input never changes), and `reset` clears it with
260
+ * the other per-run fields.
261
+ *
262
+ * @internal
263
+ */
264
+ searches: Map<object, Array<number>> | undefined;
265
+ /**
266
+ * A run of ASCII bytes of this state's UTF-8 input, decoded once, from
267
+ * which `Text.utf8` slices the long strings it decodes (see
268
+ * `internal/text.ts`); `reset` clears it with the other per-run fields.
269
+ *
270
+ * @internal
271
+ */
272
+ asciiRun: AsciiRun | undefined;
273
+ /**
274
+ * A `DataView` of this state's byte input, for the `Binary` parsers;
275
+ * created on first use. It lives as long as the state, whose input never
276
+ * changes: one per read cost most of a number's time.
277
+ *
278
+ * @internal
279
+ */
280
+ view: DataView | undefined;
248
281
  constructor(source: I | Source<I>, options?: {
249
282
  readonly partial?: boolean | undefined;
250
283
  readonly context?: Context.Context<never> | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"Input.d.ts","names":["SyntaxBuilder"],"sources":["../src/Input.ts"],"mappings":";;;;;;;;;;;;;;;YAiCY,iBAAiB,aAAa;;;;;;;;;;;;;YAc9B,cAAc,kBAAkB;;;;;;;;YAShC,OAAO,KAAK,MAAM,YAAY,cAAc;;;;;;;;;;;;;;;qBAgB3C;GACV,QAAQ,cAAc;GACtB,UAAU,OAAO,QAAQ,OAAO,KAAK;;;;;;;;YAkB5B,MAAM,KAAK,4BAEnB,UAAU,sBAER,UAAU,oBAAoB,KAC5B;;;;;;;YASI,MAAM,KAAK,4BAEnB,UAAU,aACR,aACA,UAAU,oBAAoB,KAC5B,cAAc;;;;;;;;qBAUT;;;;;YAMD,cAAc;;;;;;;;;;;YAYd;;;;;;;qBAQC;;WAGA;;WAEA,MAAM;;WAEN,UAAU;;WAEV,SAAS;;WAET;;WAEA;;WAEA;;WAEA;;;EAdA;;EAEA,MAAM;;EAEN,UAAU;;EAEV,SAAS;;EAET;;EAEA;;EAEA;;EAEA;;;qBAUA;;;;;;;iBAQI;WACN;WACA;WACA;WACA;;WAEA,gBAAgB;;WAEhB;WACA,OAAO;;;;;;;;qBASL,MAAM,UAAU,QAAQ;;WAE1B,OAAO;;;;;EAKhB;;EAEA;;WAES;;EAET;;EAEA,SAAS,QAAQ;;EAEjB,MAAM;;;;;;;;;;;EAWN,aAAa;;EAEb,aAAa;;EAEb,aAAa;;EAEb,gBAAgB;;;;;;;;EAQhB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;;;;;;;;;;;;;;;;;;;;;;;EA6CR,MACE,iBACA;aACW;aACA,UAAU,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkD/B,OAAO;;;;EASP;;;;EAOA;;;;EAOA,MAAM,eAAe,cAAc,MAAM;;;;EAsBzC,UAAU,MAAM,WAAW,WAAU,uBAA+B,kBAA4B;;;;EAOhG,IAAI,MAAM,WAAW,WAAU,uBAA+B,kBAA4B;;;;;EAQ1F,WAAW,gBAAgB,WAAU,wBAAgC;;;;;EAWrE,IAAI,MAAM,WAAW,UAAU,uBAAuB,iBAAiB;;;;EAOvE,UAAU,MAAM,SAAS,MAAM,WAAW,gBAAgB,kBAA4B;;;;EAOtF,YAAY,MAAM,SAAS,MAAM,WAAW,iBAAiB,kBAA4B;;;;EAOzF,SAAS,MAAM,SAAS,SAAS,UAAU;;;;;;;;EAwB3C,SAAS,MAAM,SAAS,MAAM,SAAS,MAAM,sBAAsB;;;;;EAenE,eAAe,SAAS;;;;;;EAUxB,mBAAmB;;;;;;EAwBnB,QAAQ,gBAAgB,UAAU;;EAWlC,YAAY,gBAAgB,MAAM,WAAW,UAAU,wBAAwB;;;qBAoBpE,gBAAiB,GAAG,uBAAuB,GAAG,0BAAwB;;;;;;;qBAqBtE,gBAAiB,GAAG,SAAS,GAAG,YAAU;;;;;;;;qBAa1C,oBAAqB,GAAG,SAAS,GAAG,SAAS,UAAU,0BAAwB"}
package/dist/Input.js CHANGED
@@ -177,6 +177,31 @@ var State = class {
177
177
  * @internal
178
178
  */
179
179
  syntax = void 0;
180
+ /**
181
+ * Where the stop characters of compiled `takeTill`s next occur in this
182
+ * state's input, by search site; created on first use. It lives as long
183
+ * as the state (whose input never changes), and `reset` clears it with
184
+ * the other per-run fields.
185
+ *
186
+ * @internal
187
+ */
188
+ searches = void 0;
189
+ /**
190
+ * A run of ASCII bytes of this state's UTF-8 input, decoded once, from
191
+ * which `Text.utf8` slices the long strings it decodes (see
192
+ * `internal/text.ts`); `reset` clears it with the other per-run fields.
193
+ *
194
+ * @internal
195
+ */
196
+ asciiRun = void 0;
197
+ /**
198
+ * A `DataView` of this state's byte input, for the `Binary` parsers;
199
+ * created on first use. It lives as long as the state, whose input never
200
+ * changes: one per read cost most of a number's time.
201
+ *
202
+ * @internal
203
+ */
204
+ view = void 0;
180
205
  constructor(source, options) {
181
206
  const input = fromSource(source);
182
207
  this.input = input;
@@ -261,6 +286,8 @@ var State = class {
261
286
  this.depth = 0;
262
287
  this.encoding = void 0;
263
288
  this.resume = void 0;
289
+ this.searches = void 0;
290
+ this.asciiRun = void 0;
264
291
  return this;
265
292
  }
266
293
  /**
@@ -426,12 +453,27 @@ var State = class {
426
453
  return new Failure(offset, kind, expected, empty, false, void 0, void 0, 0);
427
454
  }
428
455
  };
456
+ /**
457
+ * The last merges {@link mergeExpected} made, as `[a, b, merged]` triples. A
458
+ * parse merges the same few pairs of expectation arrays over and over (a
459
+ * whitespace skipper's hint with a repetition's, then with the failure of
460
+ * the token after them), and expectation arrays are never mutated, so a
461
+ * merge seen recently returns its earlier result, which in turn keeps the
462
+ * next merge's input the same array.
463
+ */
464
+ const merges = /*#__PURE__*/ new Array(12).fill(empty);
465
+ let mergeSlot = 0;
429
466
  /** @internal */
430
467
  const mergeExpected = (a, b) => {
431
468
  if (Arr.isReadonlyArrayEmpty(a)) return b;
432
469
  if (Arr.isReadonlyArrayEmpty(b)) return a;
470
+ for (let i = 0; i < 12; i += 3) if (merges[i] === a && merges[i + 1] === b) return merges[i + 2];
433
471
  const out = a.slice();
434
472
  for (const e of b) if (!out.includes(e)) out.push(e);
473
+ merges[mergeSlot] = a;
474
+ merges[mergeSlot + 1] = b;
475
+ merges[mergeSlot + 2] = out;
476
+ mergeSlot = mergeSlot === 9 ? 0 : mergeSlot + 3;
435
477
  return out;
436
478
  };
437
479
  /**
package/dist/Input.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Input.js","names":[],"sources":["../src/Input.ts"],"sourcesContent":["/**\n * Input types and the mutable parse {@link State} cursor.\n *\n * Like winnow, effect-parse parsers advance a mutable cursor rather than\n * returning the remaining input. A {@link State} wraps the original input\n * together with the current offset, the streaming (partial) flag, the\n * services available to the parser, and the details of the most recent\n * failure.\n *\n * Most users never touch `State` directly. It is exposed for writing custom\n * low-level parsers with `Parser.make`, and for drivers that run a parser's\n * `step` many times over one input, reusing a state with {@link State.reset}.\n *\n * @since 0.1.0\n */\nimport * as Arr from \"effect/Array\"\nimport * as Predicate from \"effect/Predicate\"\nimport * as Context from \"effect/Context\"\nimport type { Encoding } from \"./Encoding.js\"\nimport type { ErrorKind } from \"./ParseError.js\"\nimport type { Builder as SyntaxBuilder } from \"./internal/syntax.js\"\n\n/**\n * The kinds of input a parser can consume.\n *\n * - `string`: tokens are Unicode code points (returned as strings), offsets\n * are UTF-16 code-unit indices.\n * - `Uint8Array`: tokens are bytes (numbers), slices are `subarray` views.\n * - `ReadonlyArray<T>`: tokens are elements, e.g. the output of a lexer.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Input = string | Uint8Array | ReadonlyArray<unknown>\n\n/**\n * Binary data that can be passed wherever a `Uint8Array` input is expected:\n * an `ArrayBuffer`, a `SharedArrayBuffer`, a `DataView` or any typed array.\n *\n * It is viewed, not copied, as a `Uint8Array` of its bytes. A typed array\n * with wider elements is viewed in the platform's byte order, which is\n * little endian on all common platforms, so a `Uint16Array` of UTF-16 code\n * units can be parsed with `Text.utf16le`.\n *\n * @since 0.1.0\n * @category models\n */\nexport type BinaryInput = ArrayBufferLike | ArrayBufferView\n\n/**\n * What the runners accept for a parser over `I`: the input itself, or, for\n * byte parsers, any {@link BinaryInput}.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Source<I> = I | ([I] extends [Uint8Array] ? BinaryInput : never)\n\n/**\n * Converts a {@link Source} to the input parsers read: binary data becomes a\n * `Uint8Array` view of the same memory, everything else is returned as is.\n *\n * @example\n * ```ts\n * import { Input } from \"@thomasfosterau/effect-parse\"\n *\n * Input.fromSource(new Uint16Array([0x41]).buffer) // Uint8Array [0x41, 0x00]\n * ```\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const fromSource: {\n (source: BinaryInput): Uint8Array\n <I extends Input>(source: Source<I>): I\n} = (source: Input | BinaryInput): any => {\n if (Predicate.isString(source) || source instanceof Uint8Array || Array.isArray(source)) return source\n if (ArrayBuffer.isView(source)) return new Uint8Array(source.buffer, source.byteOffset, source.byteLength)\n // An explicit length fixes the view's size even for a resizable buffer\n if (isArrayBufferLike(source)) return new Uint8Array(source, 0, source.byteLength)\n return source\n}\n\nconst isArrayBufferLike = (u: Input | BinaryInput): u is ArrayBufferLike =>\n u instanceof ArrayBuffer || (globalThis.SharedArrayBuffer !== undefined && u instanceof SharedArrayBuffer)\n\n/**\n * The type of a single token of an input.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Token<I> = I extends string\n ? string\n : I extends Uint8Array\n ? number\n : I extends ReadonlyArray<infer T>\n ? T\n : never\n\n/**\n * The type of a contiguous slice of an input.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Slice<I> = I extends string\n ? string\n : I extends Uint8Array\n ? Uint8Array\n : I extends ReadonlyArray<infer T>\n ? ReadonlyArray<T>\n : never\n\n/**\n * Sentinel returned by a parser step to signal failure. The failure details\n * are stored on the {@link State}.\n *\n * @since 0.1.0\n * @category failure\n */\nexport const Fail: unique symbol = /*#__PURE__*/ Symbol.for(\"effect-parse/Fail\")\n\n/**\n * @since 0.1.0\n * @category failure\n */\nexport type Fail = typeof Fail\n\n/**\n * How a failure propagates (winnow's `ErrMode`, nom's `Err`).\n *\n * - `Backtrack`: recoverable; `alt`, `opt`, `repeat`, ... try something else.\n * - `Cut`: unrecoverable; alternatives are not attempted.\n * - `Incomplete`: a partial (streaming) input ran out; more data is needed.\n *\n * @since 0.1.0\n * @category failure\n */\nexport type ErrMode = \"Backtrack\" | \"Cut\" | \"Incomplete\"\n\n/**\n * The details of a parse failure.\n *\n * @since 0.1.0\n * @category failure\n */\nexport class Failure {\n constructor(\n /** Offset into the input where the failure occurred. */\n readonly offset: number,\n /** The kind of parser that failed. */\n readonly kind: ErrorKind,\n /** Rendered descriptions of what was expected at `offset`. */\n readonly expected: ReadonlyArray<string>,\n /** Context labels added by `Parser.context`, innermost first. */\n readonly context: ReadonlyArray<string>,\n /** Whether a user supplied cause is present. */\n readonly hasCause: boolean,\n /** A user supplied (typed) cause. */\n readonly cause: unknown,\n /** An optional free-form message. */\n readonly message: string | undefined,\n /** For `Incomplete` failures, how many more tokens are needed (0 if unknown). */\n readonly needed: number\n ) {}\n}\n\nconst empty: ReadonlyArray<string> = []\n\n/** The failure a {@link State} starts with, before any step has failed. */\nconst initialFailure = /*#__PURE__*/ new Failure(0, \"Fail\", empty, empty, false, undefined, undefined, 0)\n\n/** @internal */\nexport const emptyStrings = empty\n\n/**\n * A tracing event emitted by `Parser.trace`.\n *\n * @since 0.1.0\n * @category tracing\n */\nexport interface TraceEvent {\n readonly _tag: \"Enter\" | \"Exit\"\n readonly name: string\n readonly depth: number\n readonly offset: number\n /** For `Exit` events: the outcome. */\n readonly result?: \"Ok\" | ErrMode\n /** For `Exit` events: the offset reached. */\n readonly endOffset?: number\n readonly state: State\n}\n\n/**\n * The mutable parsing cursor.\n *\n * @since 0.1.0\n * @category models\n */\nexport class State<I extends Input = Input> {\n /** The full input being parsed. */\n readonly input: I\n /**\n * The current offset. Parsers advance it by assigning it; moving it back\n * (backtracking, or after a lookahead) goes through {@link rewind}.\n */\n pos: number\n /** The end offset (the input's length; in bits inside `Bits.bits`). */\n end: number\n /** 0 = string, 1 = Uint8Array, 2 = array. */\n readonly inputKind: 0 | 1 | 2\n /** Whether the input is partial (streaming): running out yields `Incomplete`. */\n partial: boolean\n /** Services available to `Parser.service`. */\n context: Context.Context<never>\n /** Mode of the latest failure. Only meaningful after a step returned {@link Fail}. */\n mode: ErrMode = \"Backtrack\"\n /**\n * The latest failure, kept unmerged: the failure is `failureHead` merged\n * (as `mergeFailures` does) with `failureTie1` and then `failureTie2`, all\n * at the same offset. `Parser.alt` records its tied branch failures here\n * with {@link failTies} instead of merging them, so that an enclosing `alt`\n * whose next branch succeeds never pays for the merge. Reading\n * {@link failure} performs the merge, once.\n *\n * @internal\n */\n failureHead: Failure\n /** @internal */\n failureTie1: Failure | undefined = undefined\n /** @internal */\n failureTie2: Failure | undefined = undefined\n /** Backs {@link deepest}. @internal */\n deepestFailure: Failure | undefined = undefined\n /**\n * Whether the furthest failure is the latest failure, still unmerged, so\n * that {@link deepest} is that failure once merged. Only set while\n * `failureTie1` is.\n *\n * @internal\n */\n deepestIsLatest = false\n /**\n * The offset of a recoverable failure that occurred without consuming\n * input (for example the last attempt of a `repeat`). Its\n * expectations are merged into new failures at the same offset, producing\n * messages like `expected digit or \")\"`.\n */\n hintOffset = -1\n /** The expectations of the hint at {@link hintOffset}. */\n hintExpected: ReadonlyArray<string> = empty\n /**\n * The furthest recoverable failure seen so far, including failures that\n * were later swallowed by backtracking (for example a trailing separator\n * followed by an invalid element). It is reported instead of the final\n * failure when it lies further into the input. This is the classic PEG\n * \"farthest failure\" heuristic. `Parser.cut` keeps only the failures\n * recorded inside it when it commits, and `Parser.peek` and `Parser.not`\n * forget the failures of a lookahead that succeeded.\n */\n get deepest(): Failure | undefined {\n if (this.deepestIsLatest) this.settleFailure()\n return this.deepestFailure\n }\n set deepest(failure: Failure | undefined) {\n this.deepestIsLatest = false\n this.deepestFailure = failure\n }\n /** When defined, `Parser.resumeAfter`/`retryAfter` record failures here. */\n recovered: Array<Failure> | undefined = undefined\n /** When defined, `Parser.trace` reports events here. */\n tracer: ((event: TraceEvent) => void) | undefined = undefined\n /** Current tracing depth. */\n depth = 0\n /**\n * The text encoding of a byte input, recorded by `Text` parsers when they\n * fail so that errors can show the input as text.\n */\n encoding: Encoding<any> | undefined = undefined\n /**\n * The checkpoints of a resumable streaming parse (see\n * `ParserStream.parseAll`); `undefined` otherwise.\n *\n * @internal\n */\n resume: Map<object, Map<number, unknown>> | undefined = undefined\n /**\n * The tree builder of a `Syntax` parse; `undefined` otherwise. A builder\n * rather than a subclass of `State`, so that every state has one shape.\n *\n * @internal\n */\n syntax: SyntaxBuilder | undefined = undefined\n\n constructor(\n source: I | Source<I>,\n options?: {\n readonly partial?: boolean | undefined\n readonly context?: Context.Context<never> | undefined\n readonly offset?: number | undefined\n }\n ) {\n const input = fromSource(source as Input) as I\n this.input = input\n this.end = input.length\n this.pos = options?.offset ?? 0\n this.partial = options?.partial ?? false\n this.context = options?.context ?? Context.empty()\n this.inputKind = Predicate.isString(input) ? 0 : input instanceof Uint8Array ? 1 : 2\n this.failureHead = initialFailure\n }\n\n /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */\n get failure(): Failure {\n if (this.failureTie1 !== undefined) this.settleFailure()\n return this.failureHead\n }\n set failure(failure: Failure) {\n if (this.deepestIsLatest) this.settleFailure()\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n }\n\n /** Merges the latest failure's ties into it (see {@link failureHead}). */\n private settleFailure(): void {\n let failure = this.failureHead\n const tie1 = this.failureTie1\n if (tie1 !== undefined) {\n failure = mergeTiedFailures(failure, tie1, mergeExpected(failure.expected, tie1.expected))\n const tie2 = this.failureTie2\n if (tie2 !== undefined) failure = mergeTiedFailures(failure, tie2, mergeExpected(failure.expected, tie2.expected))\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n }\n if (this.deepestIsLatest) {\n this.deepestFailure = failure\n this.deepestIsLatest = false\n }\n }\n\n /**\n * Prepares the state for another run over the same input, starting at\n * `offset`: afterwards it behaves exactly like\n * `new State(state.input, { ...options, offset })`, without allocating a\n * new state.\n *\n * Every per-run field is reset: the cursor and end, the latest failure,\n * hints and furthest failure, recorded recoveries, the tracer and tracing\n * depth, the recorded encoding and streaming checkpoints. Like the\n * constructor, `partial` defaults to `false` and `context` to the empty\n * context, so pass them again on every reset.\n *\n * Use it to run many small parses over one buffer, for example one per\n * token, with `parser.step`. A state can be reused after any run,\n * including one that failed, returned `Incomplete` or threw.\n *\n * @example\n * ```ts\n * import { Ascii, Input } from \"@thomasfosterau/effect-parse\"\n *\n * const state = new Input.State(\"12 34\")\n * Ascii.decUint.step(state) // 12\n * state.reset(3)\n * Ascii.decUint.step(state) // 34\n * ```\n *\n * @since 0.2.0\n */\n reset(\n offset: number = 0,\n options?: {\n readonly partial?: boolean | undefined\n readonly context?: Context.Context<never> | undefined\n }\n ): this {\n this.pos = offset\n this.end = this.input.length\n this.partial = options?.partial ?? false\n this.context = options?.context ?? Context.empty()\n this.mode = \"Backtrack\"\n this.failureHead = initialFailure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n this.hintOffset = -1\n this.hintExpected = empty\n this.deepestFailure = undefined\n this.deepestIsLatest = false\n this.recovered = undefined\n this.tracer = undefined\n this.depth = 0\n this.encoding = undefined\n this.resume = undefined\n return this\n }\n\n /**\n * Moves the cursor back to `offset`, abandoning what was parsed after it:\n * how a parser backtracks, or returns to where a lookahead started. A step\n * that moves the cursor backwards must use this rather than assigning\n * {@link pos}, so that a `Syntax` parse drops the nodes the abandoned\n * attempt built. Moving forward is an assignment.\n *\n * @example\n * ```ts\n * import { Input, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * // Like `Parser.opt`, for one parser\n * const optional = <A>(p: Parser.Parser<A>) =>\n * Parser.make<A | undefined>((state) => {\n * const start = state.pos\n * const a = p.step(state)\n * if (a !== Input.Fail) return a\n * if (state.mode !== \"Backtrack\") return Input.Fail\n * state.rewind(start)\n * return undefined\n * })\n * ```\n *\n * @since 0.4.0\n */\n rewind(offset: number): void {\n const syntax = this.syntax\n if (syntax !== undefined && offset < this.pos) syntax.rewound(this.pos, offset)\n this.pos = offset\n }\n\n /**\n * The number of input units (code units, bytes or elements) remaining.\n */\n remaining(): number {\n return this.end - this.pos\n }\n\n /**\n * Whether the cursor is at the end of the input.\n */\n atEnd(): boolean {\n return this.pos >= this.end\n }\n\n /**\n * Extracts the slice `[start, end)` of the input.\n */\n slice(start: number, end: number): Slice<I> {\n const input = this.input as any\n switch (this.inputKind) {\n case 0:\n return input.slice(start, end)\n case 1:\n return input.subarray(start, end)\n default:\n return input.slice(start, end)\n }\n }\n\n /**\n * Records a recoverable failure at the current offset and returns {@link Fail}.\n */\n backtrack(kind: ErrorKind, expected: ReadonlyArray<string> = empty, offset: number = this.pos): Fail {\n return this.failWith(\"Backtrack\", this.makeFailure(offset, kind, expected))\n }\n\n /**\n * Records an unrecoverable failure at the current offset and returns {@link Fail}.\n */\n cut(kind: ErrorKind, expected: ReadonlyArray<string> = empty, offset: number = this.pos): Fail {\n return this.failWith(\"Cut\", this.makeFailure(offset, kind, expected))\n }\n\n /**\n * Records an `Incomplete` failure (only meaningful for partial input) and\n * returns {@link Fail}.\n */\n incomplete(needed: number, expected: ReadonlyArray<string> = empty): Fail {\n return this.failWith(\n \"Incomplete\",\n new Failure(this.pos, \"Incomplete\", expected, empty, false, undefined, undefined, needed)\n )\n }\n\n /**\n * Fails because the input ended: `Incomplete` for partial input, otherwise\n * a `Backtrack` failure of the given kind.\n */\n eoi(kind: ErrorKind, expected: ReadonlyArray<string>, needed: number): Fail {\n return this.partial ? this.incomplete(needed, expected) : this.backtrack(kind, expected)\n }\n\n /**\n * Records a failure carrying a user supplied cause.\n */\n failCause(mode: ErrMode, kind: ErrorKind, cause: unknown, offset: number = this.pos): Fail {\n return this.failWith(mode, new Failure(offset, kind, empty, empty, true, cause, undefined, 0))\n }\n\n /**\n * Records a failure carrying a message.\n */\n failMessage(mode: ErrMode, kind: ErrorKind, message: string, offset: number = this.pos): Fail {\n return this.failWith(mode, new Failure(offset, kind, empty, empty, false, undefined, message, 0))\n }\n\n /**\n * Records the given failure and returns {@link Fail}.\n */\n failWith(mode: ErrMode, failure: Failure): Fail {\n this.mode = mode\n if (this.deepestIsLatest) {\n // The furthest failure is the latest one: it is replaced below, unmerged, if `failure` is as far\n if (mode === \"Backtrack\" && failure.offset >= this.failureHead.offset) this.deepestIsLatest = false\n else this.settleFailure()\n }\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n if (mode === \"Backtrack\" && (this.deepestFailure === undefined || failure.offset >= this.deepestFailure.offset)) {\n this.deepestFailure = failure\n }\n if (this.syntax !== undefined) this.syntax.reach(failure.offset)\n return Fail\n }\n\n /**\n * Records a recoverable failure made of tied failures, merged only when\n * read: `failWith(\"Backtrack\", f)` where `f` merges `head` with `tie1`\n * and then `tie2` (all at the same offset), as `mergeFailures` would.\n *\n * @internal\n */\n failTies(head: Failure, tie1: Failure, tie2: Failure | undefined): Fail {\n this.mode = \"Backtrack\"\n if (this.deepestIsLatest && head.offset < this.failureHead.offset) this.settleFailure()\n this.failureHead = head\n this.failureTie1 = tie1\n this.failureTie2 = tie2\n this.deepestIsLatest = this.deepestFailure === undefined || head.offset >= this.deepestFailure.offset\n if (this.syntax !== undefined) this.syntax.reach(head.offset)\n return Fail\n }\n\n /**\n * Replaces the details of the current failure (for example to add context),\n * keeping the record of the furthest failure consistent.\n */\n replaceFailure(failure: Failure): void {\n if (this.deepest === this.failure) this.deepest = failure\n this.failure = failure\n }\n\n /**\n * The failure to report to the user: the current failure, or the furthest\n * failure if it lies beyond the current one and the current failure is a\n * plain syntax error (no user cause or message).\n */\n reportedFailure(): Failure {\n const f = this.failure\n const d = this.deepest\n if (\n d === undefined ||\n d === f ||\n d.offset <= f.offset ||\n this.mode === \"Incomplete\" ||\n f.hasCause ||\n f.message !== undefined\n ) {\n return f\n }\n const context = Arr.isReadonlyArrayEmpty(d.context)\n ? f.context\n : [...d.context, ...f.context.filter((l) => !d.context.includes(l))]\n return new Failure(d.offset, d.kind, d.expected, context, d.hasCause, d.cause, d.message, d.needed)\n }\n\n /**\n * Records that, at `offset`, any of `expected` could also have been\n * accepted. Used by parsers that stop without failing, such as `opt`,\n * `repeat` and `Ascii.digit1`.\n */\n setHint(offset: number, expected: ReadonlyArray<string>): void {\n if (this.syntax !== undefined) this.syntax.reach(offset)\n if (this.hintOffset === offset) {\n this.hintExpected = mergeExpected(this.hintExpected, expected)\n } else {\n this.hintOffset = offset\n this.hintExpected = expected\n }\n }\n\n /** @internal */\n makeFailure(offset: number, kind: ErrorKind, expected: ReadonlyArray<string>): Failure {\n if (this.hintOffset === offset && Arr.isReadonlyArrayNonEmpty(this.hintExpected)) {\n expected = mergeExpected(this.hintExpected, expected)\n }\n return new Failure(offset, kind, expected, empty, false, undefined, undefined, 0)\n }\n}\n\n/** @internal */\nexport const mergeExpected = (a: ReadonlyArray<string>, b: ReadonlyArray<string>): ReadonlyArray<string> => {\n if (Arr.isReadonlyArrayEmpty(a)) return b\n if (Arr.isReadonlyArrayEmpty(b)) return a\n const out = a.slice()\n for (const e of b) {\n if (!out.includes(e)) out.push(e)\n }\n return out\n}\n\n/**\n * Combines the failures of two alternatives: the furthest failure wins, and\n * failures at the same offset have their expectations merged.\n *\n * @internal\n */\nexport const mergeFailures = (a: Failure, b: Failure): Failure => {\n if (a.offset > b.offset) return a\n if (b.offset > a.offset) return b\n return mergeTiedFailures(a, b, mergeExpected(a.expected, b.expected))\n}\n\n/**\n * {@link mergeFailures} for two failures at the same offset, given their\n * merged expectations (`mergeExpected(a.expected, b.expected)`, possibly\n * memoised by the caller).\n *\n * @internal\n */\nexport const mergeTiedFailures = (a: Failure, b: Failure, expected: ReadonlyArray<string>): Failure => {\n if (expected === b.expected) return b\n return new Failure(\n b.offset,\n b.kind,\n expected,\n Arr.isReadonlyArrayNonEmpty(b.context) ? b.context : a.context,\n b.hasCause || a.hasCause,\n b.hasCause ? b.cause : a.cause,\n b.message ?? a.message,\n b.needed\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,MAAa,cAGR,WAAqC;CACxC,IAAI,UAAU,SAAS,MAAM,KAAK,kBAAkB,cAAc,MAAM,QAAQ,MAAM,GAAG,OAAO;CAChG,IAAI,YAAY,OAAO,MAAM,GAAG,OAAO,IAAI,WAAW,OAAO,QAAQ,OAAO,YAAY,OAAO,UAAU;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S,EAAE,QAAQ,OAAO;CAChC,OAAO,kBAAkB,GAAG,GAAG,cAAc,EAAE,UAAU,EAAE,QAAQ,CAAC;AACtE;;;;;;;;AASA,MAAa,qBAAqB,GAAY,GAAY,aAA6C;CACrG,IAAI,aAAa,EAAE,UAAU,OAAO;CACpC,OAAO,IAAI,QACT,EAAE,QACF,EAAE,MACF,UACA,IAAI,wBAAwB,EAAE,OAAO,IAAI,EAAE,UAAU,EAAE,SACvD,EAAE,YAAY,EAAE,UAChB,EAAE,WAAW,EAAE,QAAQ,EAAE,OACzB,EAAE,WAAW,EAAE,SACf,EAAE,MACJ;AACF"}
1
+ {"version":3,"file":"Input.js","names":[],"sources":["../src/Input.ts"],"sourcesContent":["/**\n * Input types and the mutable parse {@link State} cursor.\n *\n * Like winnow, effect-parse parsers advance a mutable cursor rather than\n * returning the remaining input. A {@link State} wraps the original input\n * together with the current offset, the streaming (partial) flag, the\n * services available to the parser, and the details of the most recent\n * failure.\n *\n * Most users never touch `State` directly. It is exposed for writing custom\n * low-level parsers with `Parser.make`, and for drivers that run a parser's\n * `step` many times over one input, reusing a state with {@link State.reset}.\n *\n * @since 0.1.0\n */\nimport * as Arr from \"effect/Array\"\nimport * as Predicate from \"effect/Predicate\"\nimport * as Context from \"effect/Context\"\nimport type { Encoding } from \"./Encoding.js\"\nimport type { ErrorKind } from \"./ParseError.js\"\nimport type { Builder as SyntaxBuilder } from \"./internal/syntax.js\"\nimport type { AsciiRun } from \"./internal/text.js\"\n\n/**\n * The kinds of input a parser can consume.\n *\n * - `string`: tokens are Unicode code points (returned as strings), offsets\n * are UTF-16 code-unit indices.\n * - `Uint8Array`: tokens are bytes (numbers), slices are `subarray` views.\n * - `ReadonlyArray<T>`: tokens are elements, e.g. the output of a lexer.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Input = string | Uint8Array | ReadonlyArray<unknown>\n\n/**\n * Binary data that can be passed wherever a `Uint8Array` input is expected:\n * an `ArrayBuffer`, a `SharedArrayBuffer`, a `DataView` or any typed array.\n *\n * It is viewed, not copied, as a `Uint8Array` of its bytes. A typed array\n * with wider elements is viewed in the platform's byte order, which is\n * little endian on all common platforms, so a `Uint16Array` of UTF-16 code\n * units can be parsed with `Text.utf16le`.\n *\n * @since 0.1.0\n * @category models\n */\nexport type BinaryInput = ArrayBufferLike | ArrayBufferView\n\n/**\n * What the runners accept for a parser over `I`: the input itself, or, for\n * byte parsers, any {@link BinaryInput}.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Source<I> = I | ([I] extends [Uint8Array] ? BinaryInput : never)\n\n/**\n * The overloads of {@link fromSource}.\n *\n * @since 0.5.0\n * @category constructors\n */\nexport interface FromSourceFn {\n (source: BinaryInput): Uint8Array\n <I extends Input>(source: Source<I>): I\n}\n\n/**\n * Converts a {@link Source} to the input parsers read: binary data becomes a\n * `Uint8Array` view of the same memory, everything else is returned as is.\n *\n * @example\n * ```ts\n * import { Input } from \"@thomasfosterau/effect-parse\"\n *\n * Input.fromSource(new Uint16Array([0x41]).buffer) // Uint8Array [0x41, 0x00]\n * ```\n *\n * @since 0.1.0\n * @category constructors\n */\nexport const fromSource: FromSourceFn = (source: Input | BinaryInput): any => {\n if (Predicate.isString(source) || source instanceof Uint8Array || Array.isArray(source)) return source\n if (ArrayBuffer.isView(source)) return new Uint8Array(source.buffer, source.byteOffset, source.byteLength)\n // An explicit length fixes the view's size even for a resizable buffer\n if (isArrayBufferLike(source)) return new Uint8Array(source, 0, source.byteLength)\n return source\n}\n\nconst isArrayBufferLike = (u: Input | BinaryInput): u is ArrayBufferLike =>\n u instanceof ArrayBuffer || (globalThis.SharedArrayBuffer !== undefined && u instanceof SharedArrayBuffer)\n\n/**\n * The type of a single token of an input.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Token<I> = I extends string\n ? string\n : I extends Uint8Array\n ? number\n : I extends ReadonlyArray<infer T>\n ? T\n : never\n\n/**\n * The type of a contiguous slice of an input.\n *\n * @since 0.1.0\n * @category models\n */\nexport type Slice<I> = I extends string\n ? string\n : I extends Uint8Array\n ? Uint8Array\n : I extends ReadonlyArray<infer T>\n ? ReadonlyArray<T>\n : never\n\n/**\n * Sentinel returned by a parser step to signal failure. The failure details\n * are stored on the {@link State}.\n *\n * @since 0.1.0\n * @category failure\n */\nexport const Fail: unique symbol = /*#__PURE__*/ Symbol.for(\"effect-parse/Fail\")\n\n/**\n * @since 0.1.0\n * @category failure\n */\nexport type Fail = typeof Fail\n\n/**\n * How a failure propagates (winnow's `ErrMode`, nom's `Err`).\n *\n * - `Backtrack`: recoverable; `alt`, `opt`, `repeat`, ... try something else.\n * - `Cut`: unrecoverable; alternatives are not attempted.\n * - `Incomplete`: a partial (streaming) input ran out; more data is needed.\n *\n * @since 0.1.0\n * @category failure\n */\nexport type ErrMode = \"Backtrack\" | \"Cut\" | \"Incomplete\"\n\n/**\n * The details of a parse failure.\n *\n * @since 0.1.0\n * @category failure\n */\nexport class Failure {\n constructor(\n /** Offset into the input where the failure occurred. */\n readonly offset: number,\n /** The kind of parser that failed. */\n readonly kind: ErrorKind,\n /** Rendered descriptions of what was expected at `offset`. */\n readonly expected: ReadonlyArray<string>,\n /** Context labels added by `Parser.context`, innermost first. */\n readonly context: ReadonlyArray<string>,\n /** Whether a user supplied cause is present. */\n readonly hasCause: boolean,\n /** A user supplied (typed) cause. */\n readonly cause: unknown,\n /** An optional free-form message. */\n readonly message: string | undefined,\n /** For `Incomplete` failures, how many more tokens are needed (0 if unknown). */\n readonly needed: number\n ) {}\n}\n\nconst empty: ReadonlyArray<string> = []\n\n/** The failure a {@link State} starts with, before any step has failed. */\nconst initialFailure = /*#__PURE__*/ new Failure(0, \"Fail\", empty, empty, false, undefined, undefined, 0)\n\n/** @internal */\nexport const emptyStrings = empty\n\n/**\n * A tracing event emitted by `Parser.trace`.\n *\n * @since 0.1.0\n * @category tracing\n */\nexport interface TraceEvent {\n readonly _tag: \"Enter\" | \"Exit\"\n readonly name: string\n readonly depth: number\n readonly offset: number\n /** For `Exit` events: the outcome. */\n readonly result?: \"Ok\" | ErrMode\n /** For `Exit` events: the offset reached. */\n readonly endOffset?: number\n readonly state: State\n}\n\n/**\n * The mutable parsing cursor.\n *\n * @since 0.1.0\n * @category models\n */\nexport class State<I extends Input = Input> {\n /** The full input being parsed. */\n readonly input: I\n /**\n * The current offset. Parsers advance it by assigning it; moving it back\n * (backtracking, or after a lookahead) goes through {@link rewind}.\n */\n pos: number\n /** The end offset (the input's length; in bits inside `Bits.bits`). */\n end: number\n /** 0 = string, 1 = Uint8Array, 2 = array. */\n readonly inputKind: 0 | 1 | 2\n /** Whether the input is partial (streaming): running out yields `Incomplete`. */\n partial: boolean\n /** Services available to `Parser.service`. */\n context: Context.Context<never>\n /** Mode of the latest failure. Only meaningful after a step returned {@link Fail}. */\n mode: ErrMode = \"Backtrack\"\n /**\n * The latest failure, kept unmerged: the failure is `failureHead` merged\n * (as `mergeFailures` does) with `failureTie1` and then `failureTie2`, all\n * at the same offset. `Parser.alt` records its tied branch failures here\n * with {@link failTies} instead of merging them, so that an enclosing `alt`\n * whose next branch succeeds never pays for the merge. Reading\n * {@link failure} performs the merge, once.\n *\n * @internal\n */\n failureHead: Failure\n /** @internal */\n failureTie1: Failure | undefined = undefined\n /** @internal */\n failureTie2: Failure | undefined = undefined\n /** Backs {@link deepest}. @internal */\n deepestFailure: Failure | undefined = undefined\n /**\n * Whether the furthest failure is the latest failure, still unmerged, so\n * that {@link deepest} is that failure once merged. Only set while\n * `failureTie1` is.\n *\n * @internal\n */\n deepestIsLatest = false\n /**\n * The offset of a recoverable failure that occurred without consuming\n * input (for example the last attempt of a `repeat`). Its\n * expectations are merged into new failures at the same offset, producing\n * messages like `expected digit or \")\"`.\n */\n hintOffset = -1\n /** The expectations of the hint at {@link hintOffset}. */\n hintExpected: ReadonlyArray<string> = empty\n /**\n * The furthest recoverable failure seen so far, including failures that\n * were later swallowed by backtracking (for example a trailing separator\n * followed by an invalid element). It is reported instead of the final\n * failure when it lies further into the input. This is the classic PEG\n * \"farthest failure\" heuristic. `Parser.cut` keeps only the failures\n * recorded inside it when it commits, and `Parser.peek` and `Parser.not`\n * forget the failures of a lookahead that succeeded.\n */\n get deepest(): Failure | undefined {\n if (this.deepestIsLatest) this.settleFailure()\n return this.deepestFailure\n }\n set deepest(failure: Failure | undefined) {\n this.deepestIsLatest = false\n this.deepestFailure = failure\n }\n /** When defined, `Parser.resumeAfter`/`retryAfter` record failures here. */\n recovered: Array<Failure> | undefined = undefined\n /** When defined, `Parser.trace` reports events here. */\n tracer: ((event: TraceEvent) => void) | undefined = undefined\n /** Current tracing depth. */\n depth = 0\n /**\n * The text encoding of a byte input, recorded by `Text` parsers when they\n * fail so that errors can show the input as text.\n */\n encoding: Encoding<any> | undefined = undefined\n /**\n * The checkpoints of a resumable streaming parse (see\n * `ParserStream.parseAll`); `undefined` otherwise.\n *\n * @internal\n */\n resume: Map<object, Map<number, unknown>> | undefined = undefined\n /**\n * The tree builder of a `Syntax` parse; `undefined` otherwise. A builder\n * rather than a subclass of `State`, so that every state has one shape.\n *\n * @internal\n */\n syntax: SyntaxBuilder | undefined = undefined\n /**\n * Where the stop characters of compiled `takeTill`s next occur in this\n * state's input, by search site; created on first use. It lives as long\n * as the state (whose input never changes), and `reset` clears it with\n * the other per-run fields.\n *\n * @internal\n */\n searches: Map<object, Array<number>> | undefined = undefined\n /**\n * A run of ASCII bytes of this state's UTF-8 input, decoded once, from\n * which `Text.utf8` slices the long strings it decodes (see\n * `internal/text.ts`); `reset` clears it with the other per-run fields.\n *\n * @internal\n */\n asciiRun: AsciiRun | undefined = undefined\n /**\n * A `DataView` of this state's byte input, for the `Binary` parsers;\n * created on first use. It lives as long as the state, whose input never\n * changes: one per read cost most of a number's time.\n *\n * @internal\n */\n view: DataView | undefined = undefined\n\n constructor(\n source: I | Source<I>,\n options?: {\n readonly partial?: boolean | undefined\n readonly context?: Context.Context<never> | undefined\n readonly offset?: number | undefined\n }\n ) {\n const input = fromSource<I>(source)\n this.input = input\n this.end = input.length\n this.pos = options?.offset ?? 0\n this.partial = options?.partial ?? false\n this.context = options?.context ?? Context.empty()\n this.inputKind = Predicate.isString(input) ? 0 : input instanceof Uint8Array ? 1 : 2\n this.failureHead = initialFailure\n }\n\n /** Details of the latest failure. Only meaningful after a step returned {@link Fail}. */\n get failure(): Failure {\n if (this.failureTie1 !== undefined) this.settleFailure()\n return this.failureHead\n }\n set failure(failure: Failure) {\n if (this.deepestIsLatest) this.settleFailure()\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n }\n\n /** Merges the latest failure's ties into it (see {@link failureHead}). */\n private settleFailure(): void {\n let failure = this.failureHead\n const tie1 = this.failureTie1\n if (tie1 !== undefined) {\n failure = mergeTiedFailures(failure, tie1, mergeExpected(failure.expected, tie1.expected))\n const tie2 = this.failureTie2\n if (tie2 !== undefined) failure = mergeTiedFailures(failure, tie2, mergeExpected(failure.expected, tie2.expected))\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n }\n if (this.deepestIsLatest) {\n this.deepestFailure = failure\n this.deepestIsLatest = false\n }\n }\n\n /**\n * Prepares the state for another run over the same input, starting at\n * `offset`: afterwards it behaves exactly like\n * `new State(state.input, { ...options, offset })`, without allocating a\n * new state.\n *\n * Every per-run field is reset: the cursor and end, the latest failure,\n * hints and furthest failure, recorded recoveries, the tracer and tracing\n * depth, the recorded encoding and streaming checkpoints. Like the\n * constructor, `partial` defaults to `false` and `context` to the empty\n * context, so pass them again on every reset.\n *\n * Use it to run many small parses over one buffer, for example one per\n * token, with `parser.step`. A state can be reused after any run,\n * including one that failed, returned `Incomplete` or threw.\n *\n * @example\n * ```ts\n * import { Ascii, Input } from \"@thomasfosterau/effect-parse\"\n *\n * const state = new Input.State(\"12 34\")\n * Ascii.decUint.step(state) // 12\n * state.reset(3)\n * Ascii.decUint.step(state) // 34\n * ```\n *\n * @since 0.2.0\n */\n reset(\n offset: number = 0,\n options?: {\n readonly partial?: boolean | undefined\n readonly context?: Context.Context<never> | undefined\n }\n ): this {\n this.pos = offset\n this.end = this.input.length\n this.partial = options?.partial ?? false\n this.context = options?.context ?? Context.empty()\n this.mode = \"Backtrack\"\n this.failureHead = initialFailure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n this.hintOffset = -1\n this.hintExpected = empty\n this.deepestFailure = undefined\n this.deepestIsLatest = false\n this.recovered = undefined\n this.tracer = undefined\n this.depth = 0\n this.encoding = undefined\n this.resume = undefined\n this.searches = undefined\n this.asciiRun = undefined\n return this\n }\n\n /**\n * Moves the cursor back to `offset`, abandoning what was parsed after it:\n * how a parser backtracks, or returns to where a lookahead started. A step\n * that moves the cursor backwards must use this rather than assigning\n * {@link pos}, so that a `Syntax` parse drops the nodes the abandoned\n * attempt built. Moving forward is an assignment.\n *\n * @example\n * ```ts\n * import { Input, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * // Like `Parser.opt`, for one parser\n * const optional = <A>(p: Parser.Parser<A>) =>\n * Parser.make<A | undefined>((state) => {\n * const start = state.pos\n * const a = p.step(state)\n * if (a !== Input.Fail) return a\n * if (state.mode !== \"Backtrack\") return Input.Fail\n * state.rewind(start)\n * return undefined\n * })\n * ```\n *\n * @since 0.4.0\n */\n rewind(offset: number): void {\n const syntax = this.syntax\n if (syntax !== undefined && offset < this.pos) syntax.rewound(this.pos, offset)\n this.pos = offset\n }\n\n /**\n * The number of input units (code units, bytes or elements) remaining.\n */\n remaining(): number {\n return this.end - this.pos\n }\n\n /**\n * Whether the cursor is at the end of the input.\n */\n atEnd(): boolean {\n return this.pos >= this.end\n }\n\n /**\n * Extracts the slice `[start, end)` of the input.\n */\n slice(start: number, end: number): Slice<I> {\n // SAFETY: `inputKind` 1 is a `Uint8Array`, whose `subarray` returns a\n // `Uint8Array` view (its `Slice`); 0 and 2 are a string and an array, whose\n // `slice` returns a string and an array of the same elements (their\n // `Slice`). `subarray` is only called for kind 1\n const input = this.input as {\n slice(start: number, end: number): Slice<I>\n subarray(start: number, end: number): Slice<I>\n } & I\n switch (this.inputKind) {\n case 0:\n return input.slice(start, end)\n case 1:\n return input.subarray(start, end)\n default:\n return input.slice(start, end)\n }\n }\n\n /**\n * Records a recoverable failure at the current offset and returns {@link Fail}.\n */\n backtrack(kind: ErrorKind, expected: ReadonlyArray<string> = empty, offset: number = this.pos): Fail {\n return this.failWith(\"Backtrack\", this.makeFailure(offset, kind, expected))\n }\n\n /**\n * Records an unrecoverable failure at the current offset and returns {@link Fail}.\n */\n cut(kind: ErrorKind, expected: ReadonlyArray<string> = empty, offset: number = this.pos): Fail {\n return this.failWith(\"Cut\", this.makeFailure(offset, kind, expected))\n }\n\n /**\n * Records an `Incomplete` failure (only meaningful for partial input) and\n * returns {@link Fail}.\n */\n incomplete(needed: number, expected: ReadonlyArray<string> = empty): Fail {\n return this.failWith(\n \"Incomplete\",\n new Failure(this.pos, \"Incomplete\", expected, empty, false, undefined, undefined, needed)\n )\n }\n\n /**\n * Fails because the input ended: `Incomplete` for partial input, otherwise\n * a `Backtrack` failure of the given kind.\n */\n eoi(kind: ErrorKind, expected: ReadonlyArray<string>, needed: number): Fail {\n return this.partial ? this.incomplete(needed, expected) : this.backtrack(kind, expected)\n }\n\n /**\n * Records a failure carrying a user supplied cause.\n */\n failCause(mode: ErrMode, kind: ErrorKind, cause: unknown, offset: number = this.pos): Fail {\n return this.failWith(mode, new Failure(offset, kind, empty, empty, true, cause, undefined, 0))\n }\n\n /**\n * Records a failure carrying a message.\n */\n failMessage(mode: ErrMode, kind: ErrorKind, message: string, offset: number = this.pos): Fail {\n return this.failWith(mode, new Failure(offset, kind, empty, empty, false, undefined, message, 0))\n }\n\n /**\n * Records the given failure and returns {@link Fail}.\n */\n failWith(mode: ErrMode, failure: Failure): Fail {\n this.mode = mode\n if (this.deepestIsLatest) {\n // The furthest failure is the latest one: it is replaced below, unmerged, if `failure` is as far\n if (mode === \"Backtrack\" && failure.offset >= this.failureHead.offset) this.deepestIsLatest = false\n else this.settleFailure()\n }\n this.failureHead = failure\n this.failureTie1 = undefined\n this.failureTie2 = undefined\n if (mode === \"Backtrack\" && (this.deepestFailure === undefined || failure.offset >= this.deepestFailure.offset)) {\n this.deepestFailure = failure\n }\n if (this.syntax !== undefined) this.syntax.reach(failure.offset)\n return Fail\n }\n\n /**\n * Records a recoverable failure made of tied failures, merged only when\n * read: `failWith(\"Backtrack\", f)` where `f` merges `head` with `tie1`\n * and then `tie2` (all at the same offset), as `mergeFailures` would.\n *\n * @internal\n */\n failTies(head: Failure, tie1: Failure, tie2: Failure | undefined): Fail {\n this.mode = \"Backtrack\"\n if (this.deepestIsLatest && head.offset < this.failureHead.offset) this.settleFailure()\n this.failureHead = head\n this.failureTie1 = tie1\n this.failureTie2 = tie2\n this.deepestIsLatest = this.deepestFailure === undefined || head.offset >= this.deepestFailure.offset\n if (this.syntax !== undefined) this.syntax.reach(head.offset)\n return Fail\n }\n\n /**\n * Replaces the details of the current failure (for example to add context),\n * keeping the record of the furthest failure consistent.\n */\n replaceFailure(failure: Failure): void {\n if (this.deepest === this.failure) this.deepest = failure\n this.failure = failure\n }\n\n /**\n * The failure to report to the user: the current failure, or the furthest\n * failure if it lies beyond the current one and the current failure is a\n * plain syntax error (no user cause or message).\n */\n reportedFailure(): Failure {\n const f = this.failure\n const d = this.deepest\n if (\n d === undefined ||\n d === f ||\n d.offset <= f.offset ||\n this.mode === \"Incomplete\" ||\n f.hasCause ||\n f.message !== undefined\n ) {\n return f\n }\n const context = Arr.isReadonlyArrayEmpty(d.context)\n ? f.context\n : [...d.context, ...f.context.filter((l) => !d.context.includes(l))]\n return new Failure(d.offset, d.kind, d.expected, context, d.hasCause, d.cause, d.message, d.needed)\n }\n\n /**\n * Records that, at `offset`, any of `expected` could also have been\n * accepted. Used by parsers that stop without failing, such as `opt`,\n * `repeat` and `Ascii.digit1`.\n */\n setHint(offset: number, expected: ReadonlyArray<string>): void {\n if (this.syntax !== undefined) this.syntax.reach(offset)\n if (this.hintOffset === offset) {\n this.hintExpected = mergeExpected(this.hintExpected, expected)\n } else {\n this.hintOffset = offset\n this.hintExpected = expected\n }\n }\n\n /** @internal */\n makeFailure(offset: number, kind: ErrorKind, expected: ReadonlyArray<string>): Failure {\n if (this.hintOffset === offset && Arr.isReadonlyArrayNonEmpty(this.hintExpected)) {\n expected = mergeExpected(this.hintExpected, expected)\n }\n return new Failure(offset, kind, expected, empty, false, undefined, undefined, 0)\n }\n}\n\n/**\n * The last merges {@link mergeExpected} made, as `[a, b, merged]` triples. A\n * parse merges the same few pairs of expectation arrays over and over (a\n * whitespace skipper's hint with a repetition's, then with the failure of\n * the token after them), and expectation arrays are never mutated, so a\n * merge seen recently returns its earlier result, which in turn keeps the\n * next merge's input the same array.\n */\nconst merges: Array<ReadonlyArray<string>> = /*#__PURE__*/ new Array(12).fill(empty)\nlet mergeSlot = 0\n\n/** @internal */\nexport const mergeExpected = (a: ReadonlyArray<string>, b: ReadonlyArray<string>): ReadonlyArray<string> => {\n if (Arr.isReadonlyArrayEmpty(a)) return b\n if (Arr.isReadonlyArrayEmpty(b)) return a\n for (let i = 0; i < 12; i += 3) if (merges[i] === a && merges[i + 1] === b) return merges[i + 2]\n const out = a.slice()\n for (const e of b) {\n if (!out.includes(e)) out.push(e)\n }\n merges[mergeSlot] = a\n merges[mergeSlot + 1] = b\n merges[mergeSlot + 2] = out\n mergeSlot = mergeSlot === 9 ? 0 : mergeSlot + 3\n return out\n}\n\n/**\n * Combines the failures of two alternatives: the furthest failure wins, and\n * failures at the same offset have their expectations merged.\n *\n * @internal\n */\nexport const mergeFailures = (a: Failure, b: Failure): Failure => {\n if (a.offset > b.offset) return a\n if (b.offset > a.offset) return b\n return mergeTiedFailures(a, b, mergeExpected(a.expected, b.expected))\n}\n\n/**\n * {@link mergeFailures} for two failures at the same offset, given their\n * merged expectations (`mergeExpected(a.expected, b.expected)`, possibly\n * memoised by the caller).\n *\n * @internal\n */\nexport const mergeTiedFailures = (a: Failure, b: Failure, expected: ReadonlyArray<string>): Failure => {\n if (expected === b.expected) return b\n return new Failure(\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/dist/Nom.d.ts CHANGED
@@ -1,30 +1,24 @@
1
1
  import * as Result from "effect/Result";
2
2
  import { Input, Slice, Token } from "./Input.js";
3
- import * as P from "./Parser.js";
4
3
  import { Parser } from "./Parser.js";
4
+ import * as Token$1 from "./Token.js";
5
5
  import { TokenSet } from "./Token.js";
6
6
  import * as Option from "effect/Option";
7
+ import * as Ascii from "./Ascii.js";
7
8
  /**
8
9
  * Matches a literal (nom's `tag`).
9
10
  *
10
11
  * @since 0.1.0
11
12
  * @category bytes
12
13
  */
13
- export declare const tag: {
14
- <const L extends string>(literal: L): Parser<L, never, never, string>;
15
- (literal: Uint8Array): Parser<Uint8Array, never, never, Uint8Array>;
16
- <const T>(literal: ReadonlyArray<T>): Parser<ReadonlyArray<T>, never, never, ReadonlyArray<T>>;
17
- };
14
+ export declare const tag: Token$1.LiteralFn;
18
15
  /**
19
16
  * Matches a literal, ignoring ASCII case (nom's `tag_no_case`).
20
17
  *
21
18
  * @since 0.1.0
22
19
  * @category bytes
23
20
  */
24
- export declare const tagNoCase: {
25
- (literal: string): Parser<string>;
26
- (literal: Uint8Array): Parser<Uint8Array, never, never, Uint8Array>;
27
- };
21
+ export declare const tagNoCase: Ascii.CaselessFn;
28
22
  /**
29
23
  * Matches a single character (nom's `char`).
30
24
  *
@@ -102,11 +96,7 @@ export declare const takeTill1: <I extends Input = string>(predicate: (token: To
102
96
  * @since 0.1.0
103
97
  * @category bytes
104
98
  */
105
- export declare const takeUntil: {
106
- (literal: string, range?: P.Range): Parser<string, never, never, string>;
107
- (literal: Uint8Array, range?: P.Range): Parser<Uint8Array, never, never, Uint8Array>;
108
- <T>(literal: ReadonlyArray<T>, range?: P.Range): Parser<ReadonlyArray<T>, never, never, ReadonlyArray<T>>;
109
- };
99
+ export declare const takeUntil: Token$1.TakeUntilFn;
110
100
  /**
111
101
  * Recognizes an escaped string (nom's `escaped`).
112
102
  *
package/dist/Nom.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Nom.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AA,UAAA,OAAA,MAAA,OAAA,GAAA,GAAA,GAAA,OAAA,OAAA,GAAA,GAAA,GAAA;;qBAER,MAAG,GAAA,GAAA,GAAA,UAAA,OAAA,MAAA,OAAA,GAAA,GAAA,GAAA,OAAA,OAAA,GAAA,GAAA,GAAA;;qBAEH,UAAO,GAAA,OAAA,MAAA,OAAA,iBAAA;;;;;;;qBAOP,MAAI,4BAAA;;qBAEJ,MAAI;;qBAEJ,SAAO,6BAAA;;;;;;;qBAQP,UAAW,GAAG,GAAG,GAAG,UAAU,OAAO,eAAe,QAAQ,OAAO,GAAG,GAAG,GAAG,OAAK,OAAO,GAAG,GAAG,GAAG"}
package/dist/Nom.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Nom.js","names":[],"sources":["../src/Nom.ts"],"sourcesContent":["/**\n * nom-flavoured names for effect-parse's parsers and combinators.\n *\n * effect-parse's main API follows winnow's naming (in camelCase). This module\n * offers the names, and argument orders, that nom users know, so grammars\n * can be ported with minimal changes:\n *\n * | nom | effect-parse |\n * |---|---|\n * | `tag(\"abc\")` | `Token.literal(\"abc\")` |\n * | `many0(p)` | `Parser.repeat(p)` |\n * | `separated_list1(sep, p)` | `Parser.separated(p, sep, { min: 1 })` |\n * | `map_res(p, f)` | `Parser.tryMap(p, f)` |\n * | `recognize(p)` | `Parser.taken(p)` |\n * | `value(v, p)` | `Parser.as(p, v)` |\n *\n * nom's `streaming` and `complete` variants are not separate functions here.\n * Whether input is partial is decided by the runner (`Parser.parsePartial`\n * vs `Parser.parse`).\n *\n * @example\n * ```ts\n * import { Result } from \"effect\"\n * import { Nom, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * const hexPrimary = Nom.mapRes(\n * Nom.takeWhileMN(2, 2, (c: string) => /[0-9a-fA-F]/.test(c)),\n * (s) => Result.succeed(parseInt(s, 16))\n * )\n * const hexColor = Nom.preceded(\n * Nom.tag(\"#\"),\n * Nom.tuple(hexPrimary, hexPrimary, hexPrimary)\n * )\n *\n * Parser.parse(hexColor, \"#2F14DF\") // Result.succeed([47, 20, 223])\n * ```\n *\n * @since 0.1.0\n */\nimport * as Option from \"effect/Option\"\nimport * as Result from \"effect/Result\"\nimport * as Ascii from \"./Ascii.js\"\nimport * as Binary from \"./Binary.js\"\nimport type { Input, Slice, Token as TokenOf } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport * as P from \"./Parser.js\"\nimport * as Token from \"./Token.js\"\nimport type { TokenSet } from \"./Token.js\"\n\n// -----------------------------------------------------------------------------\n// bytes / character\n// -----------------------------------------------------------------------------\n\n/**\n * Matches a literal (nom's `tag`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const tag = Token.literal\n\n/**\n * Matches a literal, ignoring ASCII case (nom's `tag_no_case`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const tagNoCase = Ascii.caseless\n\n/**\n * Matches a single character (nom's `char`).\n *\n * @since 0.1.0\n * @category character\n */\nexport const char = <const C extends string>(c: C): Parser<C> => Token.literal(c)\n\n/**\n * Matches any character (nom's `anychar`).\n *\n * @since 0.1.0\n * @category character\n */\nexport const anychar: Parser<string> = Token.any\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const oneOf = Token.oneOf\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const noneOf = Token.noneOf\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const satisfy = Token.satisfy\n\n/**\n * The longest non-empty run of tokens from a set (nom's `is_a`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const isA = <I extends Input = string>(set: TokenSet<I>): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n Token.takeWhile<I>(set, { min: 1 })\n\n/**\n * The longest non-empty run of tokens *not* from a set (nom's `is_not`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const isNot = <I extends Input = string>(\n set: TokenSet<I>\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeTill<I>(set, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const take = Token.take\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhile = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeWhile<I>(predicate as any)\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhile1 = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeWhile<I>(predicate as any, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhileMN = <I extends Input = string>(\n m: number,\n n: number,\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeWhile<I>(predicate as any, { min: m, max: n })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeTill = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeTill<I>(predicate as any)\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeTill1 = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeTill<I>(predicate as any, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeUntil = Token.takeUntil\n\n/**\n * Recognizes an escaped string (nom's `escaped`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const escaped = Ascii.takeEscaped\n\n/**\n * Unescapes an escaped string (nom's `escaped_transform`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const escapedTransform = Ascii.escaped\n\n/** @since 0.1.0 @category character */\nexport const alpha0 = Ascii.alpha0\n/** @since 0.1.0 @category character */\nexport const alpha1 = Ascii.alpha1\n/** @since 0.1.0 @category character */\nexport const digit0 = Ascii.digit0\n/** @since 0.1.0 @category character */\nexport const digit1 = Ascii.digit1\n/** @since 0.1.0 @category character */\nexport const hexDigit0 = Ascii.hexDigit0\n/** @since 0.1.0 @category character */\nexport const hexDigit1 = Ascii.hexDigit1\n/** @since 0.1.0 @category character */\nexport const octDigit0 = Ascii.octDigit0\n/** @since 0.1.0 @category character */\nexport const octDigit1 = Ascii.octDigit1\n/** @since 0.1.0 @category character */\nexport const alphanumeric0 = Ascii.alphanumeric0\n/** @since 0.1.0 @category character */\nexport const alphanumeric1 = Ascii.alphanumeric1\n/** @since 0.1.0 @category character */\nexport const space0 = Ascii.space0\n/** @since 0.1.0 @category character */\nexport const space1 = Ascii.space1\n/** @since 0.1.0 @category character */\nexport const multispace0 = Ascii.multispace0\n/** @since 0.1.0 @category character */\nexport const multispace1 = Ascii.multispace1\n/** @since 0.1.0 @category character */\nexport const lineEnding = Ascii.lineEnding\n/** @since 0.1.0 @category character */\nexport const newline = Ascii.newline\n/** @since 0.1.0 @category character */\nexport const tab = Ascii.tab\n/** @since 0.1.0 @category character */\nexport const crlf = Ascii.crlf\n/**\n * nom's `not_line_ending`.\n *\n * @since 0.1.0\n * @category character\n */\nexport const notLineEnding = Ascii.tillLineEnding\n/**\n * A decimal unsigned integer (nom's `character::complete::u64` and friends).\n *\n * @since 0.1.0\n * @category character\n */\nexport const u64 = Ascii.decUint\n/**\n * A decimal signed integer (nom's `character::complete::i64` and friends).\n *\n * @since 0.1.0\n * @category character\n */\nexport const i64 = Ascii.decInt\n\n// -----------------------------------------------------------------------------\n// number\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `double` (and `float`).\n *\n * @since 0.1.0\n * @category number\n */\nexport const double = Ascii.float\n\n/**\n * nom's `recognize_float`.\n *\n * @since 0.1.0\n * @category number\n */\nexport const recognizeFloat: Parser<string> = /*#__PURE__*/ P.taken(Ascii.float)\n\n/**\n * nom's `hex_u32`.\n *\n * @since 0.1.0\n * @category number\n */\nexport const hexU32 = Ascii.hexUint\n\n/** @since 0.1.0 @category number */\nexport const beU8 = Binary.u8\n/** @since 0.1.0 @category number */\nexport const beI8 = Binary.i8\n/** @since 0.1.0 @category number */\nexport const leU8 = Binary.u8\n/** @since 0.1.0 @category number */\nexport const leI8 = Binary.i8\n/** @since 0.1.0 @category number */\nexport const beU16 = Binary.beU16\n/** @since 0.1.0 @category number */\nexport const leU16 = Binary.leU16\n/** @since 0.1.0 @category number */\nexport const beI16 = Binary.beI16\n/** @since 0.1.0 @category number */\nexport const leI16 = Binary.leI16\n/** @since 0.1.0 @category number */\nexport const beU24 = Binary.beU24\n/** @since 0.1.0 @category number */\nexport const leU24 = Binary.leU24\n/** @since 0.1.0 @category number */\nexport const beI24 = Binary.beI24\n/** @since 0.1.0 @category number */\nexport const leI24 = Binary.leI24\n/** @since 0.1.0 @category number */\nexport const beU32 = Binary.beU32\n/** @since 0.1.0 @category number */\nexport const leU32 = Binary.leU32\n/** @since 0.1.0 @category number */\nexport const beI32 = Binary.beI32\n/** @since 0.1.0 @category number */\nexport const leI32 = Binary.leI32\n/** @since 0.1.0 @category number */\nexport const beU64 = Binary.beU64\n/** @since 0.1.0 @category number */\nexport const leU64 = Binary.leU64\n/** @since 0.1.0 @category number */\nexport const beI64 = Binary.beI64\n/** @since 0.1.0 @category number */\nexport const leI64 = Binary.leI64\n/** @since 0.1.0 @category number */\nexport const beU128 = Binary.beU128\n/** @since 0.1.0 @category number */\nexport const leU128 = Binary.leU128\n/** @since 0.1.0 @category number */\nexport const beI128 = Binary.beI128\n/** @since 0.1.0 @category number */\nexport const leI128 = Binary.leI128\n/** @since 0.1.0 @category number */\nexport const beF32 = Binary.beF32\n/** @since 0.1.0 @category number */\nexport const leF32 = Binary.leF32\n/** @since 0.1.0 @category number */\nexport const beF64 = Binary.beF64\n/** @since 0.1.0 @category number */\nexport const leF64 = Binary.leF64\n\n// -----------------------------------------------------------------------------\n// multi\n// -----------------------------------------------------------------------------\n\n/**\n * Zero or more (nom's `many0`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const many0 = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<Array<A>, E, R, I> =>\n P.repeat(parser)\n\n/**\n * One or more (nom's `many1`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const many1 = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<[A, ...Array<A>], E, R, I> =>\n P.repeat(parser, { min: 1 })\n\n/**\n * Between `m` and `n` times (nom's `many_m_n`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const manyMN = <A, E, R, I extends Input>(\n m: number,\n n: number,\n parser: Parser<A, E, R, I>\n): Parser<Array<A>, E, R, I> => P.repeat(parser, { min: m, max: n })\n\n/**\n * Exactly `count` times (nom's `count`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const count = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>, count: number): Parser<Array<A>, E, R, I> =>\n P.repeat(parser, count)\n\n/**\n * Repeats `parser` until `end` succeeds (nom's `many_till`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const manyTill = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n parser: Parser<A, E, R, I>,\n end: Parser<B, E2, R2, I2>\n): Parser<[Array<A>, B], E | E2, R | R2, I & I2> => P.repeatTill(parser, end)\n\n/**\n * Zero or more `parser` separated by `separator` (nom's `separated_list0`;\n * note the separator comes first).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const separatedList0 = <S, E2, R2, I2 extends Input, A, E, R, I extends Input>(\n separator: Parser<S, E2, R2, I2>,\n parser: Parser<A, E, R, I>\n): Parser<Array<A>, E | E2, R | R2, I & I2> => P.separated(parser, separator)\n\n/**\n * One or more `parser` separated by `separator` (nom's `separated_list1`;\n * note the separator comes first).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const separatedList1 = <S, E2, R2, I2 extends Input, A, E, R, I extends Input>(\n separator: Parser<S, E2, R2, I2>,\n parser: Parser<A, E, R, I>\n): Parser<[A, ...Array<A>], E | E2, R | R2, I & I2> => P.separated(parser, separator, { min: 1 })\n\n/**\n * Folds zero or more (nom's `fold_many0`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldMany0 = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f })\n\n/**\n * Folds one or more (nom's `fold_many1`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldMany1 = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f, range: { min: 1 } })\n\n/**\n * Folds between `m` and `n` times (nom's `fold_many_m_n`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldManyMN = <A, E, R, I extends Input, B>(\n m: number,\n n: number,\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f, range: { min: m, max: n } })\n\n/**\n * nom's `length_data`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthData = Binary.lengthTake\n\n/**\n * nom's `length_value`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthValue = Binary.lengthAndThen\n\n/**\n * nom's `length_count`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthCount = Binary.lengthRepeat\n\n// -----------------------------------------------------------------------------\n// sequence / branch\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `pair`.\n *\n * @since 0.1.0\n * @category sequence\n */\nexport const pair = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n first: Parser<A, E, R, I>,\n second: Parser<B, E2, R2, I2>\n): Parser<[A, B], E | E2, R | R2, I & I2> => P.zip(first, second)\n\n/**\n * nom's tuples of parsers (`(a, b, c)`, formerly `tuple`).\n *\n * @since 0.1.0\n * @category sequence\n */\nexport const tuple = P.seq\n\n/** @since 0.1.0 @category sequence */\nexport const preceded = P.preceded\n/** @since 0.1.0 @category sequence */\nexport const terminated = P.terminated\n/** @since 0.1.0 @category sequence */\nexport const delimited = P.delimited\n/** @since 0.1.0 @category sequence */\nexport const separatedPair = P.separatedPair\n/** @since 0.1.0 @category branch */\nexport const alt = P.alt\n/** @since 0.1.0 @category branch */\nexport const permutation = P.permutation\n\n// -----------------------------------------------------------------------------\n// combinator\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `map`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const map = <A, E, R, I extends Input, B>(parser: Parser<A, E, R, I>, f: (a: A) => B): Parser<B, E, R, I> =>\n P.map(parser, f)\n\n/**\n * nom's `map_res`: the function returns a `Result`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapRes = <A, E, R, I extends Input, B, E2>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Result.Result<B, E2>\n): Parser<B, E | E2, R, I> => P.tryMap(parser, f)\n\n/**\n * nom's `map_opt`: the function returns an `Option`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapOpt = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Option.Option<B>\n): Parser<B, E, R, I> => P.filterMap(parser, f)\n\n/**\n * nom's `map_parser`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapParser = <A extends Input, E, R, I extends Input, B, E2, R2>(\n parser: Parser<A, E, R, I>,\n applied: Parser<B, E2, R2, A>\n): Parser<B, E | E2, R | R2, I> => P.mapParser(parser, applied)\n\n/**\n * nom's `flat_map`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const flatMap = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Parser<B, E2, R2, I2>\n): Parser<B, E | E2, R | R2, I & I2> => P.flatMap(parser, f)\n\n/**\n * nom's `value` (note the value comes first).\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const value = <B, A, E, R, I extends Input>(val: B, parser: Parser<A, E, R, I>): Parser<B, E, R, I> =>\n P.as(parser, val)\n\n/**\n * nom's `verify`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const verify = <A, E, R, I extends Input>(\n parser: Parser<A, E, R, I>,\n predicate: (a: A) => boolean\n): Parser<A, E, R, I> => P.filter(parser, predicate)\n\n/**\n * nom's `recognize`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const recognize = P.taken\n\n/**\n * nom's `consumed`: returns `[consumed, output]`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const consumed = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<[Slice<I>, A], E, R, I> =>\n P.map(P.withTaken(parser), ([a, s]) => [s, a])\n\n/** @since 0.1.0 @category combinator */\nexport const opt = P.opt\n/** @since 0.1.0 @category combinator */\nexport const cond = P.cond\n/** @since 0.1.0 @category combinator */\nexport const peek = P.peek\n/** @since 0.1.0 @category combinator */\nexport const not = P.not\n/** @since 0.1.0 @category combinator */\nexport const eof = P.eof\n/** @since 0.1.0 @category combinator */\nexport const allConsuming = P.allConsuming\n/** @since 0.1.0 @category combinator */\nexport const complete = P.complete\n/** @since 0.1.0 @category combinator */\nexport const cut = P.cut\n/** @since 0.1.0 @category combinator */\nexport const success = P.succeed\n/**\n * nom's `fail()`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const fail = P.reject\n/** @since 0.1.0 @category combinator */\nexport const rest = Token.rest\n/** @since 0.1.0 @category combinator */\nexport const restLen = Token.restLen\n\n/**\n * nom's `context` (note the label comes first).\n *\n * @since 0.1.0\n * @category error\n */\nexport const context = <A, E, R, I extends Input>(label: string, parser: Parser<A, E, R, I>): Parser<A, E, R, I> =>\n P.context(parser, label)\n"],"mappings":";;;;;;;;;;;;;AA2DA,MAAa,MAAM,MAAM;;;;;;;AAQzB,MAAa,YAAY,MAAM;;;;;;;AAQ/B,MAAa,QAAgC,MAAoB,MAAM,QAAQ,CAAC;;;;;;;AAQhF,MAAa,UAA0B,MAAM;;;;;AAM7C,MAAa,QAAQ,MAAM;;;;;AAM3B,MAAa,SAAS,MAAM;;;;;AAM5B,MA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B,MAAa,UACX,QACA,cACuB,EAAE,OAAO,QAAQ,SAAS;;;;;;;AAQnD,MAAa,YAAY,EAAE;;;;;;;AAQ3B,MAAa,YAAsC,WACjD,EAAE,IAAI,EAAE,UAAU,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;;AAG/C,MAAa,MAAM,EAAE;;AAErB,MAAa,OAAO,EAAE;;AAEtB,MAAa,OAAO,EAAE;;AAEtB,MAAa,MAAM,EAAE;;AAErB,MAAa,MAAM,EAAE;;AAErB,MAAa,eAAe,EAAE;;AAE9B,MAAa,WAAW,EAAE;;AAE1B,MAAa,MAAM,EAAE;;AAErB,MAAa,UAAU,EAAE;;;;;;;AAOzB,MAAa,OAAO,EAAE;;AAEtB,MAAa,OAAO,MAAM;;AAE1B,MAAa,UAAU,MAAM;;;;;;;AAQ7B,MAAa,WAAqC,OAAe,WAC/D,EAAE,QAAQ,QAAQ,KAAK"}
1
+ {"version":3,"file":"Nom.js","names":[],"sources":["../src/Nom.ts"],"sourcesContent":["/**\n * nom-flavoured names for effect-parse's parsers and combinators.\n *\n * effect-parse's main API follows winnow's naming (in camelCase). This module\n * offers the names, and argument orders, that nom users know, so grammars\n * can be ported with minimal changes:\n *\n * | nom | effect-parse |\n * |---|---|\n * | `tag(\"abc\")` | `Token.literal(\"abc\")` |\n * | `many0(p)` | `Parser.repeat(p)` |\n * | `separated_list1(sep, p)` | `Parser.separated(p, sep, { min: 1 })` |\n * | `map_res(p, f)` | `Parser.tryMap(p, f)` |\n * | `recognize(p)` | `Parser.taken(p)` |\n * | `value(v, p)` | `Parser.as(p, v)` |\n *\n * nom's `streaming` and `complete` variants are not separate functions here.\n * Whether input is partial is decided by the runner (`Parser.parsePartial`\n * vs `Parser.parse`).\n *\n * @example\n * ```ts\n * import { Result } from \"effect\"\n * import { Nom, Parser } from \"@thomasfosterau/effect-parse\"\n *\n * const hexPrimary = Nom.mapRes(\n * Nom.takeWhileMN(2, 2, (c: string) => /[0-9a-fA-F]/.test(c)),\n * (s) => Result.succeed(parseInt(s, 16))\n * )\n * const hexColor = Nom.preceded(\n * Nom.tag(\"#\"),\n * Nom.tuple(hexPrimary, hexPrimary, hexPrimary)\n * )\n *\n * Parser.parse(hexColor, \"#2F14DF\") // Result.succeed([47, 20, 223])\n * ```\n *\n * @since 0.1.0\n */\nimport * as Option from \"effect/Option\"\nimport * as Result from \"effect/Result\"\nimport * as Ascii from \"./Ascii.js\"\nimport * as Binary from \"./Binary.js\"\nimport type { Input, Slice, Token as TokenOf } from \"./Input.js\"\nimport type { Parser } from \"./Parser.js\"\nimport * as P from \"./Parser.js\"\nimport * as Token from \"./Token.js\"\nimport type { TokenSet } from \"./Token.js\"\n\n// -----------------------------------------------------------------------------\n// bytes / character\n// -----------------------------------------------------------------------------\n\n/**\n * Matches a literal (nom's `tag`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const tag = Token.literal\n\n/**\n * Matches a literal, ignoring ASCII case (nom's `tag_no_case`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const tagNoCase = Ascii.caseless\n\n/**\n * Matches a single character (nom's `char`).\n *\n * @since 0.1.0\n * @category character\n */\nexport const char = <const C extends string>(c: C): Parser<C> => Token.literal(c)\n\n/**\n * Matches any character (nom's `anychar`).\n *\n * @since 0.1.0\n * @category character\n */\nexport const anychar: Parser<string> = Token.any\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const oneOf = Token.oneOf\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const noneOf = Token.noneOf\n\n/**\n * @since 0.1.0\n * @category character\n */\nexport const satisfy = Token.satisfy\n\n/**\n * The longest non-empty run of tokens from a set (nom's `is_a`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const isA = <I extends Input = string>(set: TokenSet<I>): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n Token.takeWhile<I>(set, { min: 1 })\n\n/**\n * The longest non-empty run of tokens *not* from a set (nom's `is_not`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const isNot = <I extends Input = string>(\n set: TokenSet<I>\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> => Token.takeTill<I>(set, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const take = Token.take\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhile = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n // SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind\n Token.takeWhile<I>(predicate as Token.TokenSet<I>)\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhile1 = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n // SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind\n Token.takeWhile<I>(predicate as Token.TokenSet<I>, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeWhileMN = <I extends Input = string>(\n m: number,\n n: number,\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n // SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind\n Token.takeWhile<I>(predicate as Token.TokenSet<I>, { min: m, max: n })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeTill = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n // SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind\n Token.takeTill<I>(predicate as Token.TokenSet<I>)\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeTill1 = <I extends Input = string>(\n predicate: (token: TokenOf<I>) => boolean\n): Parser<Slice<NoInfer<I>>, never, never, NoInfer<I>> =>\n // SAFETY: a predicate over the input's tokens is a member of `TokenSet<I>` for each input kind\n Token.takeTill<I>(predicate as Token.TokenSet<I>, { min: 1 })\n\n/**\n * @since 0.1.0\n * @category bytes\n */\nexport const takeUntil = Token.takeUntil\n\n/**\n * Recognizes an escaped string (nom's `escaped`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const escaped = Ascii.takeEscaped\n\n/**\n * Unescapes an escaped string (nom's `escaped_transform`).\n *\n * @since 0.1.0\n * @category bytes\n */\nexport const escapedTransform = Ascii.escaped\n\n/** @since 0.1.0 @category character */\nexport const alpha0 = Ascii.alpha0\n/** @since 0.1.0 @category character */\nexport const alpha1 = Ascii.alpha1\n/** @since 0.1.0 @category character */\nexport const digit0 = Ascii.digit0\n/** @since 0.1.0 @category character */\nexport const digit1 = Ascii.digit1\n/** @since 0.1.0 @category character */\nexport const hexDigit0 = Ascii.hexDigit0\n/** @since 0.1.0 @category character */\nexport const hexDigit1 = Ascii.hexDigit1\n/** @since 0.1.0 @category character */\nexport const octDigit0 = Ascii.octDigit0\n/** @since 0.1.0 @category character */\nexport const octDigit1 = Ascii.octDigit1\n/** @since 0.1.0 @category character */\nexport const alphanumeric0 = Ascii.alphanumeric0\n/** @since 0.1.0 @category character */\nexport const alphanumeric1 = Ascii.alphanumeric1\n/** @since 0.1.0 @category character */\nexport const space0 = Ascii.space0\n/** @since 0.1.0 @category character */\nexport const space1 = Ascii.space1\n/** @since 0.1.0 @category character */\nexport const multispace0 = Ascii.multispace0\n/** @since 0.1.0 @category character */\nexport const multispace1 = Ascii.multispace1\n/** @since 0.1.0 @category character */\nexport const lineEnding = Ascii.lineEnding\n/** @since 0.1.0 @category character */\nexport const newline = Ascii.newline\n/** @since 0.1.0 @category character */\nexport const tab = Ascii.tab\n/** @since 0.1.0 @category character */\nexport const crlf = Ascii.crlf\n/**\n * nom's `not_line_ending`.\n *\n * @since 0.1.0\n * @category character\n */\nexport const notLineEnding = Ascii.tillLineEnding\n/**\n * A decimal unsigned integer (nom's `character::complete::u64` and friends).\n *\n * @since 0.1.0\n * @category character\n */\nexport const u64 = Ascii.decUint\n/**\n * A decimal signed integer (nom's `character::complete::i64` and friends).\n *\n * @since 0.1.0\n * @category character\n */\nexport const i64 = Ascii.decInt\n\n// -----------------------------------------------------------------------------\n// number\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `double` (and `float`).\n *\n * @since 0.1.0\n * @category number\n */\nexport const double = Ascii.float\n\n/**\n * nom's `recognize_float`.\n *\n * @since 0.1.0\n * @category number\n */\nexport const recognizeFloat: Parser<string> = /*#__PURE__*/ P.taken(Ascii.float)\n\n/**\n * nom's `hex_u32`.\n *\n * @since 0.1.0\n * @category number\n */\nexport const hexU32 = Ascii.hexUint\n\n/** @since 0.1.0 @category number */\nexport const beU8 = Binary.u8\n/** @since 0.1.0 @category number */\nexport const beI8 = Binary.i8\n/** @since 0.1.0 @category number */\nexport const leU8 = Binary.u8\n/** @since 0.1.0 @category number */\nexport const leI8 = Binary.i8\n/** @since 0.1.0 @category number */\nexport const beU16 = Binary.beU16\n/** @since 0.1.0 @category number */\nexport const leU16 = Binary.leU16\n/** @since 0.1.0 @category number */\nexport const beI16 = Binary.beI16\n/** @since 0.1.0 @category number */\nexport const leI16 = Binary.leI16\n/** @since 0.1.0 @category number */\nexport const beU24 = Binary.beU24\n/** @since 0.1.0 @category number */\nexport const leU24 = Binary.leU24\n/** @since 0.1.0 @category number */\nexport const beI24 = Binary.beI24\n/** @since 0.1.0 @category number */\nexport const leI24 = Binary.leI24\n/** @since 0.1.0 @category number */\nexport const beU32 = Binary.beU32\n/** @since 0.1.0 @category number */\nexport const leU32 = Binary.leU32\n/** @since 0.1.0 @category number */\nexport const beI32 = Binary.beI32\n/** @since 0.1.0 @category number */\nexport const leI32 = Binary.leI32\n/** @since 0.1.0 @category number */\nexport const beU64 = Binary.beU64\n/** @since 0.1.0 @category number */\nexport const leU64 = Binary.leU64\n/** @since 0.1.0 @category number */\nexport const beI64 = Binary.beI64\n/** @since 0.1.0 @category number */\nexport const leI64 = Binary.leI64\n/** @since 0.1.0 @category number */\nexport const beU128 = Binary.beU128\n/** @since 0.1.0 @category number */\nexport const leU128 = Binary.leU128\n/** @since 0.1.0 @category number */\nexport const beI128 = Binary.beI128\n/** @since 0.1.0 @category number */\nexport const leI128 = Binary.leI128\n/** @since 0.1.0 @category number */\nexport const beF32 = Binary.beF32\n/** @since 0.1.0 @category number */\nexport const leF32 = Binary.leF32\n/** @since 0.1.0 @category number */\nexport const beF64 = Binary.beF64\n/** @since 0.1.0 @category number */\nexport const leF64 = Binary.leF64\n\n// -----------------------------------------------------------------------------\n// multi\n// -----------------------------------------------------------------------------\n\n/**\n * Zero or more (nom's `many0`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const many0 = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<Array<A>, E, R, I> =>\n P.repeat(parser)\n\n/**\n * One or more (nom's `many1`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const many1 = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<[A, ...Array<A>], E, R, I> =>\n P.repeat(parser, { min: 1 })\n\n/**\n * Between `m` and `n` times (nom's `many_m_n`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const manyMN = <A, E, R, I extends Input>(\n m: number,\n n: number,\n parser: Parser<A, E, R, I>\n): Parser<Array<A>, E, R, I> => P.repeat(parser, { min: m, max: n })\n\n/**\n * Exactly `count` times (nom's `count`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const count = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>, count: number): Parser<Array<A>, E, R, I> =>\n P.repeat(parser, count)\n\n/**\n * Repeats `parser` until `end` succeeds (nom's `many_till`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const manyTill = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n parser: Parser<A, E, R, I>,\n end: Parser<B, E2, R2, I2>\n): Parser<[Array<A>, B], E | E2, R | R2, I & I2> => P.repeatTill(parser, end)\n\n/**\n * Zero or more `parser` separated by `separator` (nom's `separated_list0`;\n * note the separator comes first).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const separatedList0 = <S, E2, R2, I2 extends Input, A, E, R, I extends Input>(\n separator: Parser<S, E2, R2, I2>,\n parser: Parser<A, E, R, I>\n): Parser<Array<A>, E | E2, R | R2, I & I2> => P.separated(parser, separator)\n\n/**\n * One or more `parser` separated by `separator` (nom's `separated_list1`;\n * note the separator comes first).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const separatedList1 = <S, E2, R2, I2 extends Input, A, E, R, I extends Input>(\n separator: Parser<S, E2, R2, I2>,\n parser: Parser<A, E, R, I>\n): Parser<[A, ...Array<A>], E | E2, R | R2, I & I2> => P.separated(parser, separator, { min: 1 })\n\n/**\n * Folds zero or more (nom's `fold_many0`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldMany0 = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f })\n\n/**\n * Folds one or more (nom's `fold_many1`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldMany1 = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f, range: { min: 1 } })\n\n/**\n * Folds between `m` and `n` times (nom's `fold_many_m_n`).\n *\n * @since 0.1.0\n * @category multi\n */\nexport const foldManyMN = <A, E, R, I extends Input, B>(\n m: number,\n n: number,\n parser: Parser<A, E, R, I>,\n init: () => B,\n f: (acc: B, a: A) => B\n): Parser<B, E, R, I> => P.fold(parser, { init, f, range: { min: m, max: n } })\n\n/**\n * nom's `length_data`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthData = Binary.lengthTake\n\n/**\n * nom's `length_value`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthValue = Binary.lengthAndThen\n\n/**\n * nom's `length_count`.\n *\n * @since 0.1.0\n * @category multi\n */\nexport const lengthCount = Binary.lengthRepeat\n\n// -----------------------------------------------------------------------------\n// sequence / branch\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `pair`.\n *\n * @since 0.1.0\n * @category sequence\n */\nexport const pair = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n first: Parser<A, E, R, I>,\n second: Parser<B, E2, R2, I2>\n): Parser<[A, B], E | E2, R | R2, I & I2> => P.zip(first, second)\n\n/**\n * nom's tuples of parsers (`(a, b, c)`, formerly `tuple`).\n *\n * @since 0.1.0\n * @category sequence\n */\nexport const tuple = P.seq\n\n/** @since 0.1.0 @category sequence */\nexport const preceded = P.preceded\n/** @since 0.1.0 @category sequence */\nexport const terminated = P.terminated\n/** @since 0.1.0 @category sequence */\nexport const delimited = P.delimited\n/** @since 0.1.0 @category sequence */\nexport const separatedPair = P.separatedPair\n/** @since 0.1.0 @category branch */\nexport const alt = P.alt\n/** @since 0.1.0 @category branch */\nexport const permutation = P.permutation\n\n// -----------------------------------------------------------------------------\n// combinator\n// -----------------------------------------------------------------------------\n\n/**\n * nom's `map`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const map = <A, E, R, I extends Input, B>(parser: Parser<A, E, R, I>, f: (a: A) => B): Parser<B, E, R, I> =>\n P.map(parser, f)\n\n/**\n * nom's `map_res`: the function returns a `Result`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapRes = <A, E, R, I extends Input, B, E2>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Result.Result<B, E2>\n): Parser<B, E | E2, R, I> => P.tryMap(parser, f)\n\n/**\n * nom's `map_opt`: the function returns an `Option`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapOpt = <A, E, R, I extends Input, B>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Option.Option<B>\n): Parser<B, E, R, I> => P.filterMap(parser, f)\n\n/**\n * nom's `map_parser`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const mapParser = <A extends Input, E, R, I extends Input, B, E2, R2>(\n parser: Parser<A, E, R, I>,\n applied: Parser<B, E2, R2, A>\n): Parser<B, E | E2, R | R2, I> => P.mapParser(parser, applied)\n\n/**\n * nom's `flat_map`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const flatMap = <A, E, R, I extends Input, B, E2, R2, I2 extends Input>(\n parser: Parser<A, E, R, I>,\n f: (a: A) => Parser<B, E2, R2, I2>\n): Parser<B, E | E2, R | R2, I & I2> => P.flatMap(parser, f)\n\n/**\n * nom's `value` (note the value comes first).\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const value = <B, A, E, R, I extends Input>(val: B, parser: Parser<A, E, R, I>): Parser<B, E, R, I> =>\n P.as(parser, val)\n\n/**\n * nom's `verify`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const verify = <A, E, R, I extends Input>(\n parser: Parser<A, E, R, I>,\n predicate: (a: A) => boolean\n): Parser<A, E, R, I> => P.filter(parser, predicate)\n\n/**\n * nom's `recognize`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const recognize = P.taken\n\n/**\n * nom's `consumed`: returns `[consumed, output]`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const consumed = <A, E, R, I extends Input>(parser: Parser<A, E, R, I>): Parser<[Slice<I>, A], E, R, I> =>\n P.map(P.withTaken(parser), ([a, s]) => [s, a])\n\n/** @since 0.1.0 @category combinator */\nexport const opt = P.opt\n/** @since 0.1.0 @category combinator */\nexport const cond = P.cond\n/** @since 0.1.0 @category combinator */\nexport const peek = P.peek\n/** @since 0.1.0 @category combinator */\nexport const not = P.not\n/** @since 0.1.0 @category combinator */\nexport const eof = P.eof\n/** @since 0.1.0 @category combinator */\nexport const allConsuming = P.allConsuming\n/** @since 0.1.0 @category combinator */\nexport const complete = P.complete\n/** @since 0.1.0 @category combinator */\nexport const cut = P.cut\n/** @since 0.1.0 @category combinator */\nexport const success = P.succeed\n/**\n * nom's `fail()`.\n *\n * @since 0.1.0\n * @category combinator\n */\nexport const fail = P.reject\n/** @since 0.1.0 @category combinator */\nexport const rest = Token.rest\n/** @since 0.1.0 @category combinator */\nexport const restLen = Token.restLen\n\n/**\n * nom's `context` (note the label comes first).\n *\n * @since 0.1.0\n * @category error\n */\nexport const context = <A, E, R, I extends Input>(label: string, parser: Parser<A, E, R, I>): Parser<A, E, R, I> =>\n P.context(parser, label)\n"],"mappings":";;;;;;;;;;;;;AA2DA,MAAa,MAAM,MAAM;;;;;;;AAQzB,MAAa,YAAY,MAAM;;;;;;;AAQ/B,MAAa,QAAgC,MAAoB,MAAM,QAAQ,CAAC;;;;;;;AAQhF,MAAa,UAA0B,MAAM;;;;;AAM7C,MAAa,QAAQ,MAAM;;;;;AAM3B,MAAa,SAAS,MAAM;;;;;AAM5B,MAAa,UAAU,MAAM;;;;;;;AAQ7B,MAAa,OAAiC,QAC5C,MAAM,UAAa,KAAK,EAAE,KAAK,EAAE,CAAC;;;;;;;AAQpC,MAAa,SACX,QACwD,MAAM,SAAY,KAAK,EAAE,KAAK,EAAE,CAAC;;;;;AAM3F,MAAa,OAAO,MAAM;;;;;AAM1B,MAAa,aACX,cAGA,MAAM,UAAa,SAA8B;;;;;AAMnD,MAAa,cACX,cAGA,MAAM,UAAa,WAAgC,EAAE,KAAK,EAAE,CAAC;;;;;AAM/D,MAAa,eACX,GACA,GACA,cAGA,MAAM,UAAa,WAAgC;CAAE,KAAK;CAAG,KAAK;AAAE,CAAC;;;;;AAMvE,MAAa,YACX,cAGA,MAAM,SAAY,SAA8B;;;;;AAMlD,MAAa,aACX,cAGA,MAAM,SAAY,WAAgC,EAAE,KAAK,EAAE,CAAC;;;;;AAM9D,MAAa,YAAY,MAAM;;;;;;;AAQ/B,MAAa,UAAU,MAAM;;;;;;;AAQ7B,MAAa,mBAAmB,MAAM;;AAGtC,MAAa,SAAS,MAAM;;AAE5B,MAAa,SAAS,MAAM;;AAE5B,MAAa,SAAS,MAAM;;AAE5B,MAAa,SAAS,MAAM;;AAE5B,MAAa,YAAY,MAAM;;AAE/B,MAAa,YA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E;;AAE/B,MAAa,MAAM,EAAE;;AAErB,MAAa,cAAc,EAAE;;;;;;;AAY7B,MAAa,OAAoC,QAA4B,MAC3E,EAAE,IAAI,QAAQ,CAAC;;;;;;;AAQjB,MAAa,UACX,QACA,MAC4B,EAAE,OAAO,QAAQ,CAAC;;;;;;;AAQhD,MAAa,UACX,QACA,MACuB,EAAE,UAAU,QAAQ,CAAC;;;;;;;AAQ9C,MAAa,aACX,QACA,YACiC,EAAE,UAAU,QAAQ,OAAO;;;;;;;AAQ9D,MAAa,WACX,QACA,MACsC,EAAE,QAAQ,QAAQ,CAAC;;;;;;;AAQ3D,MAAa,SAAsC,KAAQ,WACzD,EAAE,GAAG,QAAQ,GAAG;;;;;;;AAQlB,MAAa,UACX,QACA,cACuB,EAAE,OAAO,QAAQ,SAAS;;;;;;;AAQnD,MAAa,YAAY,EAAE;;;;;;;AAQ3B,MAAa,YAAsC,WACjD,EAAE,IAAI,EAAE,UAAU,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;;AAG/C,MAAa,MAAM,EAAE;;AAErB,MAAa,OAAO,EAAE;;AAEtB,MAAa,OAAO,EAAE;;AAEtB,MAAa,MAAM,EAAE;;AAErB,MAAa,MAAM,EAAE;;AAErB,MAAa,eAAe,EAAE;;AAE9B,MAAa,WAAW,EAAE;;AAE1B,MAAa,MAAM,EAAE;;AAErB,MAAa,UAAU,EAAE;;;;;;;AAOzB,MAAa,OAAO,EAAE;;AAEtB,MAAa,OAAO,MAAM;;AAE1B,MAAa,UAAU,MAAM;;;;;;;AAQ7B,MAAa,WAAqC,OAAe,WAC/D,EAAE,QAAQ,QAAQ,KAAK"}
@@ -82,7 +82,7 @@ export declare const isParseError: (u: unknown) => u is ParseError<unknown>;
82
82
  * @since 0.1.0
83
83
  * @category constructors
84
84
  */
85
- export declare const fromFailure: <E = never>(input: Input, failure: Failure, mode: ErrMode, encoding?: Encoding<any> | undefined) => ParseError<E>;
85
+ export declare const fromFailure: <E = never>(input: Input, failure: Failure, mode: ErrMode, encoding?: Encoding<any>) => ParseError<E>;
86
86
  /**
87
87
  * The user supplied cause of an error, if any.
88
88
  *
@@ -109,7 +109,7 @@ export interface LineColumn {
109
109
  * @since 0.1.0
110
110
  * @category utils
111
111
  */
112
- export declare const lineColumn: (input: Input, offset: number, encoding?: Encoding<any> | undefined) => LineColumn;
112
+ export declare const lineColumn: (input: Input, offset: number, encoding?: Encoding<any>) => LineColumn;
113
113
  /**
114
114
  * Formats a list of expectations: `a`, `a or b`, `a, b or c`.
115
115
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ParseError.d.ts","names":[],"sources":["../src/ParseError.ts"],"mappings":";;;;;;;;;;;;;YAwCY;;;;;qBAuCC;;;;;;;;;;qBAQA,eAAe,iCACJ;;WAEX,OAAO;;WAEP;;WAEA,MAAM;;WAEN,MAAM;;WAEN,UAAU;;WAEV,SAAS;;WAET,OAAO;;WAEP;;;;;WAKA,WAAW,SAAS;;;;;YAMrB,gBAAgB;;;;;;;MAQtB,YAAY;;;;;;MASH;;;;EAOJ;;;;;;qBASE,eAAgB,eAAa,KAAK;;;;;;;qBAQlC,cAAe,WAC1B,OAAO,OACP,SAAS,SACT,MAAM,SACN,WAAW,8BACV,WAAW;;;;;;;qBAmBD,WAAY,GAAG,MAAM,WAAW,OAAK,OAAO,OAAO;;;;;;;iBAS/C;WACN;WACA;;;;;;;;;;;qBAYE,aAAc,OAAO,OAAO,gBAAgB,WAAW,8BAA4B;;;;;;;qBA6CnF,iBAAkB,UAAU;;qBA8B5B,eAAgB"}
1
+ {"version":3,"file":"ParseError.d.ts","names":[],"sources":["../src/ParseError.ts"],"mappings":";;;;;;;;;;;;;YAwCY;;;;;qBAuCC;;;;;;;;;;qBAQA,eAAe,iCACJ;;WAEX,OAAO;;WAEP;;WAEA,MAAM;;WAEN,MAAM;;WAEN,UAAU;;WAEV,SAAS;;WAET,OAAO;;WAEP;;;;;WAKA,WAAW,SAAS;;;;;YAMrB,gBAAgB;;;;;;;MAQtB,YAAY;;;;;;MASH;;;;EAOJ;;;;;;qBASE,eAAgB,eAAa,KAAK;;;;;;;qBAQlC,cAAe,WAC1B,OAAO,OACP,SAAS,SACT,MAAM,SACN,WAAW,kBACV,WAAW;;;;;;;qBAsBD,WAAY,GAAG,MAAM,WAAW,OAAK,OAAO,OAAO;;;;;;;iBAS/C;WACN;WACA;;;;;;;;;;;qBAYE,aAAc,OAAO,OAAO,gBAAgB,WAAW,kBAAgB;;;;;;;qBA6CvE,iBAAkB,UAAU;;qBA8B5B,eAAgB"}
@@ -176,7 +176,7 @@ const describeFound = (input, offset, encoding) => {
176
176
  /** @internal */
177
177
  const inspectToken = (u) => {
178
178
  if (Predicate.isString(u)) return JSON.stringify(u);
179
- if (Predicate.isObjectOrArray(u)) return Result.getOrElse(Result.try(() => JSON.stringify(u)), () => String(u));
179
+ if (Predicate.isObjectOrArray(u)) return Result.getOrElse(Result.try(() => JSON.stringify(u)), () => Array.isArray(u) ? u.join(",") : Object.prototype.toString.call(u));
180
180
  return String(u);
181
181
  };
182
182
  const causeMessage = (cause) => {