@bablr/helpers 0.1.4 → 0.1.5
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/lib/productions.generated.js +65 -26
- package/lib/productions.js +35 -12
- package/package.json +2 -2
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
import { interpolateString as _interpolateString } from "@bablr/boot-helpers/template";
|
|
2
2
|
import { interpolateArray as _interpolateArray } from "@bablr/boot-helpers/template";
|
|
3
3
|
import * as _t from "@bablr/boot-helpers/types";
|
|
4
|
-
export function* List({
|
|
5
|
-
|
|
4
|
+
export function* List(props, s, ctx) {
|
|
5
|
+
const {
|
|
6
6
|
element,
|
|
7
7
|
separator,
|
|
8
8
|
allowHoles = false,
|
|
9
9
|
allowTrailingSeparator = true
|
|
10
|
-
}
|
|
11
|
-
}) {
|
|
10
|
+
} = ctx.unbox(props);
|
|
12
11
|
let sep, it;
|
|
13
12
|
for (;;) {
|
|
14
13
|
it = yield _t.node("Instruction", "Call", [_t.ref`verb`, _t.ref`arguments`], {
|
|
15
14
|
verb: _t.node("Instruction", "Identifier", [_t.lit`eatMatch`], {}, {}),
|
|
16
|
-
arguments: _t.node("Instruction", "Tuple", [_t.ref`open`, _t.ref`values[]`, _t.ref`close`], {
|
|
15
|
+
arguments: _t.node("Instruction", "Tuple", [_t.ref`open`, _t.ref`values[]`, _t.trivia` `, _t.ref`values[]`, _t.ref`close`], {
|
|
17
16
|
open: _t.node("Instruction", "Punctuator", [_t.lit`(`], {}, {}),
|
|
18
|
-
values: [..._interpolateArray(element)],
|
|
17
|
+
values: [..._interpolateArray(element), _t.node("String", "String", [_t.ref`open`, _t.ref`content`, _t.ref`close`], {
|
|
18
|
+
open: _t.node("String", "Punctuator", [_t.lit`'`], {}, {}),
|
|
19
|
+
content: _t.node("String", "Content", [_t.lit`elements[]`], {}, {}),
|
|
20
|
+
close: _t.node("String", "Punctuator", [_t.lit`'`], {}, {})
|
|
21
|
+
}, {})],
|
|
19
22
|
close: _t.node("Instruction", "Punctuator", [_t.lit`)`], {}, {})
|
|
20
23
|
}, {})
|
|
21
24
|
}, {});
|
|
22
25
|
if (it || allowTrailingSeparator) {
|
|
23
26
|
sep = yield _t.node("Instruction", "Call", [_t.ref`verb`, _t.ref`arguments`], {
|
|
24
27
|
verb: _t.node("Instruction", "Identifier", [_t.lit`eatMatch`], {}, {}),
|
|
25
|
-
arguments: _t.node("Instruction", "Tuple", [_t.ref`open`, _t.ref`values[]`, _t.ref`close`], {
|
|
28
|
+
arguments: _t.node("Instruction", "Tuple", [_t.ref`open`, _t.ref`values[]`, _t.trivia` `, _t.ref`values[]`, _t.ref`close`], {
|
|
26
29
|
open: _t.node("Instruction", "Punctuator", [_t.lit`(`], {}, {}),
|
|
27
|
-
values: [..._interpolateArray(separator)],
|
|
30
|
+
values: [..._interpolateArray(separator), _t.node("String", "String", [_t.ref`open`, _t.ref`content`, _t.ref`close`], {
|
|
31
|
+
open: _t.node("String", "Punctuator", [_t.lit`'`], {}, {}),
|
|
32
|
+
content: _t.node("String", "Content", [_t.lit`separators[]`], {}, {}),
|
|
33
|
+
close: _t.node("String", "Punctuator", [_t.lit`'`], {}, {})
|
|
34
|
+
}, {})],
|
|
28
35
|
close: _t.node("Instruction", "Punctuator", [_t.lit`)`], {}, {})
|
|
29
36
|
}, {})
|
|
30
37
|
}, {});
|
|
@@ -32,12 +39,8 @@ export function* List({
|
|
|
32
39
|
if (!(sep || allowHoles)) break;
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
|
-
export function* Any({
|
|
36
|
-
|
|
37
|
-
matchers
|
|
38
|
-
}
|
|
39
|
-
}) {
|
|
40
|
-
for (const matcher of matchers) {
|
|
42
|
+
export function* Any(matchers, s, ctx) {
|
|
43
|
+
for (const matcher of ctx.unbox(matchers)) {
|
|
41
44
|
if (yield _t.node("Instruction", "Call", [_t.ref`verb`, _t.ref`arguments`], {
|
|
42
45
|
verb: _t.node("Instruction", "Identifier", [_t.lit`eatMatch`], {}, {}),
|
|
43
46
|
arguments: _t.node("Instruction", "Tuple", [_t.ref`open`, _t.ref`values[]`, _t.ref`close`], {
|
|
@@ -48,12 +51,8 @@ export function* Any({
|
|
|
48
51
|
}, {})) break;
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
|
-
export function* All({
|
|
52
|
-
|
|
53
|
-
matchers
|
|
54
|
-
}
|
|
55
|
-
}) {
|
|
56
|
-
for (const matcher of matchers) {
|
|
54
|
+
export function* All(matchers, s, ctx) {
|
|
55
|
+
for (const matcher of ctx.unbox(matchers)) {
|
|
57
56
|
yield _t.node("Instruction", "Call", [_t.ref`verb`, _t.ref`arguments`], {
|
|
58
57
|
verb: _t.node("Instruction", "Identifier", [_t.lit`eat`], {}, {}),
|
|
59
58
|
arguments: _t.node("Instruction", "Tuple", [_t.ref`open`, _t.ref`values[]`, _t.ref`close`], {
|
|
@@ -64,19 +63,59 @@ export function* All({
|
|
|
64
63
|
}, {});
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
|
-
export function*
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
export function* Match(cases, s, ctx) {
|
|
67
|
+
for (const case_ of ctx.unbox(cases)) {
|
|
68
|
+
const {
|
|
69
|
+
0: matcher,
|
|
70
|
+
1: guard
|
|
71
|
+
} = ctx.unbox(case_);
|
|
72
|
+
if (yield _t.node("Instruction", "Call", [_t.ref`verb`, _t.ref`arguments`], {
|
|
73
|
+
verb: _t.node("Instruction", "Identifier", [_t.lit`match`], {}, {}),
|
|
74
|
+
arguments: _t.node("Instruction", "Tuple", [_t.ref`open`, _t.ref`values[]`, _t.ref`close`], {
|
|
75
|
+
open: _t.node("Instruction", "Punctuator", [_t.lit`(`], {}, {}),
|
|
76
|
+
values: [..._interpolateArray(guard)],
|
|
77
|
+
close: _t.node("Instruction", "Punctuator", [_t.lit`)`], {}, {})
|
|
78
|
+
}, {})
|
|
79
|
+
}, {})) {
|
|
80
|
+
yield _t.node("Instruction", "Call", [_t.ref`verb`, _t.ref`arguments`], {
|
|
81
|
+
verb: _t.node("Instruction", "Identifier", [_t.lit`eat`], {}, {}),
|
|
82
|
+
arguments: _t.node("Instruction", "Tuple", [_t.ref`open`, _t.ref`values[]`, _t.ref`close`], {
|
|
83
|
+
open: _t.node("Instruction", "Punctuator", [_t.lit`(`], {}, {}),
|
|
84
|
+
values: [..._interpolateArray(matcher)],
|
|
85
|
+
close: _t.node("Instruction", "Punctuator", [_t.lit`)`], {}, {})
|
|
86
|
+
}, {})
|
|
87
|
+
}, {});
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
70
90
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
91
|
+
}
|
|
92
|
+
export function* Punctuator(obj, s, ctx) {
|
|
93
|
+
const {
|
|
94
|
+
value,
|
|
95
|
+
attrs
|
|
96
|
+
} = ctx.unbox(obj);
|
|
97
|
+
yield _t.node("Instruction", "Call", [_t.ref`verb`, _t.ref`arguments`], {
|
|
98
|
+
verb: _t.node("Instruction", "Identifier", [_t.lit`eat`], {}, {}),
|
|
99
|
+
arguments: _t.node("Instruction", "Tuple", [_t.ref`open`, _t.ref`values[]`, _t.ref`close`], {
|
|
100
|
+
open: _t.node("Instruction", "Punctuator", [_t.lit`(`], {}, {}),
|
|
101
|
+
values: [..._interpolateArray(value)],
|
|
102
|
+
close: _t.node("Instruction", "Punctuator", [_t.lit`)`], {}, {})
|
|
103
|
+
}, {})
|
|
104
|
+
}, {});
|
|
105
|
+
return {
|
|
106
|
+
attrs
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function* Optional(matchers, s, ctx) {
|
|
110
|
+
const matchers_ = ctx.unbox(matchers);
|
|
111
|
+
if (matchers_.length > 1) {
|
|
73
112
|
throw new Error('Optional only allows one matcher');
|
|
74
113
|
}
|
|
75
114
|
yield _t.node("Instruction", "Call", [_t.ref`verb`, _t.ref`arguments`], {
|
|
76
115
|
verb: _t.node("Instruction", "Identifier", [_t.lit`eatMatch`], {}, {}),
|
|
77
116
|
arguments: _t.node("Instruction", "Tuple", [_t.ref`open`, _t.ref`values[]`, _t.ref`close`], {
|
|
78
117
|
open: _t.node("Instruction", "Punctuator", [_t.lit`(`], {}, {}),
|
|
79
|
-
values: [..._interpolateArray(
|
|
118
|
+
values: [..._interpolateArray(matchers_[0])],
|
|
80
119
|
close: _t.node("Instruction", "Punctuator", [_t.lit`)`], {}, {})
|
|
81
120
|
}, {})
|
|
82
121
|
}, {});
|
package/lib/productions.js
CHANGED
|
@@ -1,33 +1,56 @@
|
|
|
1
1
|
import { i } from '@bablr/boot/shorthand.macro';
|
|
2
2
|
|
|
3
|
-
export function* List({
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export function* List(props, s, ctx) {
|
|
4
|
+
const {
|
|
5
|
+
element,
|
|
6
|
+
separator,
|
|
7
|
+
allowHoles = false,
|
|
8
|
+
allowTrailingSeparator = true,
|
|
9
|
+
} = ctx.unbox(props);
|
|
10
|
+
|
|
6
11
|
let sep, it;
|
|
7
12
|
for (;;) {
|
|
8
|
-
it = yield i`eatMatch(${element})`;
|
|
13
|
+
it = yield i`eatMatch(${element} 'elements[]')`;
|
|
9
14
|
if (it || allowTrailingSeparator) {
|
|
10
|
-
sep = yield i`eatMatch(${separator})`;
|
|
15
|
+
sep = yield i`eatMatch(${separator} 'separators[]')`;
|
|
11
16
|
}
|
|
12
17
|
if (!(sep || allowHoles)) break;
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
export function* Any(
|
|
17
|
-
for (const matcher of matchers) {
|
|
21
|
+
export function* Any(matchers, s, ctx) {
|
|
22
|
+
for (const matcher of ctx.unbox(matchers)) {
|
|
18
23
|
if (yield i`eatMatch(${matcher})`) break;
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
export function* All(
|
|
23
|
-
for (const matcher of matchers) {
|
|
27
|
+
export function* All(matchers, s, ctx) {
|
|
28
|
+
for (const matcher of ctx.unbox(matchers)) {
|
|
24
29
|
yield i`eat(${matcher})`;
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
export function*
|
|
29
|
-
|
|
33
|
+
export function* Match(cases, s, ctx) {
|
|
34
|
+
for (const case_ of ctx.unbox(cases)) {
|
|
35
|
+
const { 0: matcher, 1: guard } = ctx.unbox(case_);
|
|
36
|
+
if (yield i`match(${guard})`) {
|
|
37
|
+
yield i`eat(${matcher})`;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function* Punctuator(obj, s, ctx) {
|
|
44
|
+
const { value, attrs } = ctx.unbox(obj);
|
|
45
|
+
yield i`eat(${value})`;
|
|
46
|
+
|
|
47
|
+
return { attrs };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function* Optional(matchers, s, ctx) {
|
|
51
|
+
const matchers_ = ctx.unbox(matchers);
|
|
52
|
+
if (matchers_.length > 1) {
|
|
30
53
|
throw new Error('Optional only allows one matcher');
|
|
31
54
|
}
|
|
32
|
-
yield i`eatMatch(${
|
|
55
|
+
yield i`eatMatch(${matchers_[0]})`;
|
|
33
56
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bablr/helpers",
|
|
3
3
|
"description": "Command helpers for use in writing BABLR grammars",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"author": "Conrad Buck<conartist6@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"clean": "rm lib/productions.generated.js"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@bablr/boot": "0.1.
|
|
28
|
+
"@bablr/boot": "0.1.9",
|
|
29
29
|
"@bablr/boot-helpers": "0.1.3",
|
|
30
30
|
"iter-tools-es": "^7.5.3"
|
|
31
31
|
},
|