effect-grammar 0.3.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 +71 -220
- package/dist/ast.d.ts +115 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +253 -0
- package/dist/ast.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -1
- package/dist/schema.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,255 +1,106 @@
|
|
|
1
1
|
# effect-grammar
|
|
2
2
|
|
|
3
|
-
Invertible grammar combinators and parser-printers for Effect.
|
|
4
|
-
|
|
5
|
-
Schema models your structured data. `effect-grammar` models the text formats
|
|
6
|
-
inside your strings: connection strings, duration strings (`1h30m`), cron
|
|
7
|
-
expressions, search queries, or DSLs.
|
|
8
|
-
|
|
9
|
-
You write the grammar definition once. You get four outputs:
|
|
10
|
-
|
|
11
|
-
- **A parser.** Reads text and outputs structured data, with line and column
|
|
12
|
-
error messages.
|
|
13
|
-
- **A printer.** Converts structured data back to canonical text.
|
|
14
|
-
- **A `Schema.Codec<A, string>`.** Decoding parses, encoding prints, and Schema
|
|
15
|
-
refinements compose.
|
|
16
|
-
- **A text renderer.** Formats the grammar as readable text, for documentation
|
|
17
|
-
and schema descriptions.
|
|
18
|
-
|
|
19
|
-
## Why effect-grammar?
|
|
20
|
-
|
|
21
|
-
`Schema.transformOrFail` makes you write and maintain both directions by hand.
|
|
22
|
-
`Schema.TemplateLiteralParser` only handles flat `${a}-${b}` patterns.
|
|
23
|
-
`effect-grammar` derives both directions for you. It handles optional parts,
|
|
24
|
-
repetition, alternation, recursion, and parts that depend on earlier parts.
|
|
25
|
-
|
|
26
|
-
This is for format strings, not documents. The parser backtracks. There is no
|
|
27
|
-
memoization and no left recursion. Printing is canonical, not pretty.
|
|
28
|
-
|
|
29
|
-
## Install
|
|
30
|
-
|
|
31
3
|
```bash
|
|
32
4
|
pnpm add effect-grammar
|
|
33
5
|
```
|
|
34
6
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
## A grammar
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
import * as Grammar from "effect-grammar"
|
|
41
|
-
|
|
42
|
-
const endpoint = Grammar.gen(function* () {
|
|
43
|
-
yield* Grammar.literal("https://")
|
|
44
|
-
const host = yield* Grammar.regex(/[^:/?#]+/, "host")
|
|
45
|
-
const port = yield* Grammar.optional(Grammar.prefix(":", Grammar.integer))
|
|
46
|
-
return { host, port }
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
Grammar.parse(endpoint, "https://effect.website:8080")
|
|
50
|
-
// Result.succeed({ host: "effect.website", port: 8080 })
|
|
51
|
-
|
|
52
|
-
Grammar.parse(endpoint, "https://effect.website:abc")
|
|
53
|
-
// Result.fail(ParseError: line 1, column 24: expected integer, found "a")
|
|
54
|
-
|
|
55
|
-
Grammar.print(endpoint, { host: "effect.website", port: 443 })
|
|
56
|
-
// Result.succeed("https://effect.website:443")
|
|
57
|
-
|
|
58
|
-
Grammar.render(endpoint)
|
|
59
|
-
// "https://" host:<host> port:(":" <integer>)?
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
`gen` runs the generator once, when you build the grammar. Nothing is parsed
|
|
63
|
-
yet.
|
|
7
|
+
Invertible grammar combinators and parser-printers for Effect.
|
|
64
8
|
|
|
65
|
-
|
|
66
|
-
gives you a `Ref<A>`: a stand-in for the value that will exist at parse and
|
|
67
|
-
print time. `yield*` on a silent grammar, such as `literal` or `symbol`, gives
|
|
68
|
-
nothing back. Silent grammars carry no value.
|
|
9
|
+
A `Grammar<A>` supports four operations:
|
|
69
10
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
the grammar
|
|
11
|
+
- `parse`: read a string and return a `Result<A, ParseError>`
|
|
12
|
+
- `print`: write an `A` as canonical text and return a
|
|
13
|
+
`Result<string, PrintError>`
|
|
14
|
+
- `codec`: combine the grammar with an Effect Schema to make a string codec
|
|
15
|
+
- `render`: return a readable description of the grammar
|
|
74
16
|
|
|
75
17
|
```ts
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
yield* Grammar.literal(":")
|
|
79
|
-
const port = yield* Grammar.integer
|
|
80
|
-
return { kind: "endpoint", address: { host, port } } as const
|
|
81
|
-
})
|
|
82
|
-
// Grammar<{ kind: "endpoint"; address: { host: string; port: number } }>
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## The one rule
|
|
86
|
-
|
|
87
|
-
Every binding must appear in the return pattern exactly once. `gen` throws at
|
|
88
|
-
build time if one does not. A binding the return does not hold is a value the
|
|
89
|
-
printer could not print.
|
|
90
|
-
|
|
91
|
-
To parse something and then drop it, wrap it with `skip`. The grammar prints its
|
|
92
|
-
canonical form instead.
|
|
93
|
-
|
|
94
|
-
## Refs are not values
|
|
18
|
+
import { Schema } from "effect"
|
|
19
|
+
import * as G from "effect-grammar"
|
|
95
20
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
small helpers: `defaulted` supplies a value when a part is absent.
|
|
101
|
-
`get(ref, key)` reads a property of a ref, including reserved names such as
|
|
102
|
-
`then` and `toJSON`.
|
|
103
|
-
|
|
104
|
-
## Depending on an earlier part
|
|
105
|
-
|
|
106
|
-
`match` picks a grammar based on an earlier binding. The printer runs the same
|
|
107
|
-
choice backwards.
|
|
108
|
-
|
|
109
|
-
```ts
|
|
110
|
-
const tagged = Grammar.gen(function* () {
|
|
111
|
-
const kind = yield* Grammar.choice(
|
|
112
|
-
Grammar.literal("n:").pipe(Grammar.as("num")),
|
|
113
|
-
Grammar.literal("w:").pipe(Grammar.as("word")),
|
|
21
|
+
const frame = G.gen(function* () {
|
|
22
|
+
const kind = yield* G.choice(
|
|
23
|
+
G.literal("text").pipe(G.as("text")),
|
|
24
|
+
G.literal("bits").pipe(G.as("bits")),
|
|
114
25
|
)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
26
|
+
yield* G.literal("/")
|
|
27
|
+
const size = yield* G.integer
|
|
28
|
+
yield* G.literal(":")
|
|
29
|
+
const body = yield* G.match(kind, {
|
|
30
|
+
text: G.take(size),
|
|
31
|
+
bits: G.repeat(G.regex(/[01]/, "bit"), size),
|
|
118
32
|
})
|
|
119
|
-
return { kind,
|
|
33
|
+
return { kind, size, body }
|
|
120
34
|
})
|
|
121
|
-
// parses "n:12" → { kind: "num", value: 12 }
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
`match` requires the cases to cover every literal of the selector's type.
|
|
125
|
-
`matchValue` is the same idea with number or mixed literal keys. Keys keep their
|
|
126
|
-
type, so `1` and `"1"` are distinct cases.
|
|
127
35
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const frame = Grammar.gen(function* () {
|
|
133
|
-
const header = yield* headerGrammar // { kind: "text" | "bin"; size: number }
|
|
134
|
-
yield* Grammar.literal(":")
|
|
135
|
-
const body = yield* Grammar.match(header.kind, {
|
|
136
|
-
text: Grammar.take(header.size),
|
|
137
|
-
bin: Grammar.repeat(Grammar.regex(/[01]/, "bit"), header.size),
|
|
138
|
-
})
|
|
139
|
-
return { header, body }
|
|
36
|
+
const FrameValue = Schema.Struct({
|
|
37
|
+
kind: Schema.Literals(["text", "bits"]),
|
|
38
|
+
size: Schema.Number,
|
|
39
|
+
body: Schema.Union([Schema.String, Schema.Array(Schema.String)]),
|
|
140
40
|
})
|
|
141
|
-
```
|
|
142
41
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
const netstring = Grammar.gen(function* () {
|
|
149
|
-
const length = yield* Grammar.integer
|
|
150
|
-
yield* Grammar.literal(":")
|
|
151
|
-
const payload = yield* Grammar.take(length)
|
|
152
|
-
yield* Grammar.literal(",")
|
|
153
|
-
return { length, payload }
|
|
154
|
-
})
|
|
155
|
-
// "5:hello," ⇄ { length: 5, payload: "hello" }
|
|
42
|
+
const Frame = G.codec(frame, FrameValue, { identifier: "Frame" })
|
|
43
|
+
const decode = Schema.decodeSync(Frame)
|
|
44
|
+
const encode = Schema.encodeSync(Frame)
|
|
156
45
|
```
|
|
157
46
|
|
|
158
|
-
|
|
47
|
+
The grammar and its Schema codec use the same parser and printer:
|
|
159
48
|
|
|
160
|
-
|
|
49
|
+
```text
|
|
50
|
+
decode("text/5:hello") → { kind: "text", size: 5, body: "hello" }
|
|
51
|
+
decode("bits/4:1010") → { kind: "bits", size: 4, body: ["1", "0", "1", "0"] }
|
|
161
52
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
direction should return a `Result` instead:
|
|
53
|
+
encode({ kind: "text", size: 2, body: "hi" }) → "text/2:hi"
|
|
54
|
+
encode({ kind: "bits", size: 4, body: ["1", "0", "1", "0"] }) → "bits/4:1010"
|
|
165
55
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
Grammar.transformOrFail({
|
|
169
|
-
decode: (text) =>
|
|
170
|
-
Result.try({
|
|
171
|
-
try: () => JSON.parse(text),
|
|
172
|
-
catch: (error) => ({ message: String(error) }),
|
|
173
|
-
}),
|
|
174
|
-
encode: (value) => Result.succeed(JSON.stringify(value)),
|
|
175
|
-
}),
|
|
176
|
-
)
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
`decodeTo` checks the value against a Schema on parse and on print. `as` turns a
|
|
180
|
-
silent grammar into a constant. `flag` turns presence into a boolean.
|
|
181
|
-
|
|
182
|
-
`choice` tries its options in order and backtracks. It has one round-trip rule:
|
|
183
|
-
the text printed for a branch must not parse as a different value through an
|
|
184
|
-
earlier branch. `taggedChoice` records the chosen branch in the result.
|
|
56
|
+
parse("bits/4:1020") → line 1, column 10: expected bit, found "2"
|
|
57
|
+
print({ kind: "text", size: 2, body: "hello" }) → .body: expected 2 UTF-16 code units, got "hello"
|
|
185
58
|
|
|
186
|
-
|
|
187
|
-
const value = Grammar.taggedChoice("kind", {
|
|
188
|
-
number: Grammar.integer,
|
|
189
|
-
word: Grammar.regex(/[a-z]+/, "word"),
|
|
190
|
-
})
|
|
191
|
-
// parses "12" → { kind: "number", value: 12 }
|
|
192
|
-
// prints the same → "12"
|
|
59
|
+
render(frame) → kind:("text" | "bits") "/" size:<integer> ":" body:match(kind){"text" => <char>{size} | "bits" => (<bit>){size}}
|
|
193
60
|
```
|
|
194
61
|
|
|
195
|
-
|
|
62
|
+
## Schema integration
|
|
196
63
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
Grammar.choice(
|
|
201
|
-
jsonNull,
|
|
202
|
-
jsonBool,
|
|
203
|
-
jsonNumber,
|
|
204
|
-
jsonString,
|
|
205
|
-
jsonArray,
|
|
206
|
-
jsonObject,
|
|
207
|
-
),
|
|
208
|
-
"value",
|
|
209
|
-
)
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
See `examples/` for JSON, Scheme, a Postgres DSN, netstrings, a wire protocol,
|
|
213
|
-
and GitHub's search syntax.
|
|
214
|
-
|
|
215
|
-
## Products, delimiters, and trivia
|
|
64
|
+
`codec` combines a grammar with an Effect Schema. Decoding parses the text and
|
|
65
|
+
then checks the value. Encoding checks the value and then prints it. The example
|
|
66
|
+
above shows the full integration in one code block.
|
|
216
67
|
|
|
217
|
-
|
|
218
|
-
the same as what `gen` builds.
|
|
68
|
+
See the [endpoint example](./examples/endpoint.ts) for a complete Schema.
|
|
219
69
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
```ts
|
|
223
|
-
const port = Grammar.integer.pipe(
|
|
224
|
-
Grammar.prefix(":"),
|
|
225
|
-
Grammar.optional(),
|
|
226
|
-
Grammar.defaulted(443),
|
|
227
|
-
)
|
|
228
|
-
|
|
229
|
-
const pair = Grammar.tuple(
|
|
230
|
-
Grammar.integer,
|
|
231
|
-
Grammar.integer.pipe(Grammar.prefix(",")),
|
|
232
|
-
)
|
|
233
|
-
```
|
|
70
|
+
## Main building blocks
|
|
234
71
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
72
|
+
| Purpose | Combinators |
|
|
73
|
+
| --------------------------- | -------------------------------------------------------- |
|
|
74
|
+
| Text | `literal`, `regex`, `integer`, `take`, `repeat` |
|
|
75
|
+
| Sequences and products | `gen`, `seq`, `struct`, `tuple` |
|
|
76
|
+
| Delimiters | `prefix`, `suffix`, `between`, `wrap` |
|
|
77
|
+
| Repetition and options | `optional`, `many`, `sepBy` |
|
|
78
|
+
| Alternatives | `choice`, `taggedChoice`, `match`, `matchValue` |
|
|
79
|
+
| Value conversion | `transform`, `transformOrFail`, `decodeTo`, `as`, `flag` |
|
|
80
|
+
| Defaults and ignored values | `defaulted`, `skip` |
|
|
81
|
+
| Whitespace | `lexeme`, `symbol`, `space`, `spaces`, `trivia` |
|
|
82
|
+
| Recursion | `suspend` |
|
|
239
83
|
|
|
240
|
-
|
|
84
|
+
Most delimiter and repetition combinators support data-first and data-last
|
|
85
|
+
calls, so they also work with `pipe`.
|
|
241
86
|
|
|
242
|
-
|
|
243
|
-
returns a short name for a grammar.
|
|
87
|
+
## Results, errors, and rendering
|
|
244
88
|
|
|
245
|
-
|
|
246
|
-
|
|
89
|
+
`parse` and `print` return `Result` values. Parse errors report the furthest
|
|
90
|
+
text position, the expected forms, and the line and column. Print errors contain
|
|
91
|
+
a `PrintIssue` tree with paths, missing fields, failed branches, and value
|
|
92
|
+
mismatches. `PrintError.format` converts that tree to text.
|
|
247
93
|
|
|
248
|
-
|
|
94
|
+
`render` describes a complete grammar. `describe` returns a short grammar name.
|
|
249
95
|
|
|
250
|
-
|
|
251
|
-
that position, plus line and column.
|
|
96
|
+
## More examples
|
|
252
97
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
98
|
+
- [Postgres connection string](./examples/connection-string.ts): optional parts,
|
|
99
|
+
query parameters, Schema checks, encoding, and round trips
|
|
100
|
+
- [JSON](./examples/json.ts): a recursive grammar and Schema codec
|
|
101
|
+
- [Scheme](./examples/scheme.ts): recursive expressions, tokens, and canonical
|
|
102
|
+
whitespace
|
|
103
|
+
- [GitHub search](./examples/github-search.ts): a larger search-query DSL
|
|
104
|
+
- [IP address](./examples/ip.ts): transforms and Schema refinements
|
|
105
|
+
- [Printing showcase](./examples/printing.ts): parsing, printing, rendering, and
|
|
106
|
+
print failures
|
package/dist/ast.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type GrammarInternal, type Value } from "./core.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A JSON-shaped mirror of a grammar, produced by `toAst`. Scopes become stable
|
|
4
|
+
* names (`scope0`, `scope1`, …), a recursive `Suspend` is defined once and
|
|
5
|
+
* referenced by id at every other occurrence, and functions are described by
|
|
6
|
+
* name instead of being embedded. Constant values are kept as given, so the
|
|
7
|
+
* result is serializable for every value a grammar can legally hold.
|
|
8
|
+
*/
|
|
9
|
+
export interface RefAst {
|
|
10
|
+
readonly _tag: "Ref";
|
|
11
|
+
readonly scope: string;
|
|
12
|
+
readonly slot: number;
|
|
13
|
+
readonly name?: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
export type ExprAst = RefAst | {
|
|
16
|
+
readonly _tag: "Prop";
|
|
17
|
+
readonly object: ExprAst;
|
|
18
|
+
readonly key: string | number;
|
|
19
|
+
};
|
|
20
|
+
export type PatternAst = RefAst | {
|
|
21
|
+
readonly _tag: "Const";
|
|
22
|
+
readonly value: Value;
|
|
23
|
+
} | {
|
|
24
|
+
readonly _tag: "Object";
|
|
25
|
+
readonly fields: ReadonlyArray<readonly [string, PatternAst]>;
|
|
26
|
+
} | {
|
|
27
|
+
readonly _tag: "Array";
|
|
28
|
+
readonly items: ReadonlyArray<PatternAst>;
|
|
29
|
+
};
|
|
30
|
+
export interface MatchCaseAst {
|
|
31
|
+
readonly key: string | number | boolean;
|
|
32
|
+
readonly grammar: GrammarAst;
|
|
33
|
+
}
|
|
34
|
+
export type StepAst = {
|
|
35
|
+
readonly _tag: "Silent";
|
|
36
|
+
readonly grammar: GrammarAst;
|
|
37
|
+
} | {
|
|
38
|
+
readonly _tag: "Bind";
|
|
39
|
+
readonly slot: number;
|
|
40
|
+
readonly name?: string | undefined;
|
|
41
|
+
readonly grammar: GrammarAst;
|
|
42
|
+
};
|
|
43
|
+
export type GrammarAst = {
|
|
44
|
+
readonly _tag: "Literal";
|
|
45
|
+
readonly value: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly _tag: "Regex";
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly source: string;
|
|
50
|
+
readonly flags: string;
|
|
51
|
+
} | {
|
|
52
|
+
readonly _tag: "Gen";
|
|
53
|
+
readonly scope: string;
|
|
54
|
+
readonly slotCount: number;
|
|
55
|
+
readonly steps: ReadonlyArray<StepAst>;
|
|
56
|
+
readonly result: PatternAst;
|
|
57
|
+
} | {
|
|
58
|
+
readonly _tag: "Wrap";
|
|
59
|
+
readonly open: GrammarAst;
|
|
60
|
+
readonly inner: GrammarAst;
|
|
61
|
+
readonly close: GrammarAst;
|
|
62
|
+
} | {
|
|
63
|
+
readonly _tag: "Choice";
|
|
64
|
+
readonly options: ReadonlyArray<GrammarAst>;
|
|
65
|
+
} | {
|
|
66
|
+
readonly _tag: "Many";
|
|
67
|
+
readonly inner: GrammarAst;
|
|
68
|
+
readonly sep: GrammarAst;
|
|
69
|
+
readonly min: number;
|
|
70
|
+
readonly max: number | "∞";
|
|
71
|
+
} | {
|
|
72
|
+
readonly _tag: "Optional";
|
|
73
|
+
readonly inner: GrammarAst;
|
|
74
|
+
} | {
|
|
75
|
+
readonly _tag: "Transform";
|
|
76
|
+
readonly inner: GrammarAst;
|
|
77
|
+
readonly decode: string;
|
|
78
|
+
readonly encode: string;
|
|
79
|
+
readonly is?: string | undefined;
|
|
80
|
+
readonly name?: string | undefined;
|
|
81
|
+
} | {
|
|
82
|
+
readonly _tag: "Skip";
|
|
83
|
+
readonly inner: GrammarAst;
|
|
84
|
+
readonly printAs: Value;
|
|
85
|
+
readonly show: boolean;
|
|
86
|
+
} | {
|
|
87
|
+
readonly _tag: "Label";
|
|
88
|
+
readonly name: string;
|
|
89
|
+
readonly inner: GrammarAst;
|
|
90
|
+
} | {
|
|
91
|
+
readonly _tag: "Suspend";
|
|
92
|
+
readonly id: number;
|
|
93
|
+
readonly name?: string | undefined;
|
|
94
|
+
readonly body: GrammarAst;
|
|
95
|
+
} | {
|
|
96
|
+
readonly _tag: "SuspendRef";
|
|
97
|
+
readonly id: number;
|
|
98
|
+
readonly name?: string | undefined;
|
|
99
|
+
} | {
|
|
100
|
+
readonly _tag: "Match";
|
|
101
|
+
readonly scrutinee: ExprAst;
|
|
102
|
+
readonly cases: ReadonlyArray<MatchCaseAst>;
|
|
103
|
+
} | {
|
|
104
|
+
readonly _tag: "Take";
|
|
105
|
+
readonly count: ExprAst;
|
|
106
|
+
} | {
|
|
107
|
+
readonly _tag: "RepeatExact";
|
|
108
|
+
readonly count: ExprAst;
|
|
109
|
+
readonly inner: GrammarAst;
|
|
110
|
+
};
|
|
111
|
+
/** Reflects a grammar into a plain, JSON-shaped tree. */
|
|
112
|
+
export declare const toAst: (grammar: GrammarInternal) => GrammarAst;
|
|
113
|
+
/** Renders a grammar as an indented node tree, one line per AST node. */
|
|
114
|
+
export declare const renderAst: (grammar: GrammarInternal) => string;
|
|
115
|
+
//# sourceMappingURL=ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,eAAe,EAOpB,KAAK,KAAK,EACX,MAAM,WAAW,CAAA;AAIlB;;;;;;GAMG;AACH,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;IACpB,QAAQ,CAAC,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,aAAa,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAA;AAyJzF,yDAAyD;AACzD,eAAO,MAAM,KAAK,YAAa,eAAe,KAAG,UAC4B,CAAA;AA0H7E,yEAAyE;AACzE,eAAO,MAAM,SAAS,YAAa,eAAe,KAAG,MAAoC,CAAA"}
|
package/dist/ast.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { Predicate } from "effect";
|
|
2
|
+
import { nodeOf, resolve, } from "./core.js";
|
|
3
|
+
import { preview } from "./errors.js";
|
|
4
|
+
import { nameBindings, namesFor } from "./render.js";
|
|
5
|
+
const scopeName = (context, scope) => {
|
|
6
|
+
const existing = context.scopes.get(scope);
|
|
7
|
+
if (existing !== undefined)
|
|
8
|
+
return existing;
|
|
9
|
+
const name = `scope${context.scopes.size}`;
|
|
10
|
+
context.scopes.set(scope, name);
|
|
11
|
+
return name;
|
|
12
|
+
};
|
|
13
|
+
const refAst = (expr, context) => {
|
|
14
|
+
const scope = scopeName(context, expr.scope);
|
|
15
|
+
const name = context.names.get(expr.scope)?.get(expr.slot);
|
|
16
|
+
if (name === undefined)
|
|
17
|
+
return { _tag: "Ref", scope, slot: expr.slot };
|
|
18
|
+
return { _tag: "Ref", scope, slot: expr.slot, name };
|
|
19
|
+
};
|
|
20
|
+
const keyAst = (key) => Predicate.isString(key) || Predicate.isNumber(key) ? key : preview(key);
|
|
21
|
+
const exprAst = (expr, context) => expr._tag === "Ref"
|
|
22
|
+
? refAst(expr, context)
|
|
23
|
+
: { _tag: "Prop", object: exprAst(expr.object, context), key: keyAst(expr.key) };
|
|
24
|
+
const patternAst = (pattern, context) => {
|
|
25
|
+
switch (pattern._tag) {
|
|
26
|
+
case "Ref":
|
|
27
|
+
return refAst(pattern, context);
|
|
28
|
+
case "Const":
|
|
29
|
+
return { _tag: "Const", value: pattern.value };
|
|
30
|
+
case "Object":
|
|
31
|
+
return {
|
|
32
|
+
_tag: "Object",
|
|
33
|
+
fields: pattern.fields.map(([key, field]) => [key, patternAst(field, context)]),
|
|
34
|
+
};
|
|
35
|
+
case "Array":
|
|
36
|
+
return { _tag: "Array", items: pattern.items.map((item) => patternAst(item, context)) };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const fnName = (f) => (f.name === "" ? "<anonymous>" : f.name);
|
|
40
|
+
const stepAst = (step, context, names) => step._tag === "Silent"
|
|
41
|
+
? { _tag: "Silent", grammar: walk(step.grammar, context) }
|
|
42
|
+
: {
|
|
43
|
+
_tag: "Bind",
|
|
44
|
+
slot: step.slot,
|
|
45
|
+
name: names.get(step.slot),
|
|
46
|
+
grammar: walk(step.grammar, context),
|
|
47
|
+
};
|
|
48
|
+
const walk = (grammar, context) => {
|
|
49
|
+
const node = nodeOf(grammar);
|
|
50
|
+
switch (node._tag) {
|
|
51
|
+
case "Literal":
|
|
52
|
+
return { _tag: "Literal", value: node.value };
|
|
53
|
+
case "Regex":
|
|
54
|
+
return { _tag: "Regex", name: node.name, source: node.re.source, flags: node.re.flags };
|
|
55
|
+
case "Gen": {
|
|
56
|
+
const names = namesFor(context.names, node.scope);
|
|
57
|
+
nameBindings(node.result, undefined, node.scope, names);
|
|
58
|
+
const scope = scopeName(context, node.scope);
|
|
59
|
+
return {
|
|
60
|
+
_tag: "Gen",
|
|
61
|
+
scope,
|
|
62
|
+
slotCount: node.slotCount,
|
|
63
|
+
steps: node.steps.map((step) => stepAst(step, context, names)),
|
|
64
|
+
result: patternAst(node.result, context),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
case "Wrap":
|
|
68
|
+
return {
|
|
69
|
+
_tag: "Wrap",
|
|
70
|
+
open: walk(node.open, context),
|
|
71
|
+
inner: walk(node.inner, context),
|
|
72
|
+
close: walk(node.close, context),
|
|
73
|
+
};
|
|
74
|
+
case "Choice":
|
|
75
|
+
return { _tag: "Choice", options: node.options.map((option) => walk(option, context)) };
|
|
76
|
+
case "Many":
|
|
77
|
+
return {
|
|
78
|
+
_tag: "Many",
|
|
79
|
+
inner: walk(node.inner, context),
|
|
80
|
+
sep: walk(node.sep, context),
|
|
81
|
+
min: node.min,
|
|
82
|
+
max: node.max === Number.POSITIVE_INFINITY ? "∞" : node.max,
|
|
83
|
+
};
|
|
84
|
+
case "Optional":
|
|
85
|
+
return { _tag: "Optional", inner: walk(node.inner, context) };
|
|
86
|
+
case "Transform": {
|
|
87
|
+
const inner = walk(node.inner, context);
|
|
88
|
+
if (node.is === undefined) {
|
|
89
|
+
return {
|
|
90
|
+
_tag: "Transform",
|
|
91
|
+
inner,
|
|
92
|
+
decode: fnName(node.decode),
|
|
93
|
+
encode: fnName(node.encode),
|
|
94
|
+
name: node.name,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
_tag: "Transform",
|
|
99
|
+
inner,
|
|
100
|
+
decode: fnName(node.decode),
|
|
101
|
+
encode: fnName(node.encode),
|
|
102
|
+
is: fnName(node.is),
|
|
103
|
+
name: node.name,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
case "Skip":
|
|
107
|
+
return {
|
|
108
|
+
_tag: "Skip",
|
|
109
|
+
inner: walk(node.inner, context),
|
|
110
|
+
printAs: node.printAs,
|
|
111
|
+
show: node.show,
|
|
112
|
+
};
|
|
113
|
+
case "Label":
|
|
114
|
+
return { _tag: "Label", name: node.name, inner: walk(node.inner, context) };
|
|
115
|
+
case "Suspend": {
|
|
116
|
+
const existing = context.suspends.get(node);
|
|
117
|
+
if (existing !== undefined)
|
|
118
|
+
return { _tag: "SuspendRef", id: existing, name: node.name };
|
|
119
|
+
const id = context.suspends.size;
|
|
120
|
+
context.suspends.set(node, id);
|
|
121
|
+
return { _tag: "Suspend", id, name: node.name, body: walk(resolve(node), context) };
|
|
122
|
+
}
|
|
123
|
+
case "Match":
|
|
124
|
+
return {
|
|
125
|
+
_tag: "Match",
|
|
126
|
+
scrutinee: exprAst(node.scrutinee, context),
|
|
127
|
+
cases: node.cases.map((matchCase) => ({
|
|
128
|
+
key: matchCase.key,
|
|
129
|
+
grammar: walk(matchCase.grammar, context),
|
|
130
|
+
})),
|
|
131
|
+
};
|
|
132
|
+
case "Take":
|
|
133
|
+
return { _tag: "Take", count: exprAst(node.count, context) };
|
|
134
|
+
case "RepeatExact":
|
|
135
|
+
return {
|
|
136
|
+
_tag: "RepeatExact",
|
|
137
|
+
count: exprAst(node.count, context),
|
|
138
|
+
inner: walk(node.inner, context),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
/** Reflects a grammar into a plain, JSON-shaped tree. */
|
|
143
|
+
export const toAst = (grammar) => walk(grammar, { scopes: new Map(), names: new Map(), suspends: new Map() });
|
|
144
|
+
const formatValue = (value) => Predicate.isString(value) ? JSON.stringify(value) : preview(value);
|
|
145
|
+
const refText = (ref) => ref.name ?? `$${ref.slot}`;
|
|
146
|
+
const exprText = (expr) => {
|
|
147
|
+
if (expr._tag === "Ref")
|
|
148
|
+
return refText(expr);
|
|
149
|
+
const object = exprText(expr.object);
|
|
150
|
+
return Predicate.isString(expr.key) && /^[A-Za-z_$][\w$]*$/.test(expr.key)
|
|
151
|
+
? `${object}.${expr.key}`
|
|
152
|
+
: `${object}[${preview(expr.key)}]`;
|
|
153
|
+
};
|
|
154
|
+
const patternText = (pattern) => {
|
|
155
|
+
switch (pattern._tag) {
|
|
156
|
+
case "Ref":
|
|
157
|
+
return refText(pattern);
|
|
158
|
+
case "Const":
|
|
159
|
+
return formatValue(pattern.value);
|
|
160
|
+
case "Object":
|
|
161
|
+
return `{ ${pattern.fields.map(([key, field]) => `${key}: ${patternText(field)}`).join(", ")} }`;
|
|
162
|
+
case "Array":
|
|
163
|
+
return `[${pattern.items.map(patternText).join(", ")}]`;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const boundsText = (min, max) => {
|
|
167
|
+
if (max === "∞")
|
|
168
|
+
return min === 0 ? "*" : min === 1 ? "+" : `{${min},}`;
|
|
169
|
+
return min === max ? `{${min}}` : `{${min},${max}}`;
|
|
170
|
+
};
|
|
171
|
+
const headerOf = (ast) => {
|
|
172
|
+
switch (ast._tag) {
|
|
173
|
+
case "Literal":
|
|
174
|
+
return `Literal ${formatValue(ast.value)}`;
|
|
175
|
+
case "Regex":
|
|
176
|
+
return `Regex ${ast.name} /${ast.source}/${ast.flags}`;
|
|
177
|
+
case "Gen":
|
|
178
|
+
return `Gen ${ast.scope} → ${patternText(ast.result)}`;
|
|
179
|
+
case "Wrap":
|
|
180
|
+
return "Wrap";
|
|
181
|
+
case "Choice":
|
|
182
|
+
return "Choice";
|
|
183
|
+
case "Many":
|
|
184
|
+
return `Many ${boundsText(ast.min, ast.max)}`;
|
|
185
|
+
case "Optional":
|
|
186
|
+
return "Optional";
|
|
187
|
+
case "Transform":
|
|
188
|
+
return ast.name === undefined ? "Transform" : `Transform ${ast.name}`;
|
|
189
|
+
case "Skip":
|
|
190
|
+
return ast.show ? "Skip" : "Skip (hidden)";
|
|
191
|
+
case "Label":
|
|
192
|
+
return `Label ${ast.name}`;
|
|
193
|
+
case "Suspend":
|
|
194
|
+
return ast.name === undefined ? `Suspend #${ast.id}` : `Suspend #${ast.id} ${ast.name}`;
|
|
195
|
+
case "SuspendRef":
|
|
196
|
+
return ast.name === undefined ? `SuspendRef #${ast.id}` : `SuspendRef #${ast.id} ${ast.name}`;
|
|
197
|
+
case "Match":
|
|
198
|
+
return `Match ${exprText(ast.scrutinee)}`;
|
|
199
|
+
case "Take":
|
|
200
|
+
return `Take ${exprText(ast.count)}`;
|
|
201
|
+
case "RepeatExact":
|
|
202
|
+
return `RepeatExact ${exprText(ast.count)}`;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const childrenOf = (ast) => {
|
|
206
|
+
switch (ast._tag) {
|
|
207
|
+
case "Gen":
|
|
208
|
+
return ast.steps.map((step) => step._tag === "Bind"
|
|
209
|
+
? [step.name ?? `bind #${step.slot}`, step.grammar]
|
|
210
|
+
: [undefined, step.grammar]);
|
|
211
|
+
case "Wrap":
|
|
212
|
+
return [
|
|
213
|
+
[undefined, ast.open],
|
|
214
|
+
[undefined, ast.inner],
|
|
215
|
+
[undefined, ast.close],
|
|
216
|
+
];
|
|
217
|
+
case "Choice":
|
|
218
|
+
return ast.options.map((option) => [undefined, option]);
|
|
219
|
+
case "Many":
|
|
220
|
+
return [[undefined, ast.inner], ["sep", ast.sep]];
|
|
221
|
+
case "Optional":
|
|
222
|
+
case "Transform":
|
|
223
|
+
case "Skip":
|
|
224
|
+
case "Label":
|
|
225
|
+
case "RepeatExact":
|
|
226
|
+
return [[undefined, ast.inner]];
|
|
227
|
+
case "Suspend":
|
|
228
|
+
return [[undefined, ast.body]];
|
|
229
|
+
case "Match":
|
|
230
|
+
return ast.cases.map((matchCase) => [`${formatValue(matchCase.key)} =>`, matchCase.grammar]);
|
|
231
|
+
case "Literal":
|
|
232
|
+
case "Regex":
|
|
233
|
+
case "Take":
|
|
234
|
+
case "SuspendRef":
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
const renderTree = (ast) => {
|
|
239
|
+
const lines = [headerOf(ast)];
|
|
240
|
+
const visit = (node, padding) => {
|
|
241
|
+
const children = childrenOf(node);
|
|
242
|
+
children.forEach(([label, child], index) => {
|
|
243
|
+
const last = index === children.length - 1;
|
|
244
|
+
lines.push(`${padding}${last ? "└─ " : "├─ "}${label === undefined ? "" : `${label} `}${headerOf(child)}`);
|
|
245
|
+
visit(child, `${padding}${last ? " " : "│ "}`);
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
visit(ast, "");
|
|
249
|
+
return lines.join("\n");
|
|
250
|
+
};
|
|
251
|
+
/** Renders a grammar as an indented node tree, one line per AST node. */
|
|
252
|
+
export const renderAst = (grammar) => renderTree(toAst(grammar));
|
|
253
|
+
//# sourceMappingURL=ast.js.map
|
package/dist/ast.js.map
ADDED
|
@@ -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AC,OAAO,CAAC,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { as, between, choice, decodeTo, type DecodeToOptions, defaulted, empty,
|
|
|
4
4
|
export { parse } from "./parse.ts";
|
|
5
5
|
export { print } from "./print.ts";
|
|
6
6
|
export { describe, render } from "./render.ts";
|
|
7
|
-
export {
|
|
7
|
+
export { codec } from "./schema.ts";
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AACrE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzE,OAAO,EACL,EAAE,EACF,OAAO,EACP,MAAM,EACN,QAAQ,EACR,KAAK,eAAe,EACpB,SAAS,EACT,KAAK,EACL,IAAI,EACJ,GAAG,EACH,KAAK,UAAU,EACf,GAAG,EACH,OAAO,EACP,KAAK,EACL,MAAM,EACN,OAAO,EACP,IAAI,EACJ,KAAK,EACL,UAAU,EACV,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,aAAa,EAClB,KAAK,EACL,GAAG,EACH,IAAI,EACJ,KAAK,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,MAAM,EACN,KAAK,EACL,IAAI,GACL,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AACrE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzE,OAAO,EACL,EAAE,EACF,OAAO,EACP,MAAM,EACN,QAAQ,EACR,KAAK,eAAe,EACpB,SAAS,EACT,KAAK,EACL,IAAI,EACJ,GAAG,EACH,KAAK,UAAU,EACf,GAAG,EACH,OAAO,EACP,KAAK,EACL,MAAM,EACN,OAAO,EACP,IAAI,EACJ,KAAK,EACL,UAAU,EACV,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,aAAa,EAClB,KAAK,EACL,GAAG,EACH,IAAI,EACJ,KAAK,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,MAAM,EACN,KAAK,EACL,IAAI,GACL,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,5 +3,5 @@ export { as, between, choice, decodeTo, defaulted, empty, flag, gen, get, intege
|
|
|
3
3
|
export { parse } from "./parse.js";
|
|
4
4
|
export { print } from "./print.js";
|
|
5
5
|
export { describe, render } from "./render.js";
|
|
6
|
-
export {
|
|
6
|
+
export { codec } from "./schema.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAA;AAErE,OAAO,EACL,EAAE,EACF,OAAO,EACP,MAAM,EACN,QAAQ,EAER,SAAS,EACT,KAAK,EACL,IAAI,EACJ,GAAG,EAEH,GAAG,EACH,OAAO,EACP,KAAK,EACL,MAAM,EACN,OAAO,EACP,IAAI,EACJ,KAAK,EACL,UAAU,EACV,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,EAEN,KAAK,EACL,GAAG,EACH,IAAI,EACJ,KAAK,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,eAAe,EAGf,MAAM,EACN,KAAK,EACL,IAAI,GACL,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAA;AAErE,OAAO,EACL,EAAE,EACF,OAAO,EACP,MAAM,EACN,QAAQ,EAER,SAAS,EACT,KAAK,EACL,IAAI,EACJ,GAAG,EAEH,GAAG,EACH,OAAO,EACP,KAAK,EACL,MAAM,EACN,OAAO,EACP,IAAI,EACJ,KAAK,EACL,UAAU,EACV,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,EAEN,KAAK,EACL,GAAG,EACH,IAAI,EACJ,KAAK,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,eAAe,EAGf,MAAM,EACN,KAAK,EACL,IAAI,GACL,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import type { Grammar } from "./core.ts";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const codec: <S extends Schema.Top, A extends S["Encoded"]>(grammar: Grammar<A>, target: S, options?: {
|
|
4
4
|
readonly identifier?: string;
|
|
5
5
|
}) => Schema.decodeTo<S, Schema.String, never, never>;
|
|
6
6
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAqC,MAAM,QAAQ,CAAA;AAE1E,OAAO,KAAK,EAAE,OAAO,EAAS,MAAM,WAAW,CAAA;AAc/C,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAqC,MAAM,QAAQ,CAAA;AAE1E,OAAO,KAAK,EAAE,OAAO,EAAS,MAAM,WAAW,CAAA;AAc/C,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,WACvD,OAAO,CAAC,CAAC,CAAC,UACX,CAAC,YACC;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,oDAiBzC,CAAA"}
|
package/dist/schema.js
CHANGED
|
@@ -9,7 +9,7 @@ const printIssueToSchema = (actual, issue) => {
|
|
|
9
9
|
}
|
|
10
10
|
return new SchemaIssue.InvalidValue({ message: PrintError.format(issue) }, actual);
|
|
11
11
|
};
|
|
12
|
-
export const
|
|
12
|
+
export const codec = (grammar, target, options) => Schema.String.pipe(Schema.decodeTo(target, SchemaTransformation.transformOrFail({
|
|
13
13
|
decode: (text) => Effect.fromResult(parse(grammar, text)).pipe(Effect.mapError(({ message }) => new SchemaIssue.InvalidValue({ message }, text))),
|
|
14
14
|
encode: (value) => Effect.fromResult(printUnknown(grammar, value)).pipe(Effect.mapError((error) => printIssueToSchema(value, error.issue))),
|
|
15
15
|
})), Schema.annotate({ ...options, description: render(grammar) }));
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAI1E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,MAAM,kBAAkB,GAAG,CAAC,MAAa,EAAE,KAAiB,EAAqB,EAAE;IACjF,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,KA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