aontu 0.30.1 → 0.30.2

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.
Files changed (184) hide show
  1. package/dist/ctx.d.ts +51 -0
  2. package/dist/ctx.js +105 -0
  3. package/dist/ctx.js.map +1 -0
  4. package/dist/err.d.ts +12 -0
  5. package/dist/err.js +123 -0
  6. package/dist/err.js.map +1 -0
  7. package/dist/hints.d.ts +8 -0
  8. package/dist/hints.js +84 -0
  9. package/dist/hints.js.map +1 -0
  10. package/dist/lang.d.ts +11 -0
  11. package/dist/lang.js +569 -0
  12. package/dist/lang.js.map +1 -0
  13. package/dist/site.d.ts +12 -0
  14. package/dist/site.js +27 -0
  15. package/dist/site.js.map +1 -0
  16. package/dist/tsconfig.tsbuildinfo +1 -0
  17. package/dist/type.d.ts +32 -0
  18. package/dist/type.js +16 -0
  19. package/dist/type.js.map +1 -0
  20. package/dist/unify.d.ts +14 -0
  21. package/dist/unify.js +156 -0
  22. package/dist/unify.js.map +1 -0
  23. package/dist/utility.d.ts +14 -0
  24. package/dist/utility.js +122 -0
  25. package/dist/utility.js.map +1 -0
  26. package/dist/val/BagVal.d.ts +10 -0
  27. package/dist/val/BagVal.js +15 -0
  28. package/dist/val/BagVal.js.map +1 -0
  29. package/dist/val/BooleanVal.d.ts +9 -0
  30. package/dist/val/BooleanVal.js +16 -0
  31. package/dist/val/BooleanVal.js.map +1 -0
  32. package/dist/val/CloseFuncVal.d.ts +11 -0
  33. package/dist/val/CloseFuncVal.js +32 -0
  34. package/dist/val/CloseFuncVal.js.map +1 -0
  35. package/dist/val/ConjunctVal.d.ts +14 -0
  36. package/dist/val/ConjunctVal.js +187 -0
  37. package/dist/val/ConjunctVal.js.map +1 -0
  38. package/dist/val/CopyFuncVal.d.ts +13 -0
  39. package/dist/val/CopyFuncVal.js +35 -0
  40. package/dist/val/CopyFuncVal.js.map +1 -0
  41. package/dist/val/DisjunctVal.d.ts +19 -0
  42. package/dist/val/DisjunctVal.js +194 -0
  43. package/dist/val/DisjunctVal.js.map +1 -0
  44. package/dist/val/FeatureVal.d.ts +10 -0
  45. package/dist/val/FeatureVal.js +29 -0
  46. package/dist/val/FeatureVal.js.map +1 -0
  47. package/dist/val/FuncBaseVal.d.ts +15 -0
  48. package/dist/val/FuncBaseVal.js +127 -0
  49. package/dist/val/FuncBaseVal.js.map +1 -0
  50. package/dist/val/HideFuncVal.d.ts +12 -0
  51. package/dist/val/HideFuncVal.js +48 -0
  52. package/dist/val/HideFuncVal.js.map +1 -0
  53. package/dist/val/IntegerVal.d.ts +9 -0
  54. package/dist/val/IntegerVal.js +46 -0
  55. package/dist/val/IntegerVal.js.map +1 -0
  56. package/dist/val/JunctionVal.d.ts +12 -0
  57. package/dist/val/JunctionVal.js +31 -0
  58. package/dist/val/JunctionVal.js.map +1 -0
  59. package/dist/val/KeyFuncVal.d.ts +12 -0
  60. package/dist/val/KeyFuncVal.js +34 -0
  61. package/dist/val/KeyFuncVal.js.map +1 -0
  62. package/dist/val/ListVal.d.ts +17 -0
  63. package/dist/val/ListVal.js +186 -0
  64. package/dist/val/ListVal.js.map +1 -0
  65. package/dist/val/LowerFuncVal.d.ts +12 -0
  66. package/dist/val/LowerFuncVal.js +40 -0
  67. package/dist/val/LowerFuncVal.js.map +1 -0
  68. package/dist/val/MapVal.d.ts +16 -0
  69. package/dist/val/MapVal.js +211 -0
  70. package/dist/val/MapVal.js.map +1 -0
  71. package/dist/val/MoveFuncVal.d.ts +11 -0
  72. package/dist/val/MoveFuncVal.js +41 -0
  73. package/dist/val/MoveFuncVal.js.map +1 -0
  74. package/dist/val/NilVal.d.ts +25 -0
  75. package/dist/val/NilVal.js +92 -0
  76. package/dist/val/NilVal.js.map +1 -0
  77. package/dist/val/NullVal.d.ts +9 -0
  78. package/dist/val/NullVal.js +18 -0
  79. package/dist/val/NullVal.js.map +1 -0
  80. package/dist/val/NumberVal.d.ts +9 -0
  81. package/dist/val/NumberVal.js +44 -0
  82. package/dist/val/NumberVal.js.map +1 -0
  83. package/dist/val/OpBaseVal.d.ts +18 -0
  84. package/dist/val/OpBaseVal.js +152 -0
  85. package/dist/val/OpBaseVal.js.map +1 -0
  86. package/dist/val/OpenFuncVal.d.ts +11 -0
  87. package/dist/val/OpenFuncVal.js +30 -0
  88. package/dist/val/OpenFuncVal.js.map +1 -0
  89. package/dist/val/PathFuncVal.d.ts +13 -0
  90. package/dist/val/PathFuncVal.js +42 -0
  91. package/dist/val/PathFuncVal.js.map +1 -0
  92. package/dist/val/PlusOpVal.d.ts +16 -0
  93. package/dist/val/PlusOpVal.js +59 -0
  94. package/dist/val/PlusOpVal.js.map +1 -0
  95. package/dist/val/PrefFuncVal.d.ts +11 -0
  96. package/dist/val/PrefFuncVal.js +39 -0
  97. package/dist/val/PrefFuncVal.js.map +1 -0
  98. package/dist/val/PrefVal.d.ts +15 -0
  99. package/dist/val/PrefVal.js +104 -0
  100. package/dist/val/PrefVal.js.map +1 -0
  101. package/dist/val/RefVal.d.ts +22 -0
  102. package/dist/val/RefVal.js +276 -0
  103. package/dist/val/RefVal.js.map +1 -0
  104. package/dist/val/ScalarKindVal.d.ts +16 -0
  105. package/dist/val/ScalarKindVal.js +76 -0
  106. package/dist/val/ScalarKindVal.js.map +1 -0
  107. package/dist/val/ScalarVal.d.ts +16 -0
  108. package/dist/val/ScalarVal.js +61 -0
  109. package/dist/val/ScalarVal.js.map +1 -0
  110. package/dist/val/StringVal.d.ts +10 -0
  111. package/dist/val/StringVal.js +19 -0
  112. package/dist/val/StringVal.js.map +1 -0
  113. package/dist/val/SuperFuncVal.d.ts +11 -0
  114. package/dist/val/SuperFuncVal.js +22 -0
  115. package/dist/val/SuperFuncVal.js.map +1 -0
  116. package/dist/val/TopVal.d.ts +16 -0
  117. package/dist/val/TopVal.js +38 -0
  118. package/dist/val/TopVal.js.map +1 -0
  119. package/dist/val/TypeFuncVal.d.ts +12 -0
  120. package/dist/val/TypeFuncVal.js +35 -0
  121. package/dist/val/TypeFuncVal.js.map +1 -0
  122. package/dist/val/UpperFuncVal.d.ts +12 -0
  123. package/dist/val/UpperFuncVal.js +40 -0
  124. package/dist/val/UpperFuncVal.js.map +1 -0
  125. package/dist/val/Val.d.ts +89 -0
  126. package/dist/val/Val.js +186 -0
  127. package/dist/val/Val.js.map +1 -0
  128. package/dist/val/VarVal.d.ts +13 -0
  129. package/dist/val/VarVal.js +109 -0
  130. package/dist/val/VarVal.js.map +1 -0
  131. package/dist/val/top.d.ts +2 -0
  132. package/dist/val/top.js +10 -0
  133. package/dist/val/top.js.map +1 -0
  134. package/dist/val/valutil.d.ts +2 -0
  135. package/dist/val/valutil.js +30 -0
  136. package/dist/val/valutil.js.map +1 -0
  137. package/package.json +3 -5
  138. package/src/aontu.ts +218 -0
  139. package/src/ctx.ts +201 -0
  140. package/src/err.ts +172 -0
  141. package/src/hints.ts +119 -0
  142. package/src/lang.ts +782 -0
  143. package/src/site.ts +34 -0
  144. package/src/tsconfig.json +16 -0
  145. package/src/type.ts +72 -0
  146. package/src/unify.ts +225 -0
  147. package/src/utility.ts +179 -0
  148. package/src/val/BagVal.ts +33 -0
  149. package/src/val/BooleanVal.ts +32 -0
  150. package/src/val/CloseFuncVal.ts +61 -0
  151. package/src/val/ConjunctVal.ts +285 -0
  152. package/src/val/CopyFuncVal.ts +69 -0
  153. package/src/val/DisjunctVal.ts +288 -0
  154. package/src/val/FeatureVal.ts +56 -0
  155. package/src/val/FuncBaseVal.ts +198 -0
  156. package/src/val/HideFuncVal.ts +85 -0
  157. package/src/val/IntegerVal.ts +75 -0
  158. package/src/val/JunctionVal.ts +54 -0
  159. package/src/val/KeyFuncVal.ts +67 -0
  160. package/src/val/ListVal.ts +286 -0
  161. package/src/val/LowerFuncVal.ts +73 -0
  162. package/src/val/MapVal.ts +316 -0
  163. package/src/val/MoveFuncVal.ts +79 -0
  164. package/src/val/NilVal.ts +156 -0
  165. package/src/val/NullVal.ts +38 -0
  166. package/src/val/NumberVal.ts +75 -0
  167. package/src/val/OpBaseVal.ts +231 -0
  168. package/src/val/OpenFuncVal.ts +60 -0
  169. package/src/val/PathFuncVal.ts +75 -0
  170. package/src/val/PlusOpVal.ts +92 -0
  171. package/src/val/PrefFuncVal.ts +73 -0
  172. package/src/val/PrefVal.ts +159 -0
  173. package/src/val/RefVal.ts +384 -0
  174. package/src/val/ScalarKindVal.ts +125 -0
  175. package/src/val/ScalarVal.ts +105 -0
  176. package/src/val/StringVal.ts +37 -0
  177. package/src/val/SuperFuncVal.ts +46 -0
  178. package/src/val/TopVal.ts +69 -0
  179. package/src/val/TypeFuncVal.ts +69 -0
  180. package/src/val/UpperFuncVal.ts +72 -0
  181. package/src/val/Val.ts +294 -0
  182. package/src/val/VarVal.ts +171 -0
  183. package/src/val/top.ts +12 -0
  184. package/src/val/valutil.ts +31 -0
@@ -0,0 +1,79 @@
1
+ /* Copyright (c) 2021-2025 Richard Rodger, MIT License */
2
+
3
+
4
+ import type {
5
+ Val,
6
+ ValSpec,
7
+ } from '../type'
8
+
9
+ import {
10
+ AontuContext,
11
+ } from '../ctx'
12
+
13
+ import { makeNilErr } from '../err'
14
+
15
+ import { NilVal } from '../val/NilVal'
16
+
17
+ import {
18
+ walk
19
+ } from '../utility'
20
+
21
+
22
+
23
+ import { FuncBaseVal } from './FuncBaseVal'
24
+ import { CopyFuncVal } from './CopyFuncVal'
25
+
26
+
27
+
28
+ class MoveFuncVal extends FuncBaseVal {
29
+ isMoveFunc = true
30
+
31
+ constructor(
32
+ spec: ValSpec,
33
+ ctx?: AontuContext
34
+ ) {
35
+ super(spec, ctx)
36
+ }
37
+
38
+
39
+ make(_ctx: AontuContext, spec: ValSpec): Val {
40
+ return new MoveFuncVal(spec)
41
+ }
42
+
43
+ funcname() {
44
+ return 'move'
45
+ }
46
+
47
+
48
+ resolve(ctx: AontuContext, args: Val[]) {
49
+ let out = args[0] ?? makeNilErr(ctx, 'arg', this)
50
+
51
+ const orig = out
52
+ const origcanon = orig.canon
53
+
54
+ if (!orig.isNil) {
55
+ const src = orig.clone(ctx)
56
+
57
+ walk(orig, (_key: string | number | undefined, val: Val) => {
58
+ val.mark.hide = true
59
+ return val
60
+ })
61
+
62
+ out = new CopyFuncVal({ peg: [src] }, ctx)
63
+ }
64
+
65
+ Object.defineProperty(out, 'canon', {
66
+ get: () => 'move(' + origcanon + ')',
67
+ configurable: true
68
+ })
69
+
70
+ // console.log('MOVE-resolve', out)
71
+
72
+ return out
73
+ }
74
+ }
75
+
76
+
77
+ export {
78
+ MoveFuncVal,
79
+ }
@@ -0,0 +1,156 @@
1
+ /* Copyright (c) 2021-2025 Richard Rodger, MIT License */
2
+
3
+
4
+ import type {
5
+ ValSpec,
6
+ } from '../type'
7
+
8
+ import {
9
+ DONE,
10
+ } from '../type'
11
+
12
+ import {
13
+ AontuContext,
14
+ } from '../ctx'
15
+
16
+
17
+ import { Val } from './Val'
18
+
19
+ import { AontuError, descErr } from '../err'
20
+
21
+
22
+ class NilVal extends Val {
23
+ isNil = true
24
+
25
+ nil = true
26
+ why: any
27
+ primary?: Val
28
+ secondary?: Val
29
+ msg: string = ''
30
+ attempt?: string
31
+
32
+ // TODO: include Val generating nil, thus capture type
33
+
34
+ // A Nil is an error - should not happen - unify failed
35
+ // refactor ,make(spec,ctx)
36
+ static make = (ctx?: AontuContext, why?: any, av?: Val, bv?: Val, attempt?: string) => {
37
+ let nil = new NilVal({ why }, ctx)
38
+
39
+ nil.attempt = attempt
40
+ // TODO: this should be done lazily, for multiple terms
41
+
42
+ // Terms later in same file are considered the primary error location.
43
+ if (null != av) {
44
+ nil.site.row = av.site.row
45
+ nil.site.col = av.site.col
46
+ nil.site.url = av.site.url
47
+
48
+ nil.primary = av
49
+
50
+ if (null != bv) {
51
+ nil.secondary = bv
52
+
53
+ let bv_loc_wins =
54
+ (nil.site.url === bv.site.url) && (
55
+ (nil.site.row < bv.site.row) ||
56
+ (nil.site.row === bv.site.row && nil.site.col < bv.site.col)
57
+ )
58
+
59
+ if (bv_loc_wins) {
60
+ nil.site.row = bv.site.row
61
+ nil.site.col = bv.site.col
62
+ nil.site.url = bv.site.url
63
+ nil.primary = bv
64
+ nil.secondary = av
65
+ }
66
+ }
67
+ }
68
+
69
+ if (ctx) {
70
+ ctx.adderr(nil)
71
+ }
72
+
73
+ return nil
74
+ }
75
+
76
+
77
+ constructor(
78
+ spec?: {
79
+ why?: string
80
+ msg?: string
81
+ err?: NilVal | NilVal[] | Error | Error[]
82
+ } | string,
83
+ ctx?: AontuContext
84
+ ) {
85
+ super(spec && 'string' !== typeof spec ? spec : {}, ctx)
86
+
87
+ if (spec && 'object' === typeof spec) {
88
+ this.why = spec?.why
89
+ this.msg = 'string' === typeof spec?.msg ? spec.msg : this.msg
90
+ this.err = spec ?
91
+ Array.isArray(spec.err) ? [...spec.err] :
92
+ null != spec.err ? [spec.err] :
93
+ [] : []
94
+ }
95
+
96
+ // Nil is always DONE, by definition.
97
+ this.dc = DONE
98
+ }
99
+
100
+
101
+ unify(_peer: Val, _ctx: AontuContext) {
102
+ return this
103
+ }
104
+
105
+
106
+ clone(ctx: AontuContext, spec?: ValSpec): Val {
107
+ let out = (super.clone(ctx, spec) as NilVal)
108
+ out.why = this.why
109
+
110
+ // Should these clone?
111
+ // out.primary = this.primary?.clone()
112
+ // out.secondary = this.secondary?.clone()
113
+ out.primary = this.primary
114
+ out.secondary = this.secondary
115
+
116
+ out.msg = this.msg
117
+ return out
118
+ }
119
+
120
+
121
+ // TODO: custom canon? useful for unknown function errors
122
+ get canon() {
123
+ return 'nil'
124
+ }
125
+
126
+
127
+ gen(ctx: AontuContext) {
128
+ // Unresolved nil cannot be generated, so always an error.
129
+
130
+ this.why = this.why ?? 'nil_gen'
131
+ ctx.adderr(this)
132
+
133
+ if (!ctx.collect) {
134
+ const err = new AontuError(this.msg, [this])
135
+ throw err
136
+ }
137
+
138
+ return undefined
139
+ }
140
+
141
+
142
+ superior(): Val {
143
+ return this
144
+ }
145
+
146
+
147
+ inspection() {
148
+ return this.why
149
+ }
150
+
151
+ }
152
+
153
+
154
+ export {
155
+ NilVal,
156
+ }
@@ -0,0 +1,38 @@
1
+ /* Copyright (c) 2025 Richard Rodger, MIT License */
2
+
3
+
4
+ import type {
5
+ Val,
6
+ ValSpec,
7
+ } from '../type'
8
+
9
+ import {
10
+ AontuContext,
11
+ } from '../ctx'
12
+
13
+ import { ScalarVal } from './ScalarVal'
14
+ import { Null } from './ScalarKindVal'
15
+
16
+
17
+ class NullVal extends ScalarVal {
18
+ isNull = true
19
+
20
+ constructor(
21
+ spec: ValSpec,
22
+ ctx?: AontuContext
23
+ ) {
24
+ super({ peg: spec.peg, kind: Null }, ctx)
25
+ this.peg = null
26
+ }
27
+
28
+
29
+ unify(peer: Val, ctx: AontuContext): Val {
30
+ return super.unify(peer, ctx)
31
+ }
32
+ }
33
+
34
+
35
+ export {
36
+ NullVal,
37
+ }
38
+
@@ -0,0 +1,75 @@
1
+ /* Copyright (c) 2021-2025 Richard Rodger, MIT License */
2
+
3
+ import type {
4
+ Val,
5
+ ValSpec,
6
+ } from '../type'
7
+
8
+ import {
9
+ AontuContext,
10
+ } from '../ctx'
11
+
12
+ import { makeNilErr, AontuError } from '../err'
13
+
14
+ import { ScalarVal } from './ScalarVal'
15
+
16
+ import {
17
+ explainOpen,
18
+ explainClose,
19
+ } from '../utility'
20
+
21
+
22
+
23
+ class NumberVal extends ScalarVal {
24
+ isNumber = true
25
+
26
+ constructor(
27
+ spec: ValSpec,
28
+ ctx?: AontuContext
29
+ ) {
30
+ if (isNaN(spec.peg)) {
31
+ // TODO: use Nil?
32
+ throw new AontuError('not-number: ' + spec.peg)
33
+ }
34
+
35
+ super({ ...spec, kind: Number }, ctx)
36
+ }
37
+
38
+
39
+ unify(peer: any, ctx: AontuContext): Val {
40
+ const te = ctx.explain && explainOpen(ctx, ctx.explain, 'Number', this, peer)
41
+
42
+ let out: Val = this
43
+
44
+ if (null != peer) {
45
+ if (peer.isScalarKind) {
46
+ out = peer.unify(this, ctx)
47
+ }
48
+ else if (
49
+ peer.isScalar &&
50
+ peer.peg === this.peg
51
+ ) {
52
+ out = peer.isInteger ? peer : this
53
+ }
54
+ else if (peer.isTop) {
55
+ out = this
56
+ }
57
+ else {
58
+ out = makeNilErr(ctx, 'scalar_' +
59
+ ((peer as any).kind === this.kind ? 'value' : 'kind'), this, peer)
60
+ }
61
+ }
62
+ else {
63
+ out = super.unify(peer, ctx)
64
+ }
65
+
66
+ explainClose(te, out)
67
+
68
+ return out
69
+ }
70
+ }
71
+
72
+
73
+ export {
74
+ NumberVal,
75
+ }
@@ -0,0 +1,231 @@
1
+ /* Copyright (c) 2024 Richard Rodger, MIT License */
2
+
3
+
4
+ import type {
5
+ Val,
6
+ ValSpec,
7
+ } from '../type'
8
+
9
+ import {
10
+ DONE,
11
+ } from '../type'
12
+
13
+ import {
14
+ descErr,
15
+ makeNilErr,
16
+ AontuError
17
+ } from '../err'
18
+
19
+ import { AontuContext } from '../ctx'
20
+ import { unite } from '../unify'
21
+
22
+ import {
23
+ explainOpen,
24
+ ec,
25
+ explainClose,
26
+ } from '../utility'
27
+
28
+ import {
29
+ top
30
+ } from './top'
31
+
32
+ import { ConjunctVal } from './ConjunctVal'
33
+ import { FeatureVal } from './FeatureVal'
34
+
35
+
36
+
37
+
38
+ class OpBaseVal extends FeatureVal {
39
+ isPlusOp = true
40
+
41
+ constructor(
42
+ spec: ValSpec,
43
+ ctx?: AontuContext
44
+ ) {
45
+ super(spec, ctx)
46
+ this.peg = []
47
+
48
+ for (let pI = 0; pI < spec.peg.length; pI++) {
49
+ this.append(spec.peg[pI])
50
+ }
51
+ }
52
+
53
+
54
+ append(part: any) {
55
+ this.peg.push(part)
56
+ }
57
+
58
+
59
+ make(ctx: AontuContext, _spec: ValSpec): Val {
60
+ return makeNilErr(ctx, 'op:' + this.opname(), this, undefined, 'make')
61
+ }
62
+
63
+ opname() {
64
+ return 'op'
65
+ }
66
+
67
+
68
+ unify(peer: Val, ctx: AontuContext): Val {
69
+ const te = ctx.explain && explainOpen(ctx, ctx.explain, 'Op:' + this.opname(), this, peer)
70
+ let out: Val = this
71
+
72
+ if (this.id == peer.id) {
73
+ return this
74
+ }
75
+
76
+
77
+ let pegdone = true
78
+ let newpeg: Val[] = []
79
+
80
+ for (let arg of this.peg) {
81
+ if (!arg.done) {
82
+ arg = arg.unify(top(), ctx, ec(te, 'ARG'))
83
+ }
84
+ pegdone &&= arg.done
85
+ newpeg.push(arg)
86
+ }
87
+
88
+ // console.log('OPVAL', this.id, this.opname(), pegdone, newpeg.map(p => p.canon))
89
+
90
+ if (pegdone) {
91
+ let result: Val | undefined = null == ctx ? this : this.operate(ctx, newpeg)
92
+
93
+ result = result || this
94
+
95
+ if (null == result && this.canon === peer.canon) {
96
+ out = this
97
+ }
98
+
99
+ // TODO: should be result.isOp
100
+ else if (result instanceof OpBaseVal) {
101
+ if (peer.isTop) {
102
+ out = this
103
+ }
104
+ // TODO: should peer.isNil
105
+ else if (peer.isNil) {
106
+ out = makeNilErr(ctx, 'op[' + this.peg + ']', this, peer)
107
+ }
108
+
109
+ else if (this.canon === peer.canon) {
110
+ out = this
111
+ }
112
+
113
+ else {
114
+ this.dc = DONE === this.dc ? DONE : this.dc + 1
115
+ out = new ConjunctVal({ peg: [this, peer] }, ctx)
116
+ }
117
+ }
118
+ else {
119
+ out = result.done && peer.isTop ? result :
120
+ unite(ctx.clone({ explain: ec(te, 'RES') }), result, peer, 'op')
121
+ }
122
+
123
+ out.dc = DONE === out.dc ? DONE : this.dc + 1
124
+ }
125
+ else if (peer.isTop) {
126
+ this.notdone()
127
+ out = this.make(ctx, { peg: newpeg })
128
+
129
+ // TODO: make should handle this using ctx?
130
+ out.site.row = this.site.row
131
+ out.site.col = this.site.col
132
+ out.site.url = this.site.url
133
+ out.path = this.path
134
+
135
+ // why += 'top'
136
+ }
137
+ else if (peer.isNil) {
138
+ this.notdone()
139
+ out = peer
140
+ //why += 'nil'
141
+ }
142
+ else {
143
+ this.notdone()
144
+ out = new ConjunctVal({ peg: [this, peer] }, ctx)
145
+
146
+ // TODO: make should handle this using ctx?
147
+ out.site.row = this.site.row
148
+ out.site.col = this.site.col
149
+ out.site.url = this.site.url
150
+ out.path = this.path
151
+ }
152
+
153
+ explainClose(te, out)
154
+
155
+ return out
156
+ }
157
+
158
+
159
+ same(peer: Val): boolean {
160
+ return null == peer ? false : this.peg === peer.peg
161
+ }
162
+
163
+
164
+ clone(ctx: AontuContext, _spec?: ValSpec): Val {
165
+ let out = (super.clone(ctx, {
166
+ peg: this.peg,
167
+ }) as OpBaseVal)
168
+ return out
169
+ }
170
+
171
+
172
+ operate(ctx: AontuContext, _args: Val[]): Val | undefined {
173
+ return makeNilErr(ctx, 'op:' + this.opname(), this, undefined, 'operate')
174
+ }
175
+
176
+
177
+ get canon() {
178
+ return 'op'
179
+ }
180
+
181
+
182
+ primatize(v: any): undefined | null | string | number | boolean {
183
+ const t = typeof v
184
+ if (null == v || 'string' === t || 'number' === t || 'boolean' === t) {
185
+ return v
186
+ }
187
+ else if (v?.isVal) {
188
+ return this.primatize(v.peg)
189
+ }
190
+ else if (v?.toString) {
191
+ return '' + v
192
+ }
193
+ else {
194
+ return undefined
195
+ }
196
+ }
197
+
198
+
199
+ gen(ctx?: AontuContext) {
200
+ // Unresolved op cannot be generated, so always an error.
201
+ let nil = makeNilErr(
202
+ ctx,
203
+ 'op',
204
+ this,
205
+ undefined
206
+ )
207
+
208
+ // TODO: refactor to use Site
209
+ nil.path = this.path
210
+ nil.site.url = this.site.url
211
+ nil.site.row = this.site.row
212
+ nil.site.col = this.site.col
213
+
214
+ descErr(nil, ctx)
215
+
216
+ if (ctx) {
217
+ // ctx.err.push(nil)
218
+ ctx.adderr(nil)
219
+ }
220
+ else {
221
+ throw new AontuError(nil.msg)
222
+ }
223
+
224
+ return undefined
225
+ }
226
+ }
227
+
228
+
229
+ export {
230
+ OpBaseVal,
231
+ }
@@ -0,0 +1,60 @@
1
+ /* Copyright (c) 2021-2025 Richard Rodger, MIT License */
2
+
3
+
4
+ import type {
5
+ Val,
6
+ ValSpec,
7
+ } from '../type'
8
+
9
+ import {
10
+ AontuContext,
11
+ } from '../ctx'
12
+
13
+ import { makeNilErr } from '../err'
14
+
15
+
16
+ import { FuncBaseVal } from './FuncBaseVal'
17
+ import { NilVal } from '../val/NilVal'
18
+ import { BagVal } from '../val/BagVal'
19
+
20
+
21
+ class OpenFuncVal extends FuncBaseVal {
22
+ isOpenFunc = true
23
+
24
+ constructor(
25
+ spec: ValSpec,
26
+ ctx?: AontuContext
27
+ ) {
28
+ super(spec, ctx)
29
+ }
30
+
31
+
32
+ make(_ctx: AontuContext, spec: ValSpec): Val {
33
+ return new OpenFuncVal(spec)
34
+ }
35
+
36
+ funcname() {
37
+ return 'open'
38
+ }
39
+
40
+
41
+ resolve(ctx: AontuContext | undefined, args: Val[]) {
42
+ const argval: any = args[0]
43
+
44
+ if (null == argval) {
45
+ return makeNilErr(ctx, 'no_first_arg', this, undefined, 'close')
46
+ }
47
+
48
+ if (argval.isMap || argval.isList) {
49
+ (argval as BagVal).closed = false
50
+ }
51
+
52
+ return argval
53
+ }
54
+
55
+ }
56
+
57
+
58
+ export {
59
+ OpenFuncVal,
60
+ }
@@ -0,0 +1,75 @@
1
+ /* Copyright (c) 2021-2025 Richard Rodger, MIT License */
2
+
3
+
4
+ import type {
5
+ Val,
6
+ ValSpec,
7
+ } from '../type'
8
+
9
+ import {
10
+ AontuContext,
11
+ } from '../ctx'
12
+
13
+ import { makeNilErr } from '../err'
14
+
15
+ import { NilVal } from '../val/NilVal'
16
+ import { RefVal } from '../val/RefVal'
17
+ import { FuncBaseVal } from './FuncBaseVal'
18
+
19
+
20
+ class PathFuncVal extends FuncBaseVal {
21
+ isPathFunc = true
22
+
23
+ prepared = 0
24
+
25
+ constructor(
26
+ spec: ValSpec,
27
+ ctx?: AontuContext
28
+ ) {
29
+ super(spec, ctx)
30
+ }
31
+
32
+
33
+ make(_ctx: AontuContext, spec: ValSpec): Val {
34
+ const pathfunc = new PathFuncVal(spec)
35
+ pathfunc.prepared = this.prepared
36
+ return pathfunc
37
+ }
38
+
39
+ funcname() {
40
+ return 'path'
41
+ }
42
+
43
+
44
+ prepare(ctx: AontuContext, args: Val[]) {
45
+ let arg = args[0]
46
+
47
+ if (0 === this.prepared) {
48
+ if (arg.isScalar) {
49
+ arg = this.place(new RefVal({ peg: [arg], absolute: false }))
50
+ }
51
+ else if (!arg.isRef) {
52
+ arg = makeNilErr(ctx, 'invalid-arg', this)
53
+ }
54
+ }
55
+
56
+ args[0] = arg
57
+
58
+ this.prepared++
59
+
60
+ return args
61
+ }
62
+
63
+
64
+ resolve(ctx: AontuContext, args: Val[]) {
65
+ let out = args[0] ?? makeNilErr(ctx, 'arg', this)
66
+
67
+ return out
68
+ }
69
+
70
+ }
71
+
72
+
73
+ export {
74
+ PathFuncVal,
75
+ }