aontu 0.0.9 → 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/aontu.ts +11 -12
- package/dist/aontu.d.ts +3 -3
- package/dist/aontu.js +11 -8
- package/dist/aontu.js.map +1 -1
- package/dist/aontu.min.js +63 -1
- package/dist/lib/lang.d.ts +3 -2
- package/dist/lib/lang.js +278 -214
- package/dist/lib/lang.js.map +1 -1
- package/dist/lib/op/op.d.ts +1 -1
- package/dist/lib/op/unite.js +7 -2
- package/dist/lib/op/unite.js.map +1 -1
- package/dist/lib/unify.d.ts +2 -1
- package/dist/lib/unify.js +3 -4
- package/dist/lib/unify.js.map +1 -1
- package/dist/lib/val.d.ts +4 -3
- package/dist/lib/val.js +46 -33
- package/dist/lib/val.js.map +1 -1
- package/lib/lang.ts +319 -230
- package/lib/op/op.ts +2 -1
- package/lib/op/unite.ts +11 -3
- package/lib/unify.ts +5 -8
- package/lib/val.ts +53 -31
- package/package.json +14 -11
package/lib/lang.ts
CHANGED
|
@@ -6,12 +6,22 @@ import {
|
|
|
6
6
|
Rule,
|
|
7
7
|
RuleSpec,
|
|
8
8
|
Context,
|
|
9
|
-
} from 'jsonic'
|
|
9
|
+
} from '@jsonic/jsonic-next'
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
12
|
MultiSource
|
|
13
13
|
} from '@jsonic/multisource'
|
|
14
14
|
|
|
15
|
+
import {
|
|
16
|
+
makeFileResolver
|
|
17
|
+
} from '@jsonic/multisource/dist/resolver/file'
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
Expr,
|
|
21
|
+
Op,
|
|
22
|
+
} from '@jsonic/expr'
|
|
23
|
+
|
|
24
|
+
|
|
15
25
|
|
|
16
26
|
import {
|
|
17
27
|
Options
|
|
@@ -59,28 +69,33 @@ let AontuJsonic: Plugin = function aontu(jsonic: Jsonic) {
|
|
|
59
69
|
|
|
60
70
|
jsonic.options({
|
|
61
71
|
value: {
|
|
62
|
-
|
|
72
|
+
// JSONIC-UPDATE: map: { val: ... }
|
|
73
|
+
map: {
|
|
63
74
|
// NOTE: specify with functions as jsonic/deep will
|
|
64
75
|
// remove class prototype as options are assumed plain
|
|
65
76
|
// (except for functions).
|
|
66
77
|
// TODO: jsonic should be able to pass context into these
|
|
67
|
-
'string': () => new ScalarTypeVal(String),
|
|
68
|
-
'number': () => new ScalarTypeVal(Number),
|
|
69
|
-
'integer': () => new ScalarTypeVal(Integer),
|
|
70
|
-
'boolean': () => new ScalarTypeVal(Boolean),
|
|
71
|
-
'nil': () => new Nil('literal'),
|
|
72
|
-
'top': () => TOP,
|
|
78
|
+
'string': { val: () => new ScalarTypeVal(String) },
|
|
79
|
+
'number': { val: () => new ScalarTypeVal(Number) },
|
|
80
|
+
'integer': { val: () => new ScalarTypeVal(Integer) },
|
|
81
|
+
'boolean': { val: () => new ScalarTypeVal(Boolean) },
|
|
82
|
+
'nil': { val: () => new Nil('literal') },
|
|
83
|
+
'top': { val: () => TOP },
|
|
73
84
|
}
|
|
74
85
|
},
|
|
75
86
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
// // JSONIC-UPDATE: fixed: { token }
|
|
88
|
+
// fixed: {
|
|
89
|
+
// token: {
|
|
90
|
+
// '#A&': '&',
|
|
91
|
+
// '#A|': '|',
|
|
92
|
+
// '#A/': '/',
|
|
93
|
+
// '#A*': '*', // TODO: REVIEW char as * is a bit overloaded
|
|
94
|
+
// '#A=': '=',
|
|
95
|
+
// }
|
|
96
|
+
// },
|
|
97
|
+
|
|
98
|
+
// JSONIC-UPDATE: check impl
|
|
84
99
|
map: {
|
|
85
100
|
merge: (prev: any, curr: any) => {
|
|
86
101
|
let pval = (prev as Val)
|
|
@@ -91,230 +106,284 @@ let AontuJsonic: Plugin = function aontu(jsonic: Jsonic) {
|
|
|
91
106
|
})
|
|
92
107
|
|
|
93
108
|
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
let VL = jsonic.token.VL
|
|
98
|
-
let OB = jsonic.token.OB
|
|
99
|
-
let OS = jsonic.token.OS
|
|
100
|
-
|
|
101
|
-
let CJ = jsonic.token['#A&']
|
|
102
|
-
let DJ = jsonic.token['#A|']
|
|
103
|
-
let FS = jsonic.token['#A/']
|
|
104
|
-
let AK = jsonic.token['#A*']
|
|
105
|
-
let EQ = jsonic.token['#A=']
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
jsonic.rule('expr', () => {
|
|
109
|
-
return new RuleSpec({
|
|
110
|
-
open: [
|
|
111
|
-
{ s: [[CJ, DJ, AK]], p: 'disjunct', b: 1, n: { expr: 1 } },
|
|
112
|
-
],
|
|
113
|
-
close: [
|
|
114
|
-
{ s: [] }
|
|
115
|
-
],
|
|
109
|
+
let opmap: any = {
|
|
110
|
+
'conjunct-infix': (_op: Op, terms: any) => new ConjunctVal(terms),
|
|
111
|
+
'disjunct-infix': (_op: Op, terms: any) => new DisjunctVal(terms),
|
|
116
112
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
bo: (r: Rule) => r.node = { t: r.node },
|
|
113
|
+
'dot-prefix': (_op: Op, terms: any) => new RefVal(terms, true),
|
|
114
|
+
'dot-infix': (_op: Op, terms: any) => new RefVal(terms),
|
|
120
115
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (cn instanceof PrefVal) {
|
|
125
|
-
return { err: 'single-pref' }
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// replace first val with expr val
|
|
129
|
-
r.node = cn
|
|
130
|
-
},
|
|
131
|
-
})
|
|
132
|
-
})
|
|
116
|
+
'star-prefix': (_op: Op, terms: any) => new PrefVal(terms[0]),
|
|
117
|
+
}
|
|
133
118
|
|
|
134
119
|
|
|
135
|
-
jsonic
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
{
|
|
142
|
-
s: [AK], p: 'pref', b: 1
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
s: [DJ, AK], p: 'pref', b: 1,
|
|
146
|
-
a: (r: Rule) => {
|
|
147
|
-
// Append to existing or start new
|
|
148
|
-
r.node.o = r.node.o instanceof DisjunctVal ?
|
|
149
|
-
r.node.o : new DisjunctVal([r.node.t])
|
|
150
|
-
}
|
|
120
|
+
jsonic
|
|
121
|
+
.use(Expr, {
|
|
122
|
+
op: {
|
|
123
|
+
// disjunct > conjunct: c & b|a -> c & (b|a)
|
|
124
|
+
'conjunct': {
|
|
125
|
+
infix: true, src: '&', left: 14000, right: 15000
|
|
151
126
|
},
|
|
152
|
-
{
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
a: (r: Rule) => {
|
|
156
|
-
// Append to existing or start new
|
|
157
|
-
r.node.o = r.node.o instanceof DisjunctVal ?
|
|
158
|
-
r.node.o : new DisjunctVal([r.node.t])
|
|
159
|
-
}
|
|
127
|
+
'disjunct': {
|
|
128
|
+
// infix: true, src: '|', left: 14000, right: 15000
|
|
129
|
+
infix: true, src: '|', left: 16000, right: 17000
|
|
160
130
|
},
|
|
161
|
-
],
|
|
162
|
-
close: [
|
|
163
|
-
{
|
|
164
|
-
s: [DJ], r: 'disjunct', b: 1, a: (r: Rule) => {
|
|
165
|
-
// higher precedence term (e.g &) was on the left
|
|
166
|
-
let cn = r.child.node?.o || r.child.node
|
|
167
|
-
r.node.t = cn
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
s: [CJ], r: 'disjunct', b: 1, a: (r: Rule) => {
|
|
172
|
-
// & with higher precedence to the right
|
|
173
|
-
let cn = r.child.node?.o || r.child.node
|
|
174
|
-
r.node.t = cn
|
|
175
|
-
r.child.node = null
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
{}
|
|
179
|
-
],
|
|
180
|
-
ac: (r: Rule) => {
|
|
181
|
-
// child values may be normal or expr metas
|
|
182
|
-
let cn = r.child.node?.o || r.child.node
|
|
183
|
-
if (cn) {
|
|
184
|
-
if (r.node.o instanceof DisjunctVal) {
|
|
185
|
-
r.node.o.append(cn)
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
// this rule was just a pass-through
|
|
189
|
-
r.node.o = cn
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
})
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
|
|
197
131
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
p: 'val',
|
|
204
|
-
a: (r: Rule) => {
|
|
205
|
-
r.node = {
|
|
206
|
-
o: r.node.o instanceof ConjunctVal ?
|
|
207
|
-
r.node.o : new ConjunctVal([r.node.t])
|
|
208
|
-
}
|
|
209
|
-
}
|
|
132
|
+
'dot-infix': {
|
|
133
|
+
src: '.',
|
|
134
|
+
infix: true,
|
|
135
|
+
left: 15_000_000,
|
|
136
|
+
right: 14_000_000,
|
|
210
137
|
},
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
138
|
+
'dot-prefix': {
|
|
139
|
+
src: '.',
|
|
140
|
+
prefix: true,
|
|
141
|
+
right: 14_000_000,
|
|
215
142
|
},
|
|
216
|
-
{}
|
|
217
|
-
],
|
|
218
|
-
ac: (r: Rule) => {
|
|
219
|
-
let cn = r.child.node?.o || r.child.node
|
|
220
|
-
if (cn) {
|
|
221
|
-
if (r.node.o instanceof ConjunctVal) {
|
|
222
|
-
r.node.o.append(cn)
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
r.node.o = cn
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
})
|
|
230
|
-
})
|
|
231
|
-
|
|
232
143
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
],
|
|
238
|
-
bo: (r: Rule) => r.node = new RefVal('/')
|
|
239
|
-
})
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
jsonic.rule('part', () => {
|
|
244
|
-
return new RuleSpec({
|
|
245
|
-
open: [
|
|
246
|
-
{
|
|
247
|
-
s: [FS, [TX, ST, NR, VL]], r: 'part', a: (r: Rule) => {
|
|
248
|
-
r.node.append(r.open[1].src)
|
|
249
|
-
}
|
|
144
|
+
'star': {
|
|
145
|
+
src: '*',
|
|
146
|
+
prefix: true,
|
|
147
|
+
right: 14_000_000,
|
|
250
148
|
},
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
jsonic.rule('pair', (rs: RuleSpec) => {
|
|
258
|
-
rs.def.open.unshift({
|
|
259
|
-
s: [[CJ, DJ], EQ], p: 'val', u: { spread: true }
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
// TODO: make before/after function[]
|
|
263
|
-
let orig_bc = rs.def.bc
|
|
264
|
-
rs.def.bc = function(rule: Rule, ctx: Context) {
|
|
265
|
-
let out = orig_bc.call(this, rule, ctx)
|
|
266
|
-
|
|
267
|
-
if (rule.use.spread) {
|
|
268
|
-
rule.node[MapVal.SPREAD] =
|
|
269
|
-
(rule.node[MapVal.SPREAD] || { o: rule.open[0].src, v: [] })
|
|
270
|
-
rule.node[MapVal.SPREAD].v.push(rule.child.node)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return out
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
return rs
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
jsonic.rule('pref', () => {
|
|
281
|
-
return new RuleSpec({
|
|
282
|
-
open: [
|
|
283
|
-
{
|
|
284
|
-
s: [AK, [NR, TX, ST, VL, OB, OS, FS]], b: 1,
|
|
285
|
-
p: 'val',
|
|
286
|
-
},
|
|
287
|
-
],
|
|
288
|
-
close: [
|
|
289
|
-
// Can't be in a conjunct
|
|
290
|
-
{ s: [CJ], e: (r: Rule) => r.open[1] },
|
|
291
|
-
{}
|
|
292
|
-
],
|
|
293
|
-
ac: (r: Rule) => {
|
|
294
|
-
r.node = new PrefVal(r.child.node)
|
|
149
|
+
},
|
|
150
|
+
evaluate: (op: Op, terms: any) => {
|
|
151
|
+
// console.log('LANG EVAL', op, terms)
|
|
152
|
+
return opmap[op.name](op, terms)
|
|
295
153
|
}
|
|
296
154
|
})
|
|
297
|
-
|
|
155
|
+
|
|
156
|
+
// console.log(jsonic.token)
|
|
157
|
+
let CJ = jsonic.token['#E&']
|
|
158
|
+
let CL = jsonic.token.CL
|
|
159
|
+
|
|
160
|
+
// let NR = jsonic.token.NR
|
|
161
|
+
// let TX = jsonic.token.TX
|
|
162
|
+
// let ST = jsonic.token.ST
|
|
163
|
+
// let VL = jsonic.token.VL
|
|
164
|
+
// let OB = jsonic.token.OB
|
|
165
|
+
// let OS = jsonic.token.OS
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
// let DJ = jsonic.token['#A|']
|
|
169
|
+
// let FS = jsonic.token['#A/']
|
|
170
|
+
// let AK = jsonic.token['#A*']
|
|
171
|
+
// let EQ = jsonic.token['#A=']
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
// JSONIC-UPDATE: rule.open[], rule.close[] - replace with rule.oN|cN
|
|
175
|
+
|
|
176
|
+
// jsonic.rule('expr', (rs: RuleSpec) => {
|
|
177
|
+
// rs
|
|
178
|
+
// .open([
|
|
179
|
+
// { s: [[CJ, DJ, AK]], p: 'disjunct', b: 1, n: { expr: 1 } },
|
|
180
|
+
// ])
|
|
181
|
+
|
|
182
|
+
// .close([
|
|
183
|
+
// { s: [] }
|
|
184
|
+
// ])
|
|
185
|
+
|
|
186
|
+
// // NOTE: expr node are meta structures, not Vals
|
|
187
|
+
// // t=most recent term on the left, o=Val
|
|
188
|
+
// .bo((r: Rule) => r.node = { t: r.node })
|
|
189
|
+
|
|
190
|
+
// .ac((r: Rule) => {
|
|
191
|
+
// let cn = r.child.node.o
|
|
192
|
+
|
|
193
|
+
// if (cn instanceof PrefVal) {
|
|
194
|
+
// return r.o0.bad('single-pref')
|
|
195
|
+
// }
|
|
196
|
+
|
|
197
|
+
// // replace first val with expr val
|
|
198
|
+
// r.node = cn
|
|
199
|
+
|
|
200
|
+
// if ('val' === r.parent?.name) {
|
|
201
|
+
// r.parent.node = r.node
|
|
202
|
+
// }
|
|
203
|
+
// })
|
|
204
|
+
|
|
205
|
+
// })
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
// jsonic.rule('disjunct', (rs: RuleSpec) => {
|
|
209
|
+
// rs
|
|
210
|
+
// .open([
|
|
211
|
+
// {
|
|
212
|
+
// s: [CJ], p: 'conjunct', b: 1
|
|
213
|
+
// },
|
|
214
|
+
// {
|
|
215
|
+
// s: [AK], p: 'pref', b: 1
|
|
216
|
+
// },
|
|
217
|
+
// {
|
|
218
|
+
// s: [DJ, AK], p: 'pref', b: 1,
|
|
219
|
+
// a: (r: Rule) => {
|
|
220
|
+
// // Append to existing or start new
|
|
221
|
+
// r.node.o = r.node.o instanceof DisjunctVal ?
|
|
222
|
+
// r.node.o : new DisjunctVal([r.node.t])
|
|
223
|
+
// }
|
|
224
|
+
// },
|
|
225
|
+
// {
|
|
226
|
+
// s: [DJ, [NR, TX, ST, VL, OB, OS]], b: 1,
|
|
227
|
+
// p: 'val',
|
|
228
|
+
// a: (r: Rule) => {
|
|
229
|
+
// // Append to existing or start new
|
|
230
|
+
// r.node.o = r.node.o instanceof DisjunctVal ?
|
|
231
|
+
// r.node.o : new DisjunctVal([r.node.t])
|
|
232
|
+
// }
|
|
233
|
+
// },
|
|
234
|
+
// ])
|
|
235
|
+
|
|
236
|
+
// .close([
|
|
237
|
+
// {
|
|
238
|
+
// s: [DJ], r: 'disjunct', b: 1, a: (r: Rule) => {
|
|
239
|
+
// // higher precedence term (e.g &) was on the left
|
|
240
|
+
// let cn = r.child.node?.o || r.child.node
|
|
241
|
+
// r.node.t = cn
|
|
242
|
+
// }
|
|
243
|
+
// },
|
|
244
|
+
// {
|
|
245
|
+
// s: [CJ], r: 'disjunct', b: 1, a: (r: Rule) => {
|
|
246
|
+
// // & with higher precedence to the right
|
|
247
|
+
// let cn = r.child.node?.o || r.child.node
|
|
248
|
+
// r.node.t = cn
|
|
249
|
+
// r.child.node = null
|
|
250
|
+
// }
|
|
251
|
+
// },
|
|
252
|
+
// {}
|
|
253
|
+
// ])
|
|
254
|
+
// .ac((r: Rule) => {
|
|
255
|
+
// // child values may be normal or expr metas
|
|
256
|
+
// let cn = r.child.node?.o || r.child.node
|
|
257
|
+
// if (cn) {
|
|
258
|
+
// if (r.node.o instanceof DisjunctVal) {
|
|
259
|
+
// r.node.o.append(cn)
|
|
260
|
+
// }
|
|
261
|
+
// else {
|
|
262
|
+
// // this rule was just a pass-through
|
|
263
|
+
// r.node.o = cn
|
|
264
|
+
// }
|
|
265
|
+
// }
|
|
266
|
+
// })
|
|
267
|
+
// })
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
// jsonic.rule('conjunct', (rs: RuleSpec) => {
|
|
272
|
+
// rs
|
|
273
|
+
// .open([
|
|
274
|
+
// {
|
|
275
|
+
// s: [CJ, [NR, TX, ST, VL, OB, OS, FS]], b: 1,
|
|
276
|
+
// p: 'val',
|
|
277
|
+
// a: (r: Rule) => {
|
|
278
|
+
// r.node = {
|
|
279
|
+
// o: r.node.o instanceof ConjunctVal ?
|
|
280
|
+
// r.node.o : new ConjunctVal([r.node.t])
|
|
281
|
+
// }
|
|
282
|
+
// }
|
|
283
|
+
// },
|
|
284
|
+
// ])
|
|
285
|
+
// .close([
|
|
286
|
+
// {
|
|
287
|
+
// s: [CJ], r: 'conjunct', b: 1
|
|
288
|
+
// },
|
|
289
|
+
// {}
|
|
290
|
+
// ])
|
|
291
|
+
// .ac((r: Rule) => {
|
|
292
|
+
// let cn = r.child.node?.o || r.child.node
|
|
293
|
+
// if (cn) {
|
|
294
|
+
// if (r.node.o instanceof ConjunctVal) {
|
|
295
|
+
// r.node.o.append(cn)
|
|
296
|
+
// }
|
|
297
|
+
// else {
|
|
298
|
+
// r.node.o = cn
|
|
299
|
+
// }
|
|
300
|
+
// }
|
|
301
|
+
// })
|
|
302
|
+
// })
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
// jsonic.rule('path', (rs: RuleSpec) => {
|
|
306
|
+
// rs
|
|
307
|
+
// .open([
|
|
308
|
+
// { s: [FS, [TX, ST, NR, VL]], p: 'part', b: 2 }
|
|
309
|
+
// ])
|
|
310
|
+
// .bo((r: Rule) => r.node = new RefVal('/'))
|
|
311
|
+
// })
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
// jsonic.rule('part', (rs: RuleSpec) => {
|
|
315
|
+
// rs.
|
|
316
|
+
// open([
|
|
317
|
+
// {
|
|
318
|
+
// s: [FS, [TX, ST, NR, VL]], r: 'part', a: (r: Rule) => {
|
|
319
|
+
// r.node.append(r.o1.src)
|
|
320
|
+
// }
|
|
321
|
+
// },
|
|
322
|
+
// {}, // no more parts
|
|
323
|
+
// ])
|
|
324
|
+
// })
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
// // rs.def.open.unshift({
|
|
329
|
+
// // s: [[CJ, DJ], EQ], p: 'val', u: { spread: true }
|
|
330
|
+
// // })
|
|
331
|
+
|
|
332
|
+
// // // TODO: make before/after function[]
|
|
333
|
+
// // let orig_bc: any = rs.def.bc
|
|
334
|
+
// // rs.def.bc = function(rule: Rule, ctx: Context) {
|
|
335
|
+
// // let out = orig_bc.call(this, rule, ctx)
|
|
336
|
+
|
|
337
|
+
// // if (rule.use.spread) {
|
|
338
|
+
// // rule.node[MapVal.SPREAD] =
|
|
339
|
+
// // (rule.node[MapVal.SPREAD] || { o: rule.o0.src, v: [] })
|
|
340
|
+
// // rule.node[MapVal.SPREAD].v.push(rule.child.node)
|
|
341
|
+
// // }
|
|
342
|
+
|
|
343
|
+
// // return out
|
|
344
|
+
// // }
|
|
345
|
+
|
|
346
|
+
// return rs
|
|
347
|
+
// })
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
// jsonic.rule('pref', (rs: RuleSpec) => {
|
|
351
|
+
// rs
|
|
352
|
+
// .open([
|
|
353
|
+
// {
|
|
354
|
+
// s: [AK, [NR, TX, ST, VL, OB, OS, FS]], b: 1,
|
|
355
|
+
// p: 'val',
|
|
356
|
+
// },
|
|
357
|
+
// ])
|
|
358
|
+
// .close([
|
|
359
|
+
// // Can't be in a conjunct
|
|
360
|
+
// { s: [CJ], e: (r: Rule) => r.o1 },
|
|
361
|
+
// {}
|
|
362
|
+
// ])
|
|
363
|
+
// .ac((r: Rule) => {
|
|
364
|
+
// r.node = new PrefVal(r.child.node)
|
|
365
|
+
// })
|
|
366
|
+
// })
|
|
298
367
|
|
|
299
368
|
|
|
300
369
|
|
|
301
370
|
jsonic.rule('val', (rs: RuleSpec) => {
|
|
302
|
-
rs.def.open.unshift(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
)
|
|
307
|
-
rs.def.close.unshift(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
)
|
|
371
|
+
// rs.def.open.unshift(
|
|
372
|
+
// // Prefs are always within an expression
|
|
373
|
+
// { s: [AK, [NR, TX, ST, VL, OB, OS, FS]], p: 'expr', b: 2 },
|
|
374
|
+
// { s: [FS, [TX, ST, NR, VL]], p: 'path', b: 2 },
|
|
375
|
+
// )
|
|
376
|
+
// rs.def.close.unshift(
|
|
377
|
+
// {
|
|
378
|
+
// s: [[CJ, DJ]], p: 'expr', b: 1, c: (r: Rule) => {
|
|
379
|
+
// return null == r.n.expr || 0 === r.n.expr
|
|
380
|
+
// }
|
|
381
|
+
// },
|
|
382
|
+
// )
|
|
314
383
|
|
|
315
384
|
|
|
316
385
|
// TODO: wrap utility needed for jsonic to do this?
|
|
317
|
-
let orig_bc = rs.def.bc
|
|
386
|
+
let orig_bc: any = rs.def.bc
|
|
318
387
|
rs.def.bc = function(rule: Rule, ctx: Context) {
|
|
319
388
|
let out = orig_bc.call(this, rule, ctx)
|
|
320
389
|
|
|
@@ -336,12 +405,12 @@ let AontuJsonic: Plugin = function aontu(jsonic: Jsonic) {
|
|
|
336
405
|
valnode = new BooleanVal(rule.node)
|
|
337
406
|
}
|
|
338
407
|
|
|
339
|
-
let st = rule.
|
|
340
|
-
valnode.row = st.
|
|
341
|
-
valnode.col = st.
|
|
342
|
-
valnode.url = ctx.meta.multisource && ctx.meta.multisource.path
|
|
408
|
+
let st = rule.o0
|
|
409
|
+
valnode.row = st.rI
|
|
410
|
+
valnode.col = st.cI
|
|
343
411
|
|
|
344
|
-
//
|
|
412
|
+
// JSONIC-UPDATE: still valid? check multisource
|
|
413
|
+
valnode.url = ctx.meta.multisource && ctx.meta.multisource.path
|
|
345
414
|
|
|
346
415
|
rule.node = valnode
|
|
347
416
|
|
|
@@ -351,6 +420,7 @@ let AontuJsonic: Plugin = function aontu(jsonic: Jsonic) {
|
|
|
351
420
|
})
|
|
352
421
|
|
|
353
422
|
|
|
423
|
+
|
|
354
424
|
jsonic.rule('map', (rs: RuleSpec) => {
|
|
355
425
|
let orig_bc = rs.def.bc
|
|
356
426
|
rs.def.bc = function(rule: Rule, ctx: Context) {
|
|
@@ -363,9 +433,30 @@ let AontuJsonic: Plugin = function aontu(jsonic: Jsonic) {
|
|
|
363
433
|
return rs
|
|
364
434
|
})
|
|
365
435
|
|
|
436
|
+
|
|
437
|
+
jsonic.rule('pair', (rs: RuleSpec) => {
|
|
438
|
+
let orig_bc: any = rs.def.bc
|
|
439
|
+
rs
|
|
440
|
+
.open([{ s: [CJ, CL], p: 'val', u: { spread: true }, g: 'spread' }])
|
|
441
|
+
.bc((...rest: any) => {
|
|
442
|
+
orig_bc(...rest)
|
|
443
|
+
|
|
444
|
+
let rule = rest[0]
|
|
445
|
+
if (rule.use.spread) {
|
|
446
|
+
rule.node[MapVal.SPREAD] =
|
|
447
|
+
(rule.node[MapVal.SPREAD] || { o: rule.o0.src, v: [] })
|
|
448
|
+
rule.node[MapVal.SPREAD].v.push(rule.child.node)
|
|
449
|
+
}
|
|
450
|
+
})
|
|
451
|
+
return rs
|
|
452
|
+
})
|
|
453
|
+
|
|
366
454
|
}
|
|
367
455
|
|
|
368
456
|
|
|
457
|
+
const includeFileResolver = makeFileResolver((spec: any) => {
|
|
458
|
+
return 'string' === typeof spec ? spec : spec?.peg
|
|
459
|
+
})
|
|
369
460
|
|
|
370
461
|
|
|
371
462
|
class Lang {
|
|
@@ -380,14 +471,13 @@ class Lang {
|
|
|
380
471
|
this.jsonic = Jsonic.make()
|
|
381
472
|
.use(AontuJsonic)
|
|
382
473
|
.use(MultiSource, {
|
|
383
|
-
resolver: options
|
|
474
|
+
resolver: options?.resolver || includeFileResolver
|
|
384
475
|
})
|
|
385
|
-
|
|
386
|
-
// console.log('AL options', this.options)
|
|
387
476
|
}
|
|
388
477
|
|
|
389
478
|
parse(src: string, opts?: any): Val {
|
|
390
479
|
|
|
480
|
+
// JSONIC-UPDATE - check meta
|
|
391
481
|
let jm: any = {
|
|
392
482
|
multisource: {
|
|
393
483
|
// NOTE: multisource has property `path` NOT `base`
|
|
@@ -401,8 +491,6 @@ class Lang {
|
|
|
401
491
|
jm.log = opts.log
|
|
402
492
|
}
|
|
403
493
|
|
|
404
|
-
// console.log('ALp jm', jm)
|
|
405
|
-
|
|
406
494
|
let val = this.jsonic(src, jm)
|
|
407
495
|
|
|
408
496
|
return val
|
|
@@ -412,4 +500,5 @@ class Lang {
|
|
|
412
500
|
export {
|
|
413
501
|
Lang,
|
|
414
502
|
Site,
|
|
503
|
+
includeFileResolver,
|
|
415
504
|
}
|
package/lib/op/op.ts
CHANGED
|
@@ -8,10 +8,11 @@ import { disjunct } from './disjunct'
|
|
|
8
8
|
import { unite } from './unite'
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
type Operation = (ctx: Context, a?: Val, b?: Val) => Val
|
|
11
|
+
type Operation = (ctx: Context, a?: Val, b?: Val, whence?: string) => Val
|
|
12
12
|
|
|
13
13
|
export {
|
|
14
14
|
Operation,
|
|
15
15
|
disjunct,
|
|
16
16
|
unite,
|
|
17
17
|
}
|
|
18
|
+
|