@thomasfosterau/effect-parse 0.1.0 → 0.2.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 +247 -230
- package/dist/Ascii.d.ts +32 -53
- package/dist/Ascii.d.ts.map +1 -1
- package/dist/Ascii.js +576 -571
- package/dist/Ascii.js.map +1 -1
- package/dist/Binary.d.ts +6 -29
- package/dist/Binary.d.ts.map +1 -1
- package/dist/Binary.js +129 -116
- package/dist/Binary.js.map +1 -1
- package/dist/Bits.d.ts +4 -2
- package/dist/Bits.d.ts.map +1 -1
- package/dist/Bits.js +121 -123
- package/dist/Bits.js.map +1 -1
- package/dist/Compiler.d.ts +39 -0
- package/dist/Compiler.d.ts.map +1 -0
- package/dist/Compiler.js +48 -0
- package/dist/Compiler.js.map +1 -0
- package/dist/Encoding.d.ts +29 -46
- package/dist/Encoding.d.ts.map +1 -1
- package/dist/Encoding.js +76 -75
- package/dist/Encoding.js.map +1 -1
- package/dist/Expression.d.ts +15 -49
- package/dist/Expression.d.ts.map +1 -1
- package/dist/Expression.js +143 -131
- package/dist/Expression.js.map +1 -1
- package/dist/Input.d.ts +206 -177
- package/dist/Input.d.ts.map +1 -1
- package/dist/Input.js +317 -299
- package/dist/Input.js.map +1 -1
- package/dist/Nom.d.ts +44 -84
- package/dist/Nom.d.ts.map +1 -1
- package/dist/Nom.js +423 -453
- package/dist/Nom.js.map +1 -1
- package/dist/ParseError.d.ts +54 -49
- package/dist/ParseError.d.ts.map +1 -1
- package/dist/ParseError.js +233 -275
- package/dist/ParseError.js.map +1 -1
- package/dist/Parser.d.ts +345 -313
- package/dist/Parser.d.ts.map +1 -1
- package/dist/Parser.js +2010 -1802
- package/dist/Parser.js.map +1 -1
- package/dist/ParserSchema.d.ts +8 -7
- package/dist/ParserSchema.d.ts.map +1 -1
- package/dist/ParserSchema.js +49 -49
- package/dist/ParserSchema.js.map +1 -1
- package/dist/ParserStream.d.ts +26 -20
- package/dist/ParserStream.d.ts.map +1 -1
- package/dist/ParserStream.js +267 -255
- package/dist/ParserStream.js.map +1 -1
- package/dist/Syntax.d.ts +401 -0
- package/dist/Syntax.d.ts.map +1 -0
- package/dist/Syntax.js +717 -0
- package/dist/Syntax.js.map +1 -0
- package/dist/Text.d.ts +98 -134
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +534 -496
- package/dist/Text.js.map +1 -1
- package/dist/Token.d.ts +60 -42
- package/dist/Token.d.ts.map +1 -1
- package/dist/Token.js +331 -265
- package/dist/Token.js.map +1 -1
- package/dist/index.d.ts +16 -17
- package/dist/index.js +16 -17
- package/dist/internal/compiler/closure.d.ts +14 -16
- package/dist/internal/compiler/closure.d.ts.map +1 -1
- package/dist/internal/compiler/closure.js +1458 -1637
- package/dist/internal/compiler/closure.js.map +1 -1
- package/dist/internal/compiler/entries.d.ts +11 -11
- package/dist/internal/compiler/entries.d.ts.map +1 -1
- package/dist/internal/compiler/entries.js +36 -26
- package/dist/internal/compiler/entries.js.map +1 -1
- package/dist/internal/compiler/first.d.ts +19 -19
- package/dist/internal/compiler/first.d.ts.map +1 -1
- package/dist/internal/compiler/first.js +251 -227
- package/dist/internal/compiler/first.js.map +1 -1
- package/dist/internal/compiler/jit.d.ts +6 -17
- package/dist/internal/compiler/jit.d.ts.map +1 -1
- package/dist/internal/compiler/jit.js +860 -988
- package/dist/internal/compiler/jit.js.map +1 -1
- package/dist/internal/compiler/registry.d.ts +20 -21
- package/dist/internal/compiler/registry.d.ts.map +1 -1
- package/dist/internal/compiler/registry.js +21 -41
- package/dist/internal/compiler/registry.js.map +1 -1
- package/dist/internal/compiler/sets.d.ts +9 -13
- package/dist/internal/compiler/sets.d.ts.map +1 -1
- package/dist/internal/compiler/sets.js +76 -73
- package/dist/internal/compiler/sets.js.map +1 -1
- package/dist/internal/entries.d.ts +3 -3
- package/dist/internal/entries.d.ts.map +1 -1
- package/dist/internal/entries.js +38 -30
- package/dist/internal/entries.js.map +1 -1
- package/dist/internal/node.d.ts +177 -173
- package/dist/internal/node.d.ts.map +1 -1
- package/dist/internal/node.js +77 -66
- package/dist/internal/node.js.map +1 -1
- package/dist/internal/numbers.d.ts +7 -8
- package/dist/internal/numbers.d.ts.map +1 -1
- package/dist/internal/numbers.js +246 -276
- package/dist/internal/numbers.js.map +1 -1
- package/dist/internal/resume.d.ts +6 -24
- package/dist/internal/resume.d.ts.map +1 -1
- package/dist/internal/resume.js +30 -29
- package/dist/internal/resume.js.map +1 -1
- package/dist/internal/run.d.ts +15 -0
- package/dist/internal/run.d.ts.map +1 -0
- package/dist/internal/run.js +36 -0
- package/dist/internal/run.js.map +1 -0
- package/dist/internal/stack.d.ts +16 -0
- package/dist/internal/stack.d.ts.map +1 -0
- package/dist/internal/stack.js +26 -0
- package/dist/internal/stack.js.map +1 -0
- package/dist/internal/syntax.d.ts +146 -0
- package/dist/internal/syntax.d.ts.map +1 -0
- package/dist/internal/syntax.js +305 -0
- package/dist/internal/syntax.js.map +1 -0
- package/dist/internal/text.d.ts +10 -2
- package/dist/internal/text.d.ts.map +1 -1
- package/dist/internal/text.js +295 -345
- package/dist/internal/text.js.map +1 -1
- package/dist/internal/tokens.d.ts +25 -30
- package/dist/internal/tokens.d.ts.map +1 -1
- package/dist/internal/tokens.js +369 -363
- package/dist/internal/tokens.js.map +1 -1
- package/package.json +42 -28
- package/src/Ascii.ts +278 -187
- package/src/Binary.ts +150 -44
- package/src/Bits.ts +6 -3
- package/src/Compiler.ts +98 -0
- package/src/Expression.ts +10 -5
- package/src/Input.ts +106 -28
- package/src/Nom.ts +4 -3
- package/src/ParseError.ts +48 -51
- package/src/Parser.ts +1163 -795
- package/src/ParserStream.ts +104 -80
- package/src/Syntax.ts +900 -0
- package/src/Text.ts +272 -187
- package/src/Token.ts +180 -87
- package/src/index.ts +2 -0
- package/src/internal/compiler/closure.ts +121 -88
- package/src/internal/compiler/entries.ts +21 -8
- package/src/internal/compiler/first.ts +17 -15
- package/src/internal/compiler/jit.ts +360 -157
- package/src/internal/compiler/registry.ts +12 -33
- package/src/internal/compiler/sets.ts +17 -11
- package/src/internal/entries.ts +4 -2
- package/src/internal/node.ts +51 -37
- package/src/internal/numbers.ts +22 -20
- package/src/internal/resume.ts +8 -4
- package/src/internal/run.ts +41 -0
- package/src/internal/stack.ts +36 -0
- package/src/internal/syntax.ts +421 -0
- package/src/internal/text.ts +32 -25
- package/src/internal/tokens.ts +96 -51
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* Skipping a parser that is certain to fail also skips the callbacks it
|
|
16
16
|
* would have run before failing, which is why callbacks must be pure.
|
|
17
17
|
*/
|
|
18
|
+
import * as Predicate from "effect/Predicate"
|
|
18
19
|
import type { Encoding } from "../../Encoding.js"
|
|
19
20
|
import type { Node, ParserLike } from "../node.js"
|
|
20
21
|
import { nodeOf } from "../node.js"
|
|
@@ -23,8 +24,8 @@ import type { CharSet } from "./sets.js"
|
|
|
23
24
|
import { kindOfEncoding, reachesAbove, TableSize, textSet, tokenSet } from "./sets.js"
|
|
24
25
|
|
|
25
26
|
export const Strict = 0
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
const Optional = 1
|
|
28
|
+
const Unknown = 2
|
|
28
29
|
|
|
29
30
|
export interface First {
|
|
30
31
|
readonly mode: 0 | 1 | 2
|
|
@@ -32,8 +33,8 @@ export interface First {
|
|
|
32
33
|
readonly high: boolean
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
const none = new Uint8Array(TableSize)
|
|
36
|
-
const all = new Uint8Array(TableSize).fill(1)
|
|
36
|
+
const none = /*#__PURE__*/ new Uint8Array(TableSize)
|
|
37
|
+
const all = /*#__PURE__*/ new Uint8Array(TableSize).fill(1)
|
|
37
38
|
|
|
38
39
|
const unknown: First = { mode: Unknown, units: all, high: true }
|
|
39
40
|
const emptyOptional: First = { mode: Optional, units: none, high: false }
|
|
@@ -42,14 +43,14 @@ const anyUnit: First = { mode: Strict, units: all, high: true }
|
|
|
42
43
|
|
|
43
44
|
const union = (a: First, b: First, mode: 0 | 1 | 2): First => {
|
|
44
45
|
const units = new Uint8Array(TableSize)
|
|
45
|
-
for (let i = 0; i < TableSize; i++) units[i] = a.units[i]
|
|
46
|
+
for (let i = 0; i < TableSize; i++) units[i] = a.units[i] | b.units[i]
|
|
46
47
|
return { mode, units, high: a.high || b.high }
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
const withMode = (f: First, mode: 0 | 1 | 2): First => f.mode === mode ? f : { ...f, mode }
|
|
50
|
+
const withMode = (f: First, mode: 0 | 1 | 2): First => (f.mode === mode ? f : { ...f, mode })
|
|
50
51
|
|
|
51
|
-
const lowerAscii = (c: number): number => c >= 65 && c <= 90 ? c + 32 : c
|
|
52
|
-
const upperAscii = (c: number): number => c >= 97 && c <= 122 ? c - 32 : c
|
|
52
|
+
const lowerAscii = (c: number): number => (c >= 65 && c <= 90 ? c + 32 : c)
|
|
53
|
+
const upperAscii = (c: number): number => (c >= 97 && c <= 122 ? c - 32 : c)
|
|
53
54
|
|
|
54
55
|
const ofUnits = (codes: ReadonlyArray<number>, mode: 0 | 1 | 2 = Strict): First => {
|
|
55
56
|
const units = new Uint8Array(TableSize)
|
|
@@ -111,14 +112,14 @@ export class FirstSets {
|
|
|
111
112
|
if (node.caseless) return lit.length === 0 ? unknown : anyUnit
|
|
112
113
|
const encoded = node.encoding.encode(lit as string)
|
|
113
114
|
if (encoded.length === 0) return emptyOptional
|
|
114
|
-
return ofUnits([
|
|
115
|
+
return ofUnits([Predicate.isString(encoded) ? encoded.charCodeAt(0) : encoded[0]])
|
|
115
116
|
}
|
|
116
117
|
if (lit.length === 0) return emptyOptional
|
|
117
118
|
let first: number
|
|
118
|
-
if (
|
|
119
|
-
first = kind === 0 ? lit.charCodeAt(0) : new TextEncoder().encode(lit)[0]
|
|
119
|
+
if (Predicate.isString(lit)) {
|
|
120
|
+
first = kind === 0 ? lit.charCodeAt(0) : new TextEncoder().encode(lit)[0]
|
|
120
121
|
} else if (lit instanceof Uint8Array && kind === 1) {
|
|
121
|
-
first = lit[0]
|
|
122
|
+
first = lit[0]
|
|
122
123
|
} else {
|
|
123
124
|
return unknown
|
|
124
125
|
}
|
|
@@ -150,6 +151,7 @@ export class FirstSets {
|
|
|
150
151
|
case "OrFail":
|
|
151
152
|
case "Peek":
|
|
152
153
|
case "Trace":
|
|
154
|
+
case "Syntax":
|
|
153
155
|
case "ResumeAfter":
|
|
154
156
|
case "RetryAfter":
|
|
155
157
|
return this.of(node.self)
|
|
@@ -183,7 +185,7 @@ export class FirstSets {
|
|
|
183
185
|
if (f.mode === Optional) mode = Optional
|
|
184
186
|
acc = acc === undefined ? f : union(acc, f, mode)
|
|
185
187
|
}
|
|
186
|
-
return withMode(acc
|
|
188
|
+
return acc === undefined ? failing : withMode(acc, mode)
|
|
187
189
|
}
|
|
188
190
|
case "Repeat":
|
|
189
191
|
case "Fold":
|
|
@@ -232,7 +234,7 @@ export const planAlt = (firsts: ReadonlyArray<First>): AltPlan | undefined => {
|
|
|
232
234
|
const index = new Map<string, number>()
|
|
233
235
|
const listOf = (keep: (f: First) => boolean): number => {
|
|
234
236
|
const list: Array<number> = []
|
|
235
|
-
for (let i = 0; i < n; i++) if (keep(firsts[i]
|
|
237
|
+
for (let i = 0; i < n; i++) if (keep(firsts[i])) list.push(i)
|
|
236
238
|
const key = list.join(",")
|
|
237
239
|
let k = index.get(key)
|
|
238
240
|
if (k === undefined) {
|
|
@@ -246,7 +248,7 @@ export const planAlt = (firsts: ReadonlyArray<First>): AltPlan | undefined => {
|
|
|
246
248
|
for (let u = 0; u < TableSize; u++) byUnit[u] = listOf((f) => f.mode !== Strict || f.units[u] === 1)
|
|
247
249
|
const high = listOf((f) => f.mode !== Strict || f.high)
|
|
248
250
|
const end = listOf((f) => f.mode !== Strict)
|
|
249
|
-
if (lists.length === 1 && lists[0]
|
|
251
|
+
if (lists.length === 1 && lists[0].length === n) return undefined
|
|
250
252
|
if (lists.length > 255) return undefined
|
|
251
253
|
return { byUnit, high, end, lists }
|
|
252
254
|
}
|