@thomasfosterau/effect-parse 0.2.0 → 0.4.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.
- package/README.md +44 -1
- package/dist/Ascii.d.ts +0 -2
- package/dist/Ascii.d.ts.map +1 -1
- package/dist/Ascii.js +6 -6
- package/dist/Ascii.js.map +1 -1
- package/dist/Binary.d.ts +0 -2
- package/dist/Binary.d.ts.map +1 -1
- package/dist/Binary.js +1 -2
- package/dist/Bits.d.ts +0 -2
- package/dist/Bits.d.ts.map +1 -1
- package/dist/Bits.js +2 -3
- package/dist/Bits.js.map +1 -1
- package/dist/Compiler.d.ts +0 -2
- package/dist/Compiler.d.ts.map +1 -1
- package/dist/Compiler.js +1 -2
- package/dist/Encoding.d.ts +0 -2
- package/dist/Encoding.d.ts.map +1 -1
- package/dist/Encoding.js +1 -2
- package/dist/Expression.d.ts +0 -2
- package/dist/Expression.d.ts.map +1 -1
- package/dist/Expression.js +61 -18
- package/dist/Expression.js.map +1 -1
- package/dist/Input.d.ts +80 -7
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +149 -18
- package/dist/Input.js.map +1 -1
- package/dist/Nom.d.ts +1 -3
- package/dist/Nom.d.ts.map +1 -1
- package/dist/Nom.js +1 -2
- package/dist/ParseError.d.ts +0 -2
- package/dist/ParseError.d.ts.map +1 -1
- package/dist/ParseError.js +6 -10
- package/dist/ParseError.js.map +1 -1
- package/dist/Parser.d.ts +2 -2
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +58 -32
- package/dist/Parser.js.map +1 -1
- package/dist/ParserSchema.d.ts +198 -2
- package/dist/ParserSchema.d.ts.map +1 -1
- package/dist/ParserSchema.js +646 -18
- package/dist/ParserSchema.js.map +1 -1
- package/dist/ParserStream.d.ts +0 -2
- package/dist/ParserStream.d.ts.map +1 -1
- package/dist/ParserStream.js +15 -9
- package/dist/ParserStream.js.map +1 -1
- package/dist/Syntax.d.ts +0 -2
- package/dist/Syntax.d.ts.map +1 -1
- package/dist/Syntax.js +13 -11
- package/dist/Syntax.js.map +1 -1
- package/dist/Text.d.ts +0 -2
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +1 -2
- package/dist/Token.d.ts +0 -2
- package/dist/Token.d.ts.map +1 -1
- package/dist/Token.js +1 -2
- package/dist/internal/compiler/closure.d.ts +5 -2
- package/dist/internal/compiler/closure.d.ts.map +1 -1
- package/dist/internal/compiler/closure.js +160 -92
- package/dist/internal/compiler/closure.js.map +1 -1
- package/dist/internal/compiler/entries.d.ts +0 -2
- package/dist/internal/compiler/entries.d.ts.map +1 -1
- package/dist/internal/compiler/entries.js +6 -7
- package/dist/internal/compiler/entries.js.map +1 -1
- package/dist/internal/compiler/first.d.ts +0 -2
- package/dist/internal/compiler/first.d.ts.map +1 -1
- package/dist/internal/compiler/first.js +10 -10
- package/dist/internal/compiler/first.js.map +1 -1
- package/dist/internal/compiler/jit.d.ts +0 -2
- package/dist/internal/compiler/jit.d.ts.map +1 -1
- package/dist/internal/compiler/jit.js +52 -51
- package/dist/internal/compiler/jit.js.map +1 -1
- package/dist/internal/compiler/registry.d.ts +0 -2
- package/dist/internal/compiler/registry.d.ts.map +1 -1
- package/dist/internal/compiler/registry.js +1 -2
- package/dist/internal/compiler/sets.d.ts +2 -2
- package/dist/internal/compiler/sets.d.ts.map +1 -1
- package/dist/internal/compiler/sets.js +8 -3
- package/dist/internal/compiler/sets.js.map +1 -1
- package/dist/internal/entries.d.ts +0 -2
- package/dist/internal/entries.d.ts.map +1 -1
- package/dist/internal/entries.js +1 -2
- package/dist/internal/key.d.ts +10 -0
- package/dist/internal/key.d.ts.map +1 -0
- package/dist/internal/key.js +11 -0
- package/dist/internal/key.js.map +1 -0
- package/dist/internal/node.d.ts +11 -4
- package/dist/internal/node.d.ts.map +1 -1
- package/dist/internal/node.js +15 -3
- package/dist/internal/node.js.map +1 -1
- package/dist/internal/numbers.d.ts +0 -2
- package/dist/internal/numbers.d.ts.map +1 -1
- package/dist/internal/numbers.js +1 -2
- package/dist/internal/resume.d.ts +5 -6
- package/dist/internal/resume.d.ts.map +1 -1
- package/dist/internal/resume.js +1 -2
- package/dist/internal/resume.js.map +1 -1
- package/dist/internal/run.d.ts +0 -2
- package/dist/internal/run.d.ts.map +1 -1
- package/dist/internal/run.js +2 -3
- package/dist/internal/run.js.map +1 -1
- package/dist/internal/stack.d.ts +0 -2
- package/dist/internal/stack.d.ts.map +1 -1
- package/dist/internal/stack.js +12 -3
- package/dist/internal/stack.js.map +1 -1
- package/dist/internal/syntax.d.ts +30 -19
- package/dist/internal/syntax.d.ts.map +1 -1
- package/dist/internal/syntax.js +74 -63
- package/dist/internal/syntax.js.map +1 -1
- package/dist/internal/text.d.ts +5 -2
- package/dist/internal/text.d.ts.map +1 -1
- package/dist/internal/text.js +14 -5
- package/dist/internal/text.js.map +1 -1
- package/dist/internal/ties.d.ts +28 -0
- package/dist/internal/ties.d.ts.map +1 -0
- package/dist/internal/ties.js +66 -0
- package/dist/internal/ties.js.map +1 -0
- package/dist/internal/tokens.d.ts +10 -9
- package/dist/internal/tokens.d.ts.map +1 -1
- package/dist/internal/tokens.js +4 -8
- package/dist/internal/tokens.js.map +1 -1
- package/package.json +6 -6
- package/src/Ascii.ts +6 -5
- package/src/Bits.ts +1 -1
- package/src/Expression.ts +27 -23
- package/src/Input.ts +157 -21
- package/src/ParseError.ts +10 -8
- package/src/Parser.ts +67 -32
- package/src/ParserSchema.ts +982 -23
- package/src/ParserStream.ts +20 -8
- package/src/Syntax.ts +12 -9
- package/src/internal/compiler/closure.ts +202 -90
- package/src/internal/compiler/entries.ts +14 -11
- package/src/internal/compiler/first.ts +9 -8
- package/src/internal/compiler/jit.ts +95 -74
- package/src/internal/compiler/sets.ts +7 -0
- package/src/internal/key.ts +11 -0
- package/src/internal/node.ts +19 -2
- package/src/internal/resume.ts +5 -4
- package/src/internal/run.ts +1 -1
- package/src/internal/stack.ts +6 -1
- package/src/internal/syntax.ts +80 -84
- package/src/internal/text.ts +24 -4
- package/src/internal/ties.ts +83 -0
- package/src/internal/tokens.ts +20 -13
package/dist/Syntax.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Syntax.js","names":[],"sources":["../src/Syntax.ts"],"sourcesContent":["/**\n * Concrete syntax trees and incremental parsing, in the spirit of\n * [Tree-sitter](https://tree-sitter.github.io).\n *\n * Mark the rules of a grammar that should appear in the tree with\n * {@link node} (and, optionally, {@link token} and {@link field}). Outside\n * this module the marks change nothing: `Parser.parse` returns the same\n * values, and compiled parsers compile them away. {@link parse} runs the\n * grammar and returns a {@link Tree}: a tree of {@link SyntaxNode}s with\n * spans, parents and siblings, to search by position (`descendantAt`) or walk\n * with a {@link TreeCursor}. Each node also carries the value its parser\n * returned.\n *\n * Like Tree-sitter, a syntax parse always produces a tree. Failures handled\n * by `Parser.resumeAfter` and `Parser.retryAfter` become `ERROR` nodes over\n * the input they skipped, and so does any input after a fatal failure.\n *\n * After an edit, {@link reparse} (or {@link replace}) parses the new input\n * reusing every node of the old tree whose input is unchanged: only the\n * nodes that enclose the edit, or looked at the edited input, are parsed\n * again, and each reused node is stepped over whole.\n *\n * @example\n * ```ts\n * import { Ascii, Parser, Syntax, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const ws = Ascii.multispace0\n * const number = Syntax.node(Ascii.decInt, \"number\")\n * const list = Syntax.node(\n * Parser.delimited(\n * Token.literal(\"[\"),\n * Parser.separated(Parser.delimited(ws, number, ws), Token.literal(\",\")),\n * Token.literal(\"]\")\n * ),\n * \"list\"\n * )\n *\n * const tree = Syntax.parse(list, \"[1, 2, 3]\")\n * String(tree.root) // \"(list (number) (number) (number))\"\n * tree.root.descendantAt(4)?.text // \"2\"\n *\n * const edited = Syntax.replace(tree, 4, 5, \"20\") // \"[1, 20, 3]\"\n * edited.root.namedChild(1)?.value // 20\n * edited.reused // 2: only \"20\" was parsed again\n * ```\n *\n * @since 0.2.0\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type * as Context from \"effect/Context\"\nimport { dual } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type { Input, Slice, Source } from \"./Input.js\"\nimport { Fail, fromSource } from \"./Input.js\"\nimport * as ParseError from \"./ParseError.js\"\nimport { nodeOf } from \"./internal/node.js\"\nimport * as Stack from \"./internal/stack.js\"\nimport type { ErrorInfo, Green, Previous, Segment } from \"./internal/syntax.js\"\nimport { absolute, errorKind, SyntaxState } from \"./internal/syntax.js\"\nimport type { Parser } from \"./Parser.js\"\nimport { described, isParser } from \"./Parser.js\"\n\n// -----------------------------------------------------------------------------\n// Grammar annotations\n// -----------------------------------------------------------------------------\n\nconst syntaxNode = (self: Parser.Any, kind: string, named: boolean): Parser.Any => {\n const step = self.step\n // Identifies the nodes this parser builds, so a reparse can reuse them\n const key = {}\n return described<unknown, unknown, unknown, Input>(\n (state) => {\n const builder = state.syntax\n return builder === undefined ? step(state) : builder.node(state, step, key, kind, named)\n },\n self.name,\n { _tag: \"Syntax\", self, kind, named }\n )\n}\n\n/**\n * Marks a parser as a rule of the syntax tree: in a {@link parse}, each\n * match becomes a named node of the given kind, spanning the input it\n * consumed, with the nodes built inside it as children and its output as\n * its `value`. Outside {@link parse}, the parser is unchanged.\n *\n * A match that consumes nothing adds no node (as in Tree-sitter, where rules\n * can't match the empty string).\n *\n * For {@link reparse} to reuse a node, its parser's output must depend only\n * on the input from where the node starts: not on services, on state kept\n * in closures, or on absolute offsets (`Parser.location`, `Parser.span`),\n * which are not updated when the node moves. Use the node's `start` and\n * `end` instead.\n *\n * @since 0.2.0\n * @category annotations\n */\nexport const node: {\n (kind: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>\n <A, E, R, I extends Input>(self: Parser<A, E, R, I>, kind: string): Parser<A, E, R, I>\n} = /*#__PURE__*/ dual(\n 2,\n <A, E, R, I extends Input>(self: Parser<A, E, R, I>, kind: string): Parser<A, E, R, I> =>\n syntaxNode(self, kind, true) as Parser<A, E, R, I>\n)\n\n/**\n * Like {@link node}, but builds an *anonymous* node, Tree-sitter's name for\n * punctuation and keywords: anonymous nodes are left out of\n * `namedChildren` and of the tree's printed form. The kind defaults to the\n * literal for a `Token.literal` of a string, and to the parser's name\n * otherwise.\n *\n * @example\n * ```ts\n * import { Syntax, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const comma = Syntax.token(Token.literal(\",\")) // kind \",\"\n * ```\n *\n * @since 0.2.0\n * @category annotations\n */\nexport const token: {\n (kind?: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>\n <A, E, R, I extends Input>(self: Parser<A, E, R, I>, kind?: string): Parser<A, E, R, I>\n} = /*#__PURE__*/ dual(\n (args) => isParser(args[0]),\n <A, E, R, I extends Input>(self: Parser<A, E, R, I>, kind?: string): Parser<A, E, R, I> =>\n syntaxNode(self, kind ?? defaultTokenKind(self), false) as Parser<A, E, R, I>\n)\n\nconst defaultTokenKind = (self: Parser.Any): string => {\n const n = nodeOf(self)\n if (n._tag === \"Literal\" && Predicate.isString(n.literal) && !n.caseless) return n.literal\n return self.name ?? \"token\"\n}\n\n/**\n * Gives the nodes built by a parser a field name in their parent, like\n * Tree-sitter's `field(name, rule)`: find them with `childByField` and\n * `childrenByField`. Outside {@link parse}, the parser is unchanged.\n *\n * @example\n * ```ts\n * import { Ascii, Parser, Syntax, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const name = Syntax.node(Ascii.alpha1, \"name\")\n * const number = Syntax.node(Ascii.decInt, \"number\")\n * const pair = Syntax.node(\n * Parser.separatedPair(Syntax.field(name, \"key\"), Token.literal(\"=\"), Syntax.field(number, \"value\")),\n * \"pair\"\n * )\n * Syntax.parse(pair, \"x=1\").root.childByField(\"value\")?.value // 1\n * ```\n *\n * @since 0.2.0\n * @category annotations\n */\nexport const field: {\n (name: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>\n <A, E, R, I extends Input>(self: Parser<A, E, R, I>, name: string): Parser<A, E, R, I>\n} = /*#__PURE__*/ dual(2, <A, E, R, I extends Input>(self: Parser<A, E, R, I>, name: string): Parser<A, E, R, I> => {\n const step = self.step\n return described<A, E, R, I>(\n (state) => {\n const builder = state.syntax\n return (builder === undefined ? step(state) : builder.field(state, step, name)) as A | typeof Fail\n },\n self.name,\n { _tag: \"Syntax\", self, kind: undefined, named: false }\n )\n})\n\n// -----------------------------------------------------------------------------\n// Trees\n// -----------------------------------------------------------------------------\n\n/**\n * The kind of the nodes that stand for input that could not be parsed.\n *\n * @since 0.2.0\n * @category models\n */\nexport const ERROR: \"ERROR\" = errorKind\n\n/**\n * An edit to an input, as Tree-sitter's `TSInputEdit`: the input\n * `[start, oldEnd)` was replaced by `[start, newEnd)`. Offsets are in the\n * input's units (UTF-16 code units for strings, bytes, elements).\n *\n * @since 0.2.0\n * @category models\n */\nexport interface Edit {\n readonly start: number\n readonly oldEnd: number\n readonly newEnd: number\n}\n\n/**\n * Options for {@link parse}.\n *\n * @since 0.2.0\n * @category models\n */\nexport interface ParseOptions {\n /**\n * The kind of the root node, when the grammar itself is not a\n * {@link node}. Defaults to `\"document\"`.\n */\n readonly kind?: string | undefined\n /**\n * For {@link reparse}: how many input units custom parsers may read past\n * the furthest position they move the cursor to or record a failure at,\n * besides one token there. Defaults to 0, which is right for the built-in\n * parsers, and for custom parsers (`Parser.make`) that only read past\n * where they stop to see that the token there doesn't match.\n *\n * A node is reused only when the input its parse looked at is unchanged.\n * Built-in parsers that read further, such as a literal that fails part\n * way or `Token.takeUntil`, record how far they read.\n */\n readonly lookahead?: number | undefined\n}\n\n/**\n * Options for {@link parse} with a parser that requires services.\n *\n * @since 0.2.0\n * @category models\n */\nexport interface ParseOptionsWithContext<R> extends ParseOptions {\n readonly context: Context.Context<R>\n}\n\ninterface Config {\n readonly kind: string\n readonly inner: Parser.Any\n readonly lookahead: number\n readonly context: Context.Context<never> | undefined\n}\n\n/**\n * The result of a {@link parse}: a syntax tree over the whole input, the\n * grammar's output, and the errors met on the way.\n *\n * @since 0.2.0\n * @category models\n */\nexport class Tree<out A, out E = never, I extends Input = string> {\n /** The root node. It always spans the whole input. */\n readonly root: SyntaxNode<I>\n private lines: Array<number> | undefined\n private errorList: ReadonlyArray<ParseError.ParseError<E>> | undefined\n\n /** @internal */\n constructor(\n /** The input the tree was parsed from. */\n readonly input: I,\n /** The grammar's output: `none` when the parse failed. */\n readonly value: Option.Option<A>,\n /** How many nodes were reused from the previous tree by {@link reparse}. */\n readonly reused: number,\n /** @internal */\n readonly green: Green,\n /** @internal */\n readonly config: Config,\n /** @internal */\n readonly encoding: ParseError.ParseError<never>[\"encoding\"]\n ) {\n this.root = new SyntaxNode(this, green, 0, undefined, 0)\n }\n\n /**\n * Every error of the parse, in input order: the failures recovered by\n * `Parser.resumeAfter` and `Parser.retryAfter`, then the fatal one, if\n * the parse failed. Each one belongs to an `ERROR` node.\n */\n get errors(): ReadonlyArray<ParseError.ParseError<E>> {\n if (this.errorList === undefined) {\n const out: Array<ParseError.ParseError<E>> = []\n const visit = (green: Green, start: number) => {\n if (!green.hasError) return\n if (green.error !== undefined) out.push(this.toError(green.error, start))\n for (let i = 0; i < green.children.length; i++) visit(green.children[i], start + green.offsets[i])\n }\n visit(this.green, 0)\n this.errorList = out\n }\n return this.errorList\n }\n\n /** Whether the tree has any `ERROR` node. */\n get hasErrors(): boolean {\n return this.green.hasError\n }\n\n /** The smallest node containing `[start, end)` (see {@link SyntaxNode.descendantAt}). */\n descendantAt(start: number, end?: number): SyntaxNode<I> {\n return this.root.descendantAt(start, end)\n }\n\n /** A cursor at the root. */\n walk(): TreeCursor<I> {\n return new TreeCursor(this.root)\n }\n\n /**\n * The 1-based line and column (in code points) of an offset, as in\n * `ParseError`. Lines of a string input are indexed once, so lookups take\n * logarithmic time.\n */\n lineColumn(offset: number): ParseError.LineColumn {\n const input = this.input\n if (!Predicate.isString(input)) return ParseError.lineColumn(input, offset, this.encoding)\n let lines = this.lines\n if (lines === undefined) {\n lines = [0]\n for (let i = input.indexOf(\"\\n\"); i >= 0; i = input.indexOf(\"\\n\", i + 1)) lines.push(i + 1)\n this.lines = lines\n }\n const at = Math.max(0, Math.min(offset, input.length))\n let lo = 0\n let hi = lines.length - 1\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1\n if (lines[mid] <= at) lo = mid\n else hi = mid - 1\n }\n const lineStart = lines[lo]\n return { line: lo + 1, column: ParseError.lineColumn(input.slice(lineStart, at), at - lineStart).column }\n }\n\n /** The root's S-expression (see {@link SyntaxNode.toString}). */\n toString(): string {\n return this.root.toString()\n }\n\n /** @internal */\n toError(error: ErrorInfo, start: number): ParseError.ParseError<E> {\n return ParseError.fromFailure<E>(this.input, absolute(error.failure, start), error.mode, this.encoding)\n }\n}\n\n/**\n * A node of a syntax tree: its kind, span and value, and its place in the\n * tree. Nodes are views built on demand; two views of the same node are\n * different objects but have the same `start`, `end` and `kind`.\n *\n * @since 0.2.0\n * @category models\n */\nexport class SyntaxNode<I extends Input = string> {\n private childList: ReadonlyArray<SyntaxNode<I>> | undefined\n\n /** @internal */\n constructor(\n /** The tree this node belongs to. */\n readonly tree: Tree<unknown, unknown, I>,\n /** @internal */\n readonly green: Green,\n /** The offset where the node starts. */\n readonly start: number,\n /** The parent node; `undefined` for the root. */\n readonly parent: SyntaxNode<I> | undefined,\n /** The node's index among its parent's children. */\n readonly index: number\n ) {}\n\n /** The node's kind: the name given to {@link node} or {@link token}, or `\"ERROR\"`. */\n get kind(): string {\n return this.green.kind\n }\n\n /** `false` for the anonymous nodes built by {@link token}. */\n get named(): boolean {\n return this.green.named\n }\n\n /** The field name given by {@link field}, if any. */\n get field(): string | undefined {\n return this.parent?.green.fields?.[this.index]\n }\n\n /** The offset where the node ends (exclusive). */\n get end(): number {\n return this.start + this.green.width\n }\n\n /** The number of input units the node spans. */\n get length(): number {\n return this.green.width\n }\n\n /** The output of the node's parser (`undefined` for `ERROR` nodes, and for a root that failed). */\n get value(): unknown {\n return this.green.value\n }\n\n /** The input the node spans. */\n get text(): Slice<I> {\n const input = this.tree.input as any\n return input instanceof Uint8Array\n ? (input.subarray(this.start, this.end) as any)\n : input.slice(this.start, this.end)\n }\n\n /** Whether this is an `ERROR` node. */\n get isError(): boolean {\n return this.green.error !== undefined\n }\n\n /** Whether this node or a descendant is an `ERROR` node. */\n get hasError(): boolean {\n return this.green.hasError\n }\n\n /** For an `ERROR` node, the error it stands for. */\n get error(): ParseError.ParseError<unknown> | undefined {\n const error = this.green.error\n return error === undefined ? undefined : this.tree.toError(error, this.start)\n }\n\n /** The child nodes, named and anonymous, in input order. */\n get children(): ReadonlyArray<SyntaxNode<I>> {\n if (this.childList === undefined) {\n const green = this.green\n const out = new Array<SyntaxNode<I>>(green.children.length)\n for (let i = 0; i < out.length; i++) out[i] = this.makeChild(i)\n this.childList = out\n }\n return this.childList\n }\n\n /** The number of children. */\n get childCount(): number {\n return this.green.children.length\n }\n\n /** The child at `index` (negative indices count from the end). */\n child(index: number): SyntaxNode<I> | undefined {\n const n = this.green.children.length\n const i = index < 0 ? n + index : index\n return i >= 0 && i < n ? this.children[i] : undefined\n }\n\n /** The named children. */\n get namedChildren(): ReadonlyArray<SyntaxNode<I>> {\n return this.children.filter((c) => c.named)\n }\n\n /** The named child at `index`. */\n namedChild(index: number): SyntaxNode<I> | undefined {\n return this.namedChildren[index]\n }\n\n /** The first child with the given field name. */\n childByField(name: string): SyntaxNode<I> | undefined {\n const fields = this.green.fields\n if (fields === undefined) return undefined\n const i = fields.indexOf(name)\n return i < 0 ? undefined : this.children[i]\n }\n\n /** The children with the given field name. */\n childrenByField(name: string): ReadonlyArray<SyntaxNode<I>> {\n const fields = this.green.fields\n if (fields === undefined) return []\n return this.children.filter((_, i) => fields[i] === name)\n }\n\n /** The next sibling, named or anonymous. */\n get nextSibling(): SyntaxNode<I> | undefined {\n return this.parent?.children[this.index + 1]\n }\n\n /** The previous sibling, named or anonymous. */\n get previousSibling(): SyntaxNode<I> | undefined {\n return this.index > 0 ? this.parent?.children[this.index - 1] : undefined\n }\n\n /** The next named sibling. */\n get nextNamedSibling(): SyntaxNode<I> | undefined {\n const siblings = this.parent?.children\n if (siblings === undefined) return undefined\n for (let i = this.index + 1; i < siblings.length; i++) if (siblings[i].named) return siblings[i]\n return undefined\n }\n\n /** The previous named sibling. */\n get previousNamedSibling(): SyntaxNode<I> | undefined {\n const siblings = this.parent?.children\n if (siblings === undefined) return undefined\n for (let i = this.index - 1; i >= 0; i--) if (siblings[i].named) return siblings[i]\n return undefined\n }\n\n /**\n * The index of the child containing the input unit at `offset`, or -1.\n * Takes logarithmic time.\n */\n childIndexAt(offset: number): number {\n const green = this.green\n const offsets = green.offsets\n const rel = offset - this.start\n let lo = 0\n let hi = offsets.length - 1\n let found = -1\n while (lo <= hi) {\n const mid = (lo + hi) >> 1\n if (offsets[mid] <= rel) {\n found = mid\n lo = mid + 1\n } else {\n hi = mid - 1\n }\n }\n // Skip back over empty `ERROR` nodes at `offset`\n while (found >= 0 && green.children[found].width === 0 && offsets[found] === rel) found--\n return found >= 0 && rel < offsets[found] + green.children[found].width ? found : -1\n }\n\n /** The child containing the input unit at `offset`. */\n childAt(offset: number): SyntaxNode<I> | undefined {\n const i = this.childIndexAt(offset)\n return i < 0 ? undefined : this.children[i]\n }\n\n /**\n * The smallest node, this one or a descendant, that contains\n * `[start, end)` (Tree-sitter's `descendant_for_byte_range`). With only\n * `start`, the deepest node containing the input unit at `start`. Takes\n * time proportional to the depth of the tree times the logarithm of the\n * number of children.\n */\n descendantAt(start: number, end: number = start + 1): SyntaxNode<I> {\n return descendantOf(this, start, end)\n }\n\n /** Like {@link descendantAt}, but only stops at named nodes. */\n namedDescendantAt(start: number, end: number = start + 1): SyntaxNode<I> {\n let node: SyntaxNode<I> = this.descendantAt(start, end)\n // Every node below `this` has a parent, so the walk stops at `this` at the latest\n while (!node.named && node !== this) node = node.parent ?? this\n return node\n }\n\n /** This node and its descendants, in pre-order. */\n *descendants(): Generator<SyntaxNode<I>, void, undefined> {\n const cursor = this.walk()\n while (true) {\n yield cursor.node\n if (cursor.gotoFirstChild()) continue\n while (!cursor.gotoNextSibling()) {\n if (!cursor.gotoParent()) return\n }\n }\n }\n\n /** The descendants of the given kind, in pre-order. */\n *descendantsOfKind(kind: string): Generator<SyntaxNode<I>, void, undefined> {\n for (const n of this.descendants()) if (n.kind === kind) yield n\n }\n\n /** A cursor at this node, which cannot move above it. */\n walk(): TreeCursor<I> {\n return new TreeCursor(this)\n }\n\n /**\n * The node as an S-expression of its named descendants, with field\n * names, as Tree-sitter prints it: `(pair key: (name) value: (number))`.\n */\n toString(): string {\n let out = \"\"\n const visit = (green: Green, field: string | undefined) => {\n if (green.named || green === this.green) {\n if (out.length > 0) out += \" \"\n if (field !== undefined) out += `${field}: `\n out += `(${green.kind}`\n for (let i = 0; i < green.children.length; i++) visit(green.children[i], green.fields?.[i])\n out += \")\"\n } else {\n for (let i = 0; i < green.children.length; i++) visit(green.children[i], green.fields?.[i])\n }\n }\n visit(this.green, this.field)\n return out\n }\n\n toJSON(): unknown {\n return { kind: this.kind, start: this.start, end: this.end }\n }\n\n private makeChild(i: number): SyntaxNode<I> {\n const green = this.green\n return new SyntaxNode(this.tree, green.children[i], this.start + green.offsets[i], this, i)\n }\n}\n\n/** The smallest node, `root` or a descendant, that contains `[start, end)` (see `SyntaxNode.descendantAt`). */\nconst descendantOf = <I extends Input>(root: SyntaxNode<I>, start: number, end: number): SyntaxNode<I> => {\n let node = root\n while (true) {\n const i = node.childIndexAt(start)\n if (i < 0) return node\n const child = node.children[i]\n if (end > child.end) return node\n node = child\n }\n}\n\n/**\n * A cursor for walking a tree, as Tree-sitter's `TreeCursor`. It starts at\n * a node and cannot move above it.\n *\n * @since 0.2.0\n * @category models\n */\nexport class TreeCursor<I extends Input = string> {\n private current: SyntaxNode<I>\n private depth = 0\n\n /** @internal */\n constructor(node: SyntaxNode<I>) {\n this.current = node\n }\n\n /** The node at the cursor. */\n get node(): SyntaxNode<I> {\n return this.current\n }\n\n /** The field name of the node at the cursor, if any. */\n get field(): string | undefined {\n return this.depth === 0 ? undefined : this.current.field\n }\n\n /** Moves to the first child; `false` if there is none. */\n gotoFirstChild(): boolean {\n return this.goto(this.current.child(0))\n }\n\n /** Moves to the last child; `false` if there is none. */\n gotoLastChild(): boolean {\n return this.goto(this.current.child(-1))\n }\n\n /** Moves to the child containing the input unit at `offset`; `false` if there is none. */\n gotoFirstChildForOffset(offset: number): boolean {\n return this.goto(this.current.childAt(offset))\n }\n\n /** Moves to the next sibling; `false` if there is none. */\n gotoNextSibling(): boolean {\n if (this.depth === 0) return false\n const next = this.current.nextSibling\n if (next === undefined) return false\n this.current = next\n return true\n }\n\n /** Moves to the previous sibling; `false` if there is none. */\n gotoPreviousSibling(): boolean {\n if (this.depth === 0) return false\n const previous = this.current.previousSibling\n if (previous === undefined) return false\n this.current = previous\n return true\n }\n\n /** Moves to the parent; `false` at the node the cursor started at. */\n gotoParent(): boolean {\n const parent = this.current.parent\n if (this.depth === 0 || parent === undefined) return false\n this.current = parent\n this.depth--\n return true\n }\n\n /** Moves to the deepest node containing the input unit at `offset`. */\n gotoDescendantAt(offset: number): void {\n while (this.gotoFirstChildForOffset(offset)) {\n // descend\n }\n }\n\n /** Starts again at `node`. */\n reset(node: SyntaxNode<I>): void {\n this.current = node\n this.depth = 0\n }\n\n private goto(node: SyntaxNode<I> | undefined): boolean {\n if (node === undefined) return false\n this.current = node\n this.depth++\n return true\n }\n}\n\n// -----------------------------------------------------------------------------\n// Parsing\n// -----------------------------------------------------------------------------\n\nconst expectedEof = [\"end of input\"]\n\nconst run = <A, E, I extends Input>(config: Config, input: I, previous: Previous | undefined): Tree<A, E, I> => {\n const state = new SyntaxState<I>(input, { context: config.context }, previous)\n const a = Stack.run(config.inner.step, state)\n // Text parsers record the encoding when they fail, which they may have done inside reused nodes\n if (state.encoding === undefined && previous !== undefined) state.encoding = previous.encoding\n let fatal: ErrorInfo | undefined\n let value: Option.Option<A> = Option.none()\n if (a === Fail) {\n fatal = { failure: state.reportedFailure(), mode: state.mode }\n } else if (state.pos < state.end) {\n state.backtrack(\"Eof\", expectedEof)\n fatal = { failure: state.reportedFailure(), mode: \"Backtrack\" }\n } else {\n value = Option.some(a as A)\n }\n const green = state.finish(config.kind, Option.getOrUndefined(value), fatal, state.pos)\n return new Tree<A, E, I>(input, value, state.reused, green, config, state.encoding)\n}\n\n/**\n * Parses an input into a syntax {@link Tree}. The grammar's output is the\n * tree's `value`, and its {@link node}s are the tree's nodes. When the\n * grammar is itself a {@link node}, that node is the root; otherwise the\n * root is a node of kind `options.kind` (by default `\"document\"`).\n *\n * The parse never fails: recovered failures (see `Parser.resumeAfter`), a\n * fatal failure and unparsed input at the end all become `ERROR` nodes, and\n * are listed in `tree.errors`. The parse is interpreted, never compiled.\n *\n * @since 0.2.0\n * @category parsing\n */\nexport const parse: {\n <A, E, I extends Input>(\n grammar: Parser<A, E, never, I>,\n input: NoInfer<Source<I>>,\n options?: ParseOptions\n ): Tree<A, E, I>\n <A, E, R, I extends Input>(\n grammar: Parser<A, E, R, I>,\n input: NoInfer<Source<I>>,\n options: ParseOptionsWithContext<R>\n ): Tree<A, E, I>\n} = <A, E, R, I extends Input>(\n grammar: Parser<A, E, R, I>,\n input: I | Source<I>,\n options?: ParseOptions & { readonly context?: Context.Context<R> }\n): Tree<A, E, I> => {\n const n = nodeOf(grammar)\n const isRoot = n._tag === \"Syntax\" && n.kind !== undefined && n.named\n const config: Config = {\n kind: isRoot ? n.kind : (options?.kind ?? \"document\"),\n inner: isRoot ? (n.self as Parser.Any) : grammar,\n lookahead: options?.lookahead ?? 0,\n context: options?.context as Context.Context<never> | undefined\n }\n return run(config, fromSource(input as Input) as I, undefined)\n}\n\n/**\n * Parses the new version of a tree's input, reusing the nodes of the tree\n * that the edits leave unchanged (Tree-sitter's `ts_tree_edit` followed by\n * `ts_parser_parse` with the old tree). The result is the tree a fresh\n * {@link parse} of `input` would build, but only the parts of the tree\n * around the edits are parsed again. `tree.reused` says how many nodes were\n * reused.\n *\n * `edits` describe how the old input became the new one, applied in order,\n * each in the coordinates of the input as the previous edits left it. When\n * they are omitted, the edit is found by comparing the inputs (their common\n * prefix and suffix), which takes time linear in their length but much less\n * than parsing.\n *\n * Errors in the new tree are those a fresh parse reports, except that an\n * error just after a reused node may list fewer expected alternatives.\n *\n * @example\n * ```ts\n * import { Ascii, Syntax } from \"@thomasfosterau/effect-parse\"\n *\n * const number = Syntax.node(Ascii.decInt, \"number\")\n * const tree = Syntax.parse(number, \"12\")\n * Syntax.reparse(tree, \"123\", [{ start: 2, oldEnd: 2, newEnd: 3 }]).root.value // 123\n * ```\n *\n * @since 0.2.0\n * @category parsing\n */\nexport const reparse = <A, E, I extends Input>(\n tree: Tree<A, E, I>,\n input: NoInfer<Source<I>>,\n edits?: Edit | ReadonlyArray<Edit>\n): Tree<A, E, I> => {\n const next = fromSource(input as Input) as I\n const list =\n edits === undefined\n ? diffList(tree.input, next)\n : \"start\" in edits\n ? [edits as Edit]\n : (edits as ReadonlyArray<Edit>)\n const previous: Previous = {\n root: tree.green,\n oldLength: tree.input.length,\n newLength: next.length,\n segments: segmentsOf(tree.input.length, next.length, list),\n input: tree.input,\n extra: tree.config.lookahead,\n encoding: tree.encoding\n }\n return run(tree.config, next, previous)\n}\n\n/**\n * Replaces `[start, end)` of a tree's string input with `text` and parses\n * the result incrementally (see {@link reparse}).\n *\n * @since 0.2.0\n * @category parsing\n */\nexport const replace = <A, E>(\n tree: Tree<A, E, string>,\n start: number,\n end: number,\n text: string\n): Tree<A, E, string> => {\n const input = tree.input\n if (start < 0 || end < start || end > input.length) {\n throw new RangeError(`invalid range [${start}, ${end}) of an input of length ${input.length}`)\n }\n return reparse(tree, input.slice(0, start) + text + input.slice(end), {\n start,\n oldEnd: end,\n newEnd: start + text.length\n })\n}\n\n/**\n * Finds the edit that turns `before` into `after`: the part between their\n * longest common prefix and suffix. `undefined` when they are equal.\n *\n * @since 0.2.0\n * @category parsing\n */\nexport const diff = <I extends Input>(before: I, after: I): Edit | undefined => {\n const a = before as any\n const b = after as any\n const at = Predicate.isString(a) ? (s: string, i: number) => s.charCodeAt(i) : (s: any, i: number) => s[i]\n const max = Math.min(a.length, b.length)\n let prefix = 0\n while (prefix < max && at(a, prefix) === at(b, prefix)) prefix++\n if (prefix === a.length && prefix === b.length) return undefined\n let suffix = 0\n while (suffix < max - prefix && at(a, a.length - 1 - suffix) === at(b, b.length - 1 - suffix)) suffix++\n return { start: prefix, oldEnd: a.length - suffix, newEnd: b.length - suffix }\n}\n\nconst diffList = (before: Input, after: Input): ReadonlyArray<Edit> => {\n const edit = diff(before, after)\n return edit === undefined ? [] : [edit]\n}\n\n/** The stretches of the new input copied unchanged from the old one. */\nconst segmentsOf = (oldLength: number, newLength: number, edits: ReadonlyArray<Edit>): Array<Segment> => {\n let segments: Array<Segment> = oldLength > 0 ? [{ newStart: 0, oldStart: 0, length: oldLength }] : []\n let length = oldLength\n for (const { newEnd, oldEnd, start } of edits) {\n if (!(start >= 0 && oldEnd >= start && oldEnd <= length && newEnd >= start)) {\n throw new RangeError(\n `invalid edit { start: ${start}, oldEnd: ${oldEnd}, newEnd: ${newEnd} } of an input of length ${length}`\n )\n }\n const delta = newEnd - oldEnd\n const out: Array<Segment> = []\n for (const s of segments) {\n const end = s.newStart + s.length\n if (s.newStart < start) {\n out.push({ newStart: s.newStart, oldStart: s.oldStart, length: Math.min(end, start) - s.newStart })\n }\n if (end > oldEnd) {\n const from = Math.max(s.newStart, oldEnd)\n out.push({ newStart: from + delta, oldStart: s.oldStart + (from - s.newStart), length: end - from })\n }\n }\n segments = out\n length += delta\n }\n if (length !== newLength) {\n throw new RangeError(`the edits give an input of length ${length}, but the new input has length ${newLength}`)\n }\n return segments\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAM,cAAc,MAAkB,MAAc,UAA+B;CACjF,MAAM,OAAO,KAAK;CAElB,MAA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rete syntax trees and incremental parsing, in the spirit of\n * [Tree-sitter](https://tree-sitter.github.io).\n *\n * Mark the rules of a grammar that should appear in the tree with\n * {@link node} (and, optionally, {@link token} and {@link field}). Outside\n * this module the marks change nothing: `Parser.parse` returns the same\n * values, and compiled parsers compile them away. {@link parse} runs the\n * grammar and returns a {@link Tree}: a tree of {@link SyntaxNode}s with\n * spans, parents and siblings, to search by position (`descendantAt`) or walk\n * with a {@link TreeCursor}. Each node also carries the value its parser\n * returned.\n *\n * Like Tree-sitter, a syntax parse always produces a tree. Failures handled\n * by `Parser.resumeAfter` and `Parser.retryAfter` become `ERROR` nodes over\n * the input they skipped, and so does any input after a fatal failure.\n *\n * After an edit, {@link reparse} (or {@link replace}) parses the new input\n * reusing every node of the old tree whose input is unchanged: only the\n * nodes that enclose the edit, or looked at the edited input, are parsed\n * again, and each reused node is stepped over whole.\n *\n * @example\n * ```ts\n * import { Ascii, Parser, Syntax, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const ws = Ascii.multispace0\n * const number = Syntax.node(Ascii.decInt, \"number\")\n * const list = Syntax.node(\n * Parser.delimited(\n * Token.literal(\"[\"),\n * Parser.separated(Parser.delimited(ws, number, ws), Token.literal(\",\")),\n * Token.literal(\"]\")\n * ),\n * \"list\"\n * )\n *\n * const tree = Syntax.parse(list, \"[1, 2, 3]\")\n * String(tree.root) // \"(list (number) (number) (number))\"\n * tree.root.descendantAt(4)?.text // \"2\"\n *\n * const edited = Syntax.replace(tree, 4, 5, \"20\") // \"[1, 20, 3]\"\n * edited.root.namedChild(1)?.value // 20\n * edited.reused // 2: only \"20\" was parsed again\n * ```\n *\n * @since 0.2.0\n */\nimport * as Str from \"effect/String\"\nimport * as Predicate from \"effect/Predicate\"\nimport type * as Context from \"effect/Context\"\nimport { dual } from \"effect/Function\"\nimport * as Option from \"effect/Option\"\nimport type { Input, Slice, Source } from \"./Input.js\"\nimport { Fail, fromSource, State } from \"./Input.js\"\nimport * as ParseError from \"./ParseError.js\"\nimport { nodeOf } from \"./internal/node.js\"\nimport { Key } from \"./internal/key.js\"\nimport * as Stack from \"./internal/stack.js\"\nimport type { ErrorInfo, Green, Previous, Segment } from \"./internal/syntax.js\"\nimport { absolute, errorKind, SyntaxBuilder } from \"./internal/syntax.js\"\nimport type { Parser } from \"./Parser.js\"\nimport { described, isParser } from \"./Parser.js\"\n\n// -----------------------------------------------------------------------------\n// Grammar annotations\n// -----------------------------------------------------------------------------\n\nconst syntaxNode = (self: Parser.Any, kind: string, named: boolean): Parser.Any => {\n const step = self.step\n // Identifies the nodes this parser builds, so a reparse can reuse them\n const key = new Key()\n return described<unknown, unknown, unknown, Input>(\n (state) => {\n const builder = state.syntax\n return builder === undefined ? step(state) : builder.node(state, step, key, kind, named)\n },\n self.name,\n { _tag: \"Syntax\", self, kind, named }\n )\n}\n\n/**\n * Marks a parser as a rule of the syntax tree: in a {@link parse}, each\n * match becomes a named node of the given kind, spanning the input it\n * consumed, with the nodes built inside it as children and its output as\n * its `value`. Outside {@link parse}, the parser is unchanged.\n *\n * A match that consumes nothing adds no node (as in Tree-sitter, where rules\n * can't match the empty string).\n *\n * For {@link reparse} to reuse a node, its parser's output must depend only\n * on the input from where the node starts: not on services, on state kept\n * in closures, or on absolute offsets (`Parser.location`, `Parser.span`),\n * which are not updated when the node moves. Use the node's `start` and\n * `end` instead.\n *\n * @since 0.2.0\n * @category annotations\n */\nexport const node: {\n (kind: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>\n <A, E, R, I extends Input>(self: Parser<A, E, R, I>, kind: string): Parser<A, E, R, I>\n} = /*#__PURE__*/ dual(\n 2,\n <A, E, R, I extends Input>(self: Parser<A, E, R, I>, kind: string): Parser<A, E, R, I> =>\n syntaxNode(self, kind, true) as Parser<A, E, R, I>\n)\n\n/**\n * Like {@link node}, but builds an *anonymous* node, Tree-sitter's name for\n * punctuation and keywords: anonymous nodes are left out of\n * `namedChildren` and of the tree's printed form. The kind defaults to the\n * literal for a `Token.literal` of a string, and to the parser's name\n * otherwise.\n *\n * @example\n * ```ts\n * import { Syntax, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const comma = Syntax.token(Token.literal(\",\")) // kind \",\"\n * ```\n *\n * @since 0.2.0\n * @category annotations\n */\nexport const token: {\n (kind?: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>\n <A, E, R, I extends Input>(self: Parser<A, E, R, I>, kind?: string): Parser<A, E, R, I>\n} = /*#__PURE__*/ dual(\n (args) => isParser(args[0]),\n <A, E, R, I extends Input>(self: Parser<A, E, R, I>, kind?: string): Parser<A, E, R, I> =>\n syntaxNode(self, kind ?? defaultTokenKind(self), false) as Parser<A, E, R, I>\n)\n\nconst defaultTokenKind = (self: Parser.Any): string => {\n const n = nodeOf(self)\n if (Predicate.isTagged(n, \"Literal\") && Predicate.isString(n.literal) && !n.caseless) return n.literal\n return self.name ?? \"token\"\n}\n\n/**\n * Gives the nodes built by a parser a field name in their parent, like\n * Tree-sitter's `field(name, rule)`: find them with `childByField` and\n * `childrenByField`. Outside {@link parse}, the parser is unchanged.\n *\n * @example\n * ```ts\n * import { Ascii, Parser, Syntax, Token } from \"@thomasfosterau/effect-parse\"\n *\n * const name = Syntax.node(Ascii.alpha1, \"name\")\n * const number = Syntax.node(Ascii.decInt, \"number\")\n * const pair = Syntax.node(\n * Parser.separatedPair(Syntax.field(name, \"key\"), Token.literal(\"=\"), Syntax.field(number, \"value\")),\n * \"pair\"\n * )\n * Syntax.parse(pair, \"x=1\").root.childByField(\"value\")?.value // 1\n * ```\n *\n * @since 0.2.0\n * @category annotations\n */\nexport const field: {\n (name: string): <A, E, R, I extends Input>(self: Parser<A, E, R, I>) => Parser<A, E, R, I>\n <A, E, R, I extends Input>(self: Parser<A, E, R, I>, name: string): Parser<A, E, R, I>\n} = /*#__PURE__*/ dual(2, <A, E, R, I extends Input>(self: Parser<A, E, R, I>, name: string): Parser<A, E, R, I> => {\n const step = self.step\n return described<A, E, R, I>(\n (state) => {\n const builder = state.syntax\n return (builder === undefined ? step(state) : builder.field(state, step, name)) as A | typeof Fail\n },\n self.name,\n { _tag: \"Syntax\", self, kind: undefined, named: false }\n )\n})\n\n// -----------------------------------------------------------------------------\n// Trees\n// -----------------------------------------------------------------------------\n\n/**\n * The kind of the nodes that stand for input that could not be parsed.\n *\n * @since 0.2.0\n * @category models\n */\nexport const ERROR: \"ERROR\" = errorKind\n\n/**\n * An edit to an input, as Tree-sitter's `TSInputEdit`: the input\n * `[start, oldEnd)` was replaced by `[start, newEnd)`. Offsets are in the\n * input's units (UTF-16 code units for strings, bytes, elements).\n *\n * @since 0.2.0\n * @category models\n */\nexport interface Edit {\n readonly start: number\n readonly oldEnd: number\n readonly newEnd: number\n}\n\n/**\n * Options for {@link parse}.\n *\n * @since 0.2.0\n * @category models\n */\nexport interface ParseOptions {\n /**\n * The kind of the root node, when the grammar itself is not a\n * {@link node}. Defaults to `\"document\"`.\n */\n readonly kind?: string | undefined\n /**\n * For {@link reparse}: how many input units custom parsers may read past\n * the furthest position they move the cursor to or record a failure at,\n * besides one token there. Defaults to 0, which is right for the built-in\n * parsers, and for custom parsers (`Parser.make`) that only read past\n * where they stop to see that the token there doesn't match.\n *\n * A node is reused only when the input its parse looked at is unchanged.\n * Built-in parsers that read further, such as a literal that fails part\n * way or `Token.takeUntil`, record how far they read.\n */\n readonly lookahead?: number | undefined\n}\n\n/**\n * Options for {@link parse} with a parser that requires services.\n *\n * @since 0.2.0\n * @category models\n */\nexport interface ParseOptionsWithContext<R> extends ParseOptions {\n readonly context: Context.Context<R>\n}\n\ninterface Config {\n readonly kind: string\n readonly inner: Parser.Any\n readonly lookahead: number\n readonly context: Context.Context<never> | undefined\n}\n\n/**\n * The result of a {@link parse}: a syntax tree over the whole input, the\n * grammar's output, and the errors met on the way.\n *\n * @since 0.2.0\n * @category models\n */\nexport class Tree<out A, out E = never, I extends Input = string> {\n /** The root node. It always spans the whole input. */\n readonly root: SyntaxNode<I>\n private lines: Array<number> | undefined\n private errorList: ReadonlyArray<ParseError.ParseError<E>> | undefined\n\n /** @internal */\n constructor(\n /** The input the tree was parsed from. */\n readonly input: I,\n /** The grammar's output: `none` when the parse failed. */\n readonly value: Option.Option<A>,\n /** How many nodes were reused from the previous tree by {@link reparse}. */\n readonly reused: number,\n /** @internal */\n readonly green: Green,\n /** @internal */\n readonly config: Config,\n /** @internal */\n readonly encoding: ParseError.ParseError<never>[\"encoding\"]\n ) {\n this.root = new SyntaxNode(this, green, 0, undefined, 0)\n }\n\n /**\n * Every error of the parse, in input order: the failures recovered by\n * `Parser.resumeAfter` and `Parser.retryAfter`, then the fatal one, if\n * the parse failed. Each one belongs to an `ERROR` node.\n */\n get errors(): ReadonlyArray<ParseError.ParseError<E>> {\n if (this.errorList === undefined) {\n const out: Array<ParseError.ParseError<E>> = []\n const visit = (green: Green, start: number) => {\n if (!green.hasError) return\n if (green.error !== undefined) out.push(this.toError(green.error, start))\n for (let i = 0; i < green.children.length; i++) visit(green.children[i], start + green.offsets[i])\n }\n visit(this.green, 0)\n this.errorList = out\n }\n return this.errorList\n }\n\n /** Whether the tree has any `ERROR` node. */\n get hasErrors(): boolean {\n return this.green.hasError\n }\n\n /** The smallest node containing `[start, end)` (see {@link SyntaxNode.descendantAt}). */\n descendantAt(start: number, end?: number): SyntaxNode<I> {\n return this.root.descendantAt(start, end)\n }\n\n /** A cursor at the root. */\n walk(): TreeCursor<I> {\n return new TreeCursor(this.root)\n }\n\n /**\n * The 1-based line and column (in code points) of an offset, as in\n * `ParseError`. Lines of a string input are indexed once, so lookups take\n * logarithmic time.\n */\n lineColumn(offset: number): ParseError.LineColumn {\n const input = this.input\n if (!Predicate.isString(input)) return ParseError.lineColumn(input, offset, this.encoding)\n let lines = this.lines\n if (lines === undefined) {\n lines = [0]\n for (let i = input.indexOf(\"\\n\"); i >= 0; i = input.indexOf(\"\\n\", i + 1)) lines.push(i + 1)\n this.lines = lines\n }\n const at = Math.max(0, Math.min(offset, input.length))\n let lo = 0\n let hi = lines.length - 1\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1\n if (lines[mid] <= at) lo = mid\n else hi = mid - 1\n }\n const lineStart = lines[lo]\n return { line: lo + 1, column: ParseError.lineColumn(input.slice(lineStart, at), at - lineStart).column }\n }\n\n /** The root's S-expression (see {@link SyntaxNode.toString}). */\n toString(): string {\n return this.root.toString()\n }\n\n /** @internal */\n toError(error: ErrorInfo, start: number): ParseError.ParseError<E> {\n return ParseError.fromFailure<E>(this.input, absolute(error.failure, start), error.mode, this.encoding)\n }\n}\n\n/**\n * A node of a syntax tree: its kind, span and value, and its place in the\n * tree. Nodes are views built on demand; two views of the same node are\n * different objects but have the same `start`, `end` and `kind`.\n *\n * @since 0.2.0\n * @category models\n */\nexport class SyntaxNode<I extends Input = string> {\n private childList: ReadonlyArray<SyntaxNode<I>> | undefined\n\n /** @internal */\n constructor(\n /** The tree this node belongs to. */\n readonly tree: Tree<unknown, unknown, I>,\n /** @internal */\n readonly green: Green,\n /** The offset where the node starts. */\n readonly start: number,\n /** The parent node; `undefined` for the root. */\n readonly parent: SyntaxNode<I> | undefined,\n /** The node's index among its parent's children. */\n readonly index: number\n ) {}\n\n /** The node's kind: the name given to {@link node} or {@link token}, or `\"ERROR\"`. */\n get kind(): string {\n return this.green.kind\n }\n\n /** `false` for the anonymous nodes built by {@link token}. */\n get named(): boolean {\n return this.green.named\n }\n\n /** The field name given by {@link field}, if any. */\n get field(): string | undefined {\n return this.parent?.green.fields?.[this.index]\n }\n\n /** The offset where the node ends (exclusive). */\n get end(): number {\n return this.start + this.green.width\n }\n\n /** The number of input units the node spans. */\n get length(): number {\n return this.green.width\n }\n\n /** The output of the node's parser (`undefined` for `ERROR` nodes, and for a root that failed). */\n get value(): unknown {\n return this.green.value\n }\n\n /** The input the node spans. */\n get text(): Slice<I> {\n const input = this.tree.input as any\n return input instanceof Uint8Array\n ? (input.subarray(this.start, this.end) as any)\n : input.slice(this.start, this.end)\n }\n\n /** Whether this is an `ERROR` node. */\n get isError(): boolean {\n return this.green.error !== undefined\n }\n\n /** Whether this node or a descendant is an `ERROR` node. */\n get hasError(): boolean {\n return this.green.hasError\n }\n\n /** For an `ERROR` node, the error it stands for. */\n get error(): ParseError.ParseError<unknown> | undefined {\n const error = this.green.error\n return error === undefined ? undefined : this.tree.toError(error, this.start)\n }\n\n /** The child nodes, named and anonymous, in input order. */\n get children(): ReadonlyArray<SyntaxNode<I>> {\n if (this.childList === undefined) {\n const green = this.green\n const out = new Array<SyntaxNode<I>>(green.children.length)\n for (let i = 0; i < out.length; i++) out[i] = this.makeChild(i)\n this.childList = out\n }\n return this.childList\n }\n\n /** The number of children. */\n get childCount(): number {\n return this.green.children.length\n }\n\n /** The child at `index` (negative indices count from the end). */\n child(index: number): SyntaxNode<I> | undefined {\n const n = this.green.children.length\n const i = index < 0 ? n + index : index\n return i >= 0 && i < n ? this.children[i] : undefined\n }\n\n /** The named children. */\n get namedChildren(): ReadonlyArray<SyntaxNode<I>> {\n return this.children.filter((c) => c.named)\n }\n\n /** The named child at `index`. */\n namedChild(index: number): SyntaxNode<I> | undefined {\n return this.namedChildren[index]\n }\n\n /** The first child with the given field name. */\n childByField(name: string): SyntaxNode<I> | undefined {\n const fields = this.green.fields\n if (fields === undefined) return undefined\n const i = fields.indexOf(name)\n return i < 0 ? undefined : this.children[i]\n }\n\n /** The children with the given field name. */\n childrenByField(name: string): ReadonlyArray<SyntaxNode<I>> {\n const fields = this.green.fields\n if (fields === undefined) return []\n return this.children.filter((_, i) => fields[i] === name)\n }\n\n /** The next sibling, named or anonymous. */\n get nextSibling(): SyntaxNode<I> | undefined {\n return this.parent?.children[this.index + 1]\n }\n\n /** The previous sibling, named or anonymous. */\n get previousSibling(): SyntaxNode<I> | undefined {\n return this.index > 0 ? this.parent?.children[this.index - 1] : undefined\n }\n\n /** The next named sibling. */\n get nextNamedSibling(): SyntaxNode<I> | undefined {\n const siblings = this.parent?.children\n if (siblings === undefined) return undefined\n for (let i = this.index + 1; i < siblings.length; i++) if (siblings[i].named) return siblings[i]\n return undefined\n }\n\n /** The previous named sibling. */\n get previousNamedSibling(): SyntaxNode<I> | undefined {\n const siblings = this.parent?.children\n if (siblings === undefined) return undefined\n for (let i = this.index - 1; i >= 0; i--) if (siblings[i].named) return siblings[i]\n return undefined\n }\n\n /**\n * The index of the child containing the input unit at `offset`, or -1.\n * Takes logarithmic time.\n */\n childIndexAt(offset: number): number {\n const green = this.green\n const offsets = green.offsets\n const rel = offset - this.start\n let lo = 0\n let hi = offsets.length - 1\n let found = -1\n while (lo <= hi) {\n const mid = (lo + hi) >> 1\n if (offsets[mid] <= rel) {\n found = mid\n lo = mid + 1\n } else {\n hi = mid - 1\n }\n }\n // Skip back over empty `ERROR` nodes at `offset`\n while (found >= 0 && green.children[found].width === 0 && offsets[found] === rel) found--\n return found >= 0 && rel < offsets[found] + green.children[found].width ? found : -1\n }\n\n /** The child containing the input unit at `offset`. */\n childAt(offset: number): SyntaxNode<I> | undefined {\n const i = this.childIndexAt(offset)\n return i < 0 ? undefined : this.children[i]\n }\n\n /**\n * The smallest node, this one or a descendant, that contains\n * `[start, end)` (Tree-sitter's `descendant_for_byte_range`). With only\n * `start`, the deepest node containing the input unit at `start`. Takes\n * time proportional to the depth of the tree times the logarithm of the\n * number of children.\n */\n descendantAt(start: number, end: number = start + 1): SyntaxNode<I> {\n return descendantOf(this, start, end)\n }\n\n /** Like {@link descendantAt}, but only stops at named nodes. */\n namedDescendantAt(start: number, end: number = start + 1): SyntaxNode<I> {\n let node: SyntaxNode<I> = this.descendantAt(start, end)\n // Every node below `this` has a parent, so the walk stops at `this` at the latest\n while (!node.named && node !== this) node = node.parent ?? this\n return node\n }\n\n /** This node and its descendants, in pre-order. */\n *descendants(): Generator<SyntaxNode<I>, void, undefined> {\n const cursor = this.walk()\n while (true) {\n yield cursor.node\n if (cursor.gotoFirstChild()) continue\n while (!cursor.gotoNextSibling()) {\n if (!cursor.gotoParent()) return\n }\n }\n }\n\n /** The descendants of the given kind, in pre-order. */\n *descendantsOfKind(kind: string): Generator<SyntaxNode<I>, void, undefined> {\n for (const n of this.descendants()) if (n.kind === kind) yield n\n }\n\n /** A cursor at this node, which cannot move above it. */\n walk(): TreeCursor<I> {\n return new TreeCursor(this)\n }\n\n /**\n * The node as an S-expression of its named descendants, with field\n * names, as Tree-sitter prints it: `(pair key: (name) value: (number))`.\n */\n toString(): string {\n let out = \"\"\n const visit = (green: Green, field: string | undefined) => {\n if (green.named || green === this.green) {\n if (Str.isNonEmpty(out)) out += \" \"\n if (field !== undefined) out += `${field}: `\n out += `(${green.kind}`\n for (let i = 0; i < green.children.length; i++) visit(green.children[i], green.fields?.[i])\n out += \")\"\n } else {\n for (let i = 0; i < green.children.length; i++) visit(green.children[i], green.fields?.[i])\n }\n }\n visit(this.green, this.field)\n return out\n }\n\n toJSON(): unknown {\n return { kind: this.kind, start: this.start, end: this.end }\n }\n\n private makeChild(i: number): SyntaxNode<I> {\n const green = this.green\n return new SyntaxNode(this.tree, green.children[i], this.start + green.offsets[i], this, i)\n }\n}\n\n/** The smallest node, `root` or a descendant, that contains `[start, end)` (see `SyntaxNode.descendantAt`). */\nconst descendantOf = <I extends Input>(root: SyntaxNode<I>, start: number, end: number): SyntaxNode<I> => {\n let node = root\n while (true) {\n const i = node.childIndexAt(start)\n if (i < 0) return node\n const child = node.children[i]\n if (end > child.end) return node\n node = child\n }\n}\n\n/**\n * A cursor for walking a tree, as Tree-sitter's `TreeCursor`. It starts at\n * a node and cannot move above it.\n *\n * @since 0.2.0\n * @category models\n */\nexport class TreeCursor<I extends Input = string> {\n private current: SyntaxNode<I>\n private depth = 0\n\n /** @internal */\n constructor(node: SyntaxNode<I>) {\n this.current = node\n }\n\n /** The node at the cursor. */\n get node(): SyntaxNode<I> {\n return this.current\n }\n\n /** The field name of the node at the cursor, if any. */\n get field(): string | undefined {\n return this.depth === 0 ? undefined : this.current.field\n }\n\n /** Moves to the first child; `false` if there is none. */\n gotoFirstChild(): boolean {\n return this.goto(this.current.child(0))\n }\n\n /** Moves to the last child; `false` if there is none. */\n gotoLastChild(): boolean {\n return this.goto(this.current.child(-1))\n }\n\n /** Moves to the child containing the input unit at `offset`; `false` if there is none. */\n gotoFirstChildForOffset(offset: number): boolean {\n return this.goto(this.current.childAt(offset))\n }\n\n /** Moves to the next sibling; `false` if there is none. */\n gotoNextSibling(): boolean {\n if (this.depth === 0) return false\n const next = this.current.nextSibling\n if (next === undefined) return false\n this.current = next\n return true\n }\n\n /** Moves to the previous sibling; `false` if there is none. */\n gotoPreviousSibling(): boolean {\n if (this.depth === 0) return false\n const previous = this.current.previousSibling\n if (previous === undefined) return false\n this.current = previous\n return true\n }\n\n /** Moves to the parent; `false` at the node the cursor started at. */\n gotoParent(): boolean {\n const parent = this.current.parent\n if (this.depth === 0 || parent === undefined) return false\n this.current = parent\n this.depth--\n return true\n }\n\n /** Moves to the deepest node containing the input unit at `offset`. */\n gotoDescendantAt(offset: number): void {\n while (this.gotoFirstChildForOffset(offset)) {\n // descend\n }\n }\n\n /** Starts again at `node`. */\n reset(node: SyntaxNode<I>): void {\n this.current = node\n this.depth = 0\n }\n\n private goto(node: SyntaxNode<I> | undefined): boolean {\n if (node === undefined) return false\n this.current = node\n this.depth++\n return true\n }\n}\n\n// -----------------------------------------------------------------------------\n// Parsing\n// -----------------------------------------------------------------------------\n\nconst expectedEof = [\"end of input\"]\n\nconst run = <A, E, I extends Input>(config: Config, input: I, previous: Previous | undefined): Tree<A, E, I> => {\n const state = new State<I>(input, { context: config.context })\n const builder = new SyntaxBuilder(state, previous)\n const a = Stack.run(config.inner.step, state)\n // Text parsers record the encoding when they fail, which they may have done inside reused nodes\n if (state.encoding === undefined && previous !== undefined) state.encoding = previous.encoding\n let fatal: ErrorInfo | undefined\n let value: Option.Option<A> = Option.none()\n if (a === Fail) {\n fatal = { failure: state.reportedFailure(), mode: state.mode }\n } else if (state.pos < state.end) {\n state.backtrack(\"Eof\", expectedEof)\n fatal = { failure: state.reportedFailure(), mode: \"Backtrack\" }\n } else {\n value = Option.some(a as A)\n }\n const green = builder.finish(config.kind, Option.getOrUndefined(value), fatal, state.pos)\n return new Tree<A, E, I>(input, value, builder.reused, green, config, state.encoding)\n}\n\n/**\n * Parses an input into a syntax {@link Tree}. The grammar's output is the\n * tree's `value`, and its {@link node}s are the tree's nodes. When the\n * grammar is itself a {@link node}, that node is the root; otherwise the\n * root is a node of kind `options.kind` (by default `\"document\"`).\n *\n * The parse never fails: recovered failures (see `Parser.resumeAfter`), a\n * fatal failure and unparsed input at the end all become `ERROR` nodes, and\n * are listed in `tree.errors`. The parse is interpreted, never compiled.\n *\n * @since 0.2.0\n * @category parsing\n */\nexport const parse: {\n <A, E, I extends Input>(\n grammar: Parser<A, E, never, I>,\n input: NoInfer<Source<I>>,\n options?: ParseOptions\n ): Tree<A, E, I>\n <A, E, R, I extends Input>(\n grammar: Parser<A, E, R, I>,\n input: NoInfer<Source<I>>,\n options: ParseOptionsWithContext<R>\n ): Tree<A, E, I>\n} = <A, E, R, I extends Input>(\n grammar: Parser<A, E, R, I>,\n input: I | Source<I>,\n options?: ParseOptions & { readonly context?: Context.Context<R> }\n): Tree<A, E, I> => {\n const n = nodeOf(grammar)\n const isRoot = Predicate.isTagged(n, \"Syntax\") && n.kind !== undefined && n.named\n const config: Config = {\n kind: isRoot ? n.kind : (options?.kind ?? \"document\"),\n inner: isRoot ? (n.self as Parser.Any) : grammar,\n lookahead: options?.lookahead ?? 0,\n context: options?.context as Context.Context<never> | undefined\n }\n return run(config, fromSource(input as Input) as I, undefined)\n}\n\n/**\n * Parses the new version of a tree's input, reusing the nodes of the tree\n * that the edits leave unchanged (Tree-sitter's `ts_tree_edit` followed by\n * `ts_parser_parse` with the old tree). The result is the tree a fresh\n * {@link parse} of `input` would build, but only the parts of the tree\n * around the edits are parsed again. `tree.reused` says how many nodes were\n * reused.\n *\n * `edits` describe how the old input became the new one, applied in order,\n * each in the coordinates of the input as the previous edits left it. When\n * they are omitted, the edit is found by comparing the inputs (their common\n * prefix and suffix), which takes time linear in their length but much less\n * than parsing.\n *\n * Errors in the new tree are those a fresh parse reports, except that an\n * error just after a reused node may list fewer expected alternatives.\n *\n * @example\n * ```ts\n * import { Ascii, Syntax } from \"@thomasfosterau/effect-parse\"\n *\n * const number = Syntax.node(Ascii.decInt, \"number\")\n * const tree = Syntax.parse(number, \"12\")\n * Syntax.reparse(tree, \"123\", [{ start: 2, oldEnd: 2, newEnd: 3 }]).root.value // 123\n * ```\n *\n * @since 0.2.0\n * @category parsing\n */\nexport const reparse = <A, E, I extends Input>(\n tree: Tree<A, E, I>,\n input: NoInfer<Source<I>>,\n edits?: Edit | ReadonlyArray<Edit>\n): Tree<A, E, I> => {\n const next = fromSource(input as Input) as I\n const list =\n edits === undefined\n ? diffList(tree.input, next)\n : \"start\" in edits\n ? [edits as Edit]\n : (edits as ReadonlyArray<Edit>)\n const previous: Previous = {\n root: tree.green,\n oldLength: tree.input.length,\n newLength: next.length,\n segments: segmentsOf(tree.input.length, next.length, list),\n input: tree.input,\n extra: tree.config.lookahead,\n encoding: tree.encoding\n }\n return run(tree.config, next, previous)\n}\n\n/**\n * Replaces `[start, end)` of a tree's string input with `text` and parses\n * the result incrementally (see {@link reparse}).\n *\n * @since 0.2.0\n * @category parsing\n */\nexport const replace = <A, E>(\n tree: Tree<A, E, string>,\n start: number,\n end: number,\n text: string\n): Tree<A, E, string> => {\n const input = tree.input\n if (start < 0 || end < start || end > input.length) {\n throw new RangeError(`invalid range [${start}, ${end}) of an input of length ${input.length}`)\n }\n return reparse(tree, input.slice(0, start) + text + input.slice(end), {\n start,\n oldEnd: end,\n newEnd: start + text.length\n })\n}\n\n/**\n * Finds the edit that turns `before` into `after`: the part between their\n * longest common prefix and suffix. `undefined` when they are equal.\n *\n * @since 0.2.0\n * @category parsing\n */\nexport const diff = <I extends Input>(before: I, after: I): Edit | undefined => {\n const a = before as any\n const b = after as any\n const at = Predicate.isString(a) ? (s: string, i: number) => s.charCodeAt(i) : (s: any, i: number) => s[i]\n const max = Math.min(a.length, b.length)\n let prefix = 0\n while (prefix < max && at(a, prefix) === at(b, prefix)) prefix++\n if (prefix === a.length && prefix === b.length) return undefined\n let suffix = 0\n while (suffix < max - prefix && at(a, a.length - 1 - suffix) === at(b, b.length - 1 - suffix)) suffix++\n return { start: prefix, oldEnd: a.length - suffix, newEnd: b.length - suffix }\n}\n\nconst diffList = (before: Input, after: Input): ReadonlyArray<Edit> => {\n const edit = diff(before, after)\n return edit === undefined ? [] : [edit]\n}\n\n/** The stretches of the new input copied unchanged from the old one. */\nconst segmentsOf = (oldLength: number, newLength: number, edits: ReadonlyArray<Edit>): Array<Segment> => {\n let segments: Array<Segment> = oldLength > 0 ? [{ newStart: 0, oldStart: 0, length: oldLength }] : []\n let length = oldLength\n for (const { newEnd, oldEnd, start } of edits) {\n if (!(start >= 0 && oldEnd >= start && oldEnd <= length && newEnd >= start)) {\n throw new RangeError(\n `invalid edit { start: ${start}, oldEnd: ${oldEnd}, newEnd: ${newEnd} } of an input of length ${length}`\n )\n }\n const delta = newEnd - oldEnd\n const out: Array<Segment> = []\n for (const s of segments) {\n const end = s.newStart + s.length\n if (s.newStart < start) {\n out.push({ newStart: s.newStart, oldStart: s.oldStart, length: Math.min(end, start) - s.newStart })\n }\n if (end > oldEnd) {\n const from = Math.max(s.newStart, oldEnd)\n out.push({ newStart: from + delta, oldStart: s.oldStart + (from - s.newStart), length: end - from })\n }\n }\n segments = out\n length += delta\n }\n if (length !== newLength) {\n throw new RangeError(`the edits give an input of length ${length}, but the new input has length ${newLength}`)\n }\n return segments\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,cAAc,MAAkB,MAAc,UAA+B;CACjF,MAAM,OAAO,KAAK;CAElB,MAAM,MAAM,IAAI,IAAI;CACpB,OAAO,WACJ,UAAU;EACT,MAAM,UAAU,MAAM;EACtB,OAAO,YAAY,KAAA,I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2
|
import { StringTokenSet } from "./Token.js";
|
|
3
3
|
import { Encoding } from "./Encoding.js";
|
|
4
|
-
//#region src/Text.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* A predicate over characters. It accepts a one-character string or a code
|
|
7
6
|
* point.
|
|
@@ -290,5 +289,4 @@ export declare const utf16be: TextParsers<Uint8Array>;
|
|
|
290
289
|
* @category instances
|
|
291
290
|
*/
|
|
292
291
|
export declare const latin1: TextParsers<Uint8Array>;
|
|
293
|
-
//#endregion
|
|
294
292
|
//# sourceMappingURL=Text.d.ts.map
|
package/dist/Text.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.d.ts","names":[],"sources":["../src/Text.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Text.d.ts","names":[],"sources":["../src/Text.ts"],"mappings":";;;;;;;;;;YAgEY,iBAAiB;;;;;;;;;;;;;;;;;qBAsChB,WAAY,iBAAe;;;;;;;;qBAS3B,cAAc;;;;;;;qBAQd,UAAU;;;;;;;qBAQV,aAAa;;;;;;;qBAQb,aAAa;;;;;;;;qBASb,gBAAgB;;;;;;;;qBAShB,WAAW;;;;;;;qBAQX,gBAAgB;;;;;;;;qBAShB,cAAc;;;;;;;;qBASd,SAAS;;;;;;;;qBAYT,WAAW;;;;;;;;qBASX,cAAc;;;;;;;qBAQd,eAAe;;;;;;;qBAQf,WAAW;;;;;;;;;;;;iBAiBP,YAAY,mBAAmB;;WAErC,UAAU,SAAS;;WAKnB,KAAK,6BAA6B;;;;;WAKlC,gBAAgB,kBAAkB,SAAS,MAAM,OAAO,iBAAiB;;;;;;WAMzE,WAAW,oBAAoB,6BAA6B;;WAE5D,QAAQ,KAAK,mBAAmB,6BAA6B;;WAE7D,SAAS,KAAK,mBAAmB,6BAA6B;;WAE9D,KAAK,8BAA8B;;WAKnC,OAAO,kBAAkB,6BAA6B;;WAEtD,YAAY,KAAK,gBAAgB,QAAQ,UAAU,6BAA6B;;WAEhF,WAAW,K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"}
|
package/dist/Text.js
CHANGED
|
@@ -6,7 +6,7 @@ import { codePointPredicate, compile, indexOf, matchLiteral } from "./internal/t
|
|
|
6
6
|
import * as internal from "./internal/text.js";
|
|
7
7
|
import { escapedImpl, overflow, takeEscapedImpl, toFloat as toFloat$1 } from "./Ascii.js";
|
|
8
8
|
import * as Encodings from "./Encoding.js";
|
|
9
|
-
|
|
9
|
+
// src/Text.ts
|
|
10
10
|
/**
|
|
11
11
|
* Unicode text parsers, generic over the input's encoding.
|
|
12
12
|
*
|
|
@@ -561,7 +561,6 @@ const utf16be = /*#__PURE__*/ make(Encodings.utf16be);
|
|
|
561
561
|
* @category instances
|
|
562
562
|
*/
|
|
563
563
|
const latin1 = /*#__PURE__*/ make(Encodings.latin1);
|
|
564
|
-
//#endregion
|
|
565
564
|
export { isAlphabetic, isAlphanumeric, isControl, isDecimalDigit, isIdContinue, isIdStart, isLetter, isLowercase, isNumeric, isPunctuation, isSpace, isUppercase, isWhitespace, latin1, make, property, string, utf16be, utf16le, utf8 };
|
|
566
565
|
|
|
567
566
|
//# sourceMappingURL=Text.js.map
|
package/dist/Token.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Input, Slice, Token } from "./Input.js";
|
|
2
2
|
import { Parser, Range } from "./Parser.js";
|
|
3
3
|
import { ErrorKind } from "./ParseError.js";
|
|
4
|
-
//#region src/Token.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* An inclusive range of tokens, e.g. `Token.range("a", "z")`.
|
|
7
6
|
*
|
|
@@ -238,6 +237,5 @@ export declare const restLen: Parser<number, never, never, Input>;
|
|
|
238
237
|
* @category tokens
|
|
239
238
|
*/
|
|
240
239
|
export declare const satisfy: <I extends Input = string>(predicate: (token: Token<I>) => boolean) => Parser<Token<NoInfer<I>>, never, never, NoInfer<I>>;
|
|
241
|
-
//#endregion
|
|
242
240
|
export type { Token };
|
|
243
241
|
//# sourceMappingURL=Token.d.ts.map
|
package/dist/Token.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Token.d.ts","names":[],"sources":["../src/Token.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Token.d.ts","names":[],"sources":["../src/Token.ts"],"mappings":";;;;;;;;;iBAyDiB,WAAW;WACjB;WACA,MAAM;WACN,IAAI;;;;;;;;qBASF,QAAS,2BAA2B,MAAM,GAAG,IAAI,MAAI,WAAW;cAE/D;;;;;;;;;iBAUG;GACd;YACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA8BC,aACX,cACA,YAAY,+BACZ,SAAS,6CACR;;;;;;;;;;YAiBS,0BAER,qBACA,eACE,4BACF,cAAc;;;;;;;;YASN,iCAGR,aACA,qBACA,eACE,4BACF,cAAc;;;;;;;;YASN,SAAS,KAAK,mBACtB,iBACA,UAAU,aACR,eACA,UAAU,oBAAoB,OAC1B,OAAO,iBAAiB,cAAc;;;;;;;;qBAoCnC,KAAK;;;;;;;;;;;;;;;qBAgBL,WAAY,UAAU,qBAAmB,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;;;;;;;;;;;;;qBAkBzF;SACJ,kBAAkB,SAAS,IAAI,OAAO;GAC5C,SAAS,aAAa,OAAO,0BAA0B;SACjD,GAAG,SAAS,cAAc,KAAK,OAAO,cAAc,kBAAkB,cAAc;;;qBAIhF,cAAe,KAAK,OAAO,sBAAoB;;;;;;;;;;;;;;;;;qBAyC/C,QAAS,UAAU,gBAC9B,KAAK,SAAS,OACb,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;;;;qBAsBtC,SAAU,UAAU,gBAC/B,KAAK,SAAS,OACb,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;;;qBAqBtC,OAAQ,UAAU,gBAAgB,kBAAgB,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;qBAsBlG,gBAAiB,UAAU,OACtC,cACA,GAAG,mBACH,iBACA,cACA,sBACA,OAAM,WACN,mBACC,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;;;;;;;;;;;;;;;;qBAuCtC,YAAa,UAAU,gBAClC,KAAK,SAAS,IACd,QAAQ,UACP,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;;;;qBAStC,WAAY,UAAU,gBACjC,KAAK,SAAS,IACd,QAAQ,UACP,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;;;;;qBAUtC;GACV,iBAAiB,QAAQ,QAAQ;GACjC,SAAS,YAAY,QAAQ,QAAQ,OAAO,0BAA0B;GACtE,GAAG,SAAS,cAAc,IAAI,QAAQ,QAAQ,OAAO,cAAc,kBAAkB,cAAc;;;;;;;;qBAmCzF,MAAM;;;;;;;qBAgBN,SAAU,UAAU,qBAAmB,OAAO,MAAM,QAAQ,mBAAmB,QAAQ;;;;;;;;qBASvF,SAAS,6BAA6B;;;;;;;;qBAetC,UAAW,UAAU,gBAChC,YAAY,OAAO,MAAM,mBACxB,OAAO,MAAM,QAAQ,mBAAmB,QAAQ"}
|
package/dist/Token.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as Predicate from "effect/Predicate";
|
|
|
2
2
|
import { described } from "./Parser.js";
|
|
3
3
|
import { End, NoMatch, advance, codePointPredicate, compileAny, countTokens, describeLiteral, indexOf, matchLiteral, nextIf, scan, splitSurrogate } from "./internal/tokens.js";
|
|
4
4
|
import { bounds } from "./internal/node.js";
|
|
5
|
-
|
|
5
|
+
// src/Token.ts
|
|
6
6
|
/**
|
|
7
7
|
* Parsers for individual tokens and slices of tokens (winnow's `token`
|
|
8
8
|
* module, nom's `bytes` module).
|
|
@@ -354,7 +354,6 @@ const restLen = /*#__PURE__*/ described((state) => state.end - state.pos, "restL
|
|
|
354
354
|
* @category tokens
|
|
355
355
|
*/
|
|
356
356
|
const satisfy = (predicate) => oneOf(predicate);
|
|
357
|
-
//#endregion
|
|
358
357
|
export { any, anyToken, codePoints, literal, literalImpl, noneOf, oneOf, range, rest, restLen, restOf, satisfy, take, takeTill, takeUntil, takeWhile, takeWhileImpl };
|
|
359
358
|
|
|
360
359
|
//# sourceMappingURL=Token.js.map
|
|
@@ -2,7 +2,6 @@ import { State } from "../../Input.js";
|
|
|
2
2
|
import { Backend } from "./registry.js";
|
|
3
3
|
import { Node, ParserLike } from "../node.js";
|
|
4
4
|
import { FirstSets } from "./first.js";
|
|
5
|
-
//#region src/internal/compiler/closure.d.ts
|
|
6
5
|
export type Step = (state: State<any>) => any;
|
|
7
6
|
/** A parser that the compiler left to its interpreted step. */
|
|
8
7
|
export interface Fallback {
|
|
@@ -17,7 +16,11 @@ export interface ClosureCompiler {
|
|
|
17
16
|
readonly fallbacks: ReadonlyArray<Fallback>;
|
|
18
17
|
}
|
|
19
18
|
export declare const createClosureCompiler: (kind: 0 | 1 | 2, resumable?: boolean) => ClosureCompiler;
|
|
19
|
+
/** A compiled root parser, with the parts of it that run interpreted. */
|
|
20
|
+
export interface CompiledRoot {
|
|
21
|
+
readonly step: Step;
|
|
22
|
+
readonly fallbacks: ReadonlyArray<Fallback>;
|
|
23
|
+
}
|
|
20
24
|
/** The closure compiler as a backend. */
|
|
21
25
|
export declare const backend: Backend;
|
|
22
|
-
//#endregion
|
|
23
26
|
//# sourceMappingURL=closure.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closure.d.ts","names":[],"sources":["../../../src/internal/compiler/closure.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"closure.d.ts","names":[],"sources":["../../../src/internal/compiler/closure.ts"],"mappings":";;;;YA8BY,QAAQ,OAAO;;iBAGV;WACN;WACA,KAAK;WACL;;iBAmnDM;WACN,UAAU,GAAG,YAAY,kBAAkB;WAC3C,OAAO,GAAG,YAAY,MAAM,MAAM;WAClC,QAAQ;WACR,WAAW,cAAc;;qBAGvB,wBAAyB,iBAAiB,wBAAoB;;iBAW1D;WACN,MAAM;WACN,WAAW,cAAc;;;qBAWvB,SAAS"}
|