@jdeighan/coffee-utils 11.0.34 → 11.0.35
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -3
- package/src/Section.coffee +4 -4
- package/src/Section.js +6 -4
- package/src/SectionMap.coffee +43 -36
- package/src/SectionMap.js +48 -37
- package/src/fs.coffee +4 -3
- package/src/fs.js +8 -3
- package/src/fsa.coffee +8 -8
- package/src/fsa.js +10 -8
- package/src/utils.coffee +4 -10
- package/src/utils.js +2 -9
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "11.0.
|
4
|
+
"version": "11.0.35",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -48,7 +48,7 @@
|
|
48
48
|
},
|
49
49
|
"homepage": "https://github.com/johndeighan/coffee-utils#readme",
|
50
50
|
"dependencies": {
|
51
|
-
"@jdeighan/exceptions": "^
|
51
|
+
"@jdeighan/exceptions": "^2.0.0",
|
52
52
|
"cross-env": "^7.0.3",
|
53
53
|
"js-yaml": "^4.1.0",
|
54
54
|
"n-readlines": "^1.0.1",
|
@@ -56,6 +56,6 @@
|
|
56
56
|
"svelte": "^3.52.0"
|
57
57
|
},
|
58
58
|
"devDependencies": {
|
59
|
-
"@jdeighan/unit-tester": "^2.0.
|
59
|
+
"@jdeighan/unit-tester": "^2.0.55"
|
60
60
|
}
|
61
61
|
}
|
package/src/Section.coffee
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Section.coffee
|
2
2
|
|
3
3
|
import {assert, croak} from '@jdeighan/exceptions'
|
4
|
-
import {
|
4
|
+
import {dbg, dbgEnter, dbgReturn} from '@jdeighan/exceptions/debug'
|
5
5
|
import {
|
6
6
|
pass, undef, defined, isArray, isEmpty, isFunction,
|
7
7
|
} from '@jdeighan/coffee-utils'
|
@@ -61,12 +61,12 @@ export class Section
|
|
61
61
|
|
62
62
|
getBlock: () ->
|
63
63
|
|
64
|
-
|
64
|
+
dbgEnter "Section.getBlock"
|
65
65
|
if (@lParts.length == 0)
|
66
|
-
|
66
|
+
dbgReturn "Section.getBlock", undef
|
67
67
|
return undef
|
68
68
|
block = toBlock(@lParts)
|
69
69
|
if defined(@replacer)
|
70
70
|
block = @replacer block
|
71
|
-
|
71
|
+
dbgReturn "Section.getBlock", block
|
72
72
|
return block
|
package/src/Section.js
CHANGED
@@ -6,7 +6,9 @@ import {
|
|
6
6
|
} from '@jdeighan/exceptions';
|
7
7
|
|
8
8
|
import {
|
9
|
-
|
9
|
+
dbg,
|
10
|
+
dbgEnter,
|
11
|
+
dbgReturn
|
10
12
|
} from '@jdeighan/exceptions/debug';
|
11
13
|
|
12
14
|
import {
|
@@ -74,16 +76,16 @@ export var Section = class Section {
|
|
74
76
|
// ..........................................................
|
75
77
|
getBlock() {
|
76
78
|
var block;
|
77
|
-
|
79
|
+
dbgEnter("Section.getBlock");
|
78
80
|
if (this.lParts.length === 0) {
|
79
|
-
|
81
|
+
dbgReturn("Section.getBlock", undef);
|
80
82
|
return undef;
|
81
83
|
}
|
82
84
|
block = toBlock(this.lParts);
|
83
85
|
if (defined(this.replacer)) {
|
84
86
|
block = this.replacer(block);
|
85
87
|
}
|
86
|
-
|
88
|
+
dbgReturn("Section.getBlock", block);
|
87
89
|
return block;
|
88
90
|
}
|
89
91
|
|
package/src/SectionMap.coffee
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# SectionMap.coffee
|
2
2
|
|
3
3
|
import {
|
4
|
-
assert, croak, LOG, LOGVALUE, LOGTAML,
|
4
|
+
assert, croak, LOG, LOGVALUE, LOGTAML, isTAML, fromTAML,
|
5
5
|
} from '@jdeighan/exceptions'
|
6
6
|
import {
|
7
|
-
|
7
|
+
dbg, dbgEnter, dbgReturn, dbgYield, dbgResume,
|
8
|
+
} from '@jdeighan/exceptions/debug'
|
9
|
+
import {
|
10
|
+
pass, undef, defined, notdefined, OL, isEmpty, nonEmpty,
|
8
11
|
isString, isHash, isArray, isUniqueTree, isNonEmptyString,
|
9
12
|
isNonEmptyArray, isFunction, jsType, isArrayOfStrings,
|
10
13
|
} from '@jdeighan/coffee-utils'
|
@@ -36,7 +39,7 @@ export class SectionMap
|
|
36
39
|
# <name> can be a section name or a set name
|
37
40
|
# <function> should be <block> -> <block>
|
38
41
|
|
39
|
-
|
42
|
+
dbgEnter "SectionMap", tree, @hReplacers
|
40
43
|
|
41
44
|
@checkTree tree
|
42
45
|
@checkReplacers @hReplacers
|
@@ -46,34 +49,34 @@ export class SectionMap
|
|
46
49
|
|
47
50
|
@init @lFullTree
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
dbg 'hSections', @hSections
|
53
|
+
dbg 'hSets', @hSets
|
54
|
+
dbgReturn "SectionMap"
|
52
55
|
|
53
56
|
# ..........................................................
|
54
57
|
|
55
58
|
init: (lTree) ->
|
56
59
|
|
57
|
-
|
60
|
+
dbgEnter "init", lTree
|
58
61
|
assert isArray(lTree), "not an array"
|
59
62
|
assert nonEmpty(lTree), "empty array"
|
60
63
|
|
61
64
|
firstItem = lTree[0]
|
62
65
|
if isSetName(firstItem)
|
63
|
-
|
66
|
+
dbg "found set name #{OL(firstItem)}"
|
64
67
|
lTree = lTree.slice(1)
|
65
68
|
@mkSet firstItem, lTree
|
66
69
|
|
67
70
|
for item in lTree
|
68
71
|
if isArray(item)
|
69
|
-
|
72
|
+
dbg "init subtree"
|
70
73
|
@init item
|
71
74
|
else if isSectionName(item)
|
72
|
-
|
75
|
+
dbg "mkSection #{OL(item)}"
|
73
76
|
@mkSection item
|
74
77
|
else
|
75
78
|
assert isString(item), "Bad item in tree: #{OL(item)}"
|
76
|
-
|
79
|
+
dbgReturn "init"
|
77
80
|
return
|
78
81
|
|
79
82
|
# ..........................................................
|
@@ -82,7 +85,7 @@ export class SectionMap
|
|
82
85
|
|
83
86
|
assert isArray(lTree), "tree is not an array"
|
84
87
|
assert nonEmpty(lTree), "set without sections"
|
85
|
-
assert
|
88
|
+
assert notdefined(@hSets[name]), "set #{OL(name)} already exists"
|
86
89
|
@hSets[name] = lTree
|
87
90
|
return
|
88
91
|
|
@@ -90,7 +93,7 @@ export class SectionMap
|
|
90
93
|
|
91
94
|
mkSection: (name) ->
|
92
95
|
|
93
|
-
assert
|
96
|
+
assert notdefined(@hSections[name]), "duplicate section name"
|
94
97
|
@hSections[name] = new Section(name, @hReplacers[name])
|
95
98
|
return
|
96
99
|
|
@@ -104,19 +107,17 @@ export class SectionMap
|
|
104
107
|
# an array of section or set names or literal strings
|
105
108
|
# i.e. it should NOT contain sub-arrays
|
106
109
|
|
107
|
-
if isString(desc)
|
108
|
-
|
109
|
-
else if isArrayOfStrings(desc)
|
110
|
-
debug "enter SectionMap.getBlock()", desc
|
110
|
+
if isString(desc) || isArrayOfStrings(desc)
|
111
|
+
dbgEnter "SectionMap.getBlock", desc
|
111
112
|
else
|
112
113
|
croak "Bad desc: #{OL(desc)}"
|
113
114
|
|
114
115
|
if isSectionName(desc)
|
115
|
-
|
116
|
+
dbg "item is a section name"
|
116
117
|
# --- a section's getBlock() applies any replacer
|
117
118
|
block = @section(desc).getBlock()
|
118
119
|
else if isSetName(desc)
|
119
|
-
|
120
|
+
dbg "item is a set name"
|
120
121
|
lBlocks = for item in @hSets[desc]
|
121
122
|
if isArray(item)
|
122
123
|
@getBlock item[0]
|
@@ -126,22 +127,22 @@ export class SectionMap
|
|
126
127
|
croak "Item in set #{desc} is not a string or array"
|
127
128
|
block = toBlock(lBlocks)
|
128
129
|
replacer = @hReplacers[desc]
|
129
|
-
|
130
|
-
if
|
130
|
+
dbg "replacer for is #{OL(replacer)}"
|
131
|
+
if defined(replacer)
|
131
132
|
block = replacer(block)
|
132
133
|
else if isString(desc)
|
133
|
-
|
134
|
+
dbg "item is a literal string"
|
134
135
|
# --- a literal string
|
135
136
|
block = desc
|
136
137
|
else if isArray(desc)
|
137
|
-
|
138
|
+
dbg "item is an array"
|
138
139
|
lBlocks = for item in desc
|
139
140
|
@getBlock(item)
|
140
141
|
block = toBlock(lBlocks)
|
141
142
|
else
|
142
143
|
croak "Bad arg: #{OL(desc)}"
|
143
144
|
|
144
|
-
|
145
|
+
dbgReturn "SectionMap.getBlock", block
|
145
146
|
return block
|
146
147
|
|
147
148
|
# ..........................................................
|
@@ -150,22 +151,28 @@ export class SectionMap
|
|
150
151
|
|
151
152
|
allSections: (desc=undef) ->
|
152
153
|
|
153
|
-
|
154
|
-
if
|
154
|
+
dbgEnter "allSections", desc
|
155
|
+
if notdefined(desc)
|
155
156
|
desc = @lFullTree
|
156
157
|
|
157
158
|
if isSectionName(desc)
|
158
|
-
|
159
|
+
dbg "is section name"
|
160
|
+
dbgYield "allSections", @section(desc)
|
159
161
|
yield @section(desc)
|
162
|
+
dbgResume "allSections"
|
160
163
|
else if isSetName(desc)
|
161
|
-
|
164
|
+
dbg "is set name"
|
162
165
|
for name in @hSets[desc]
|
166
|
+
dbgYield "allSections"
|
163
167
|
yield from @allSections(name)
|
168
|
+
dbgResume "allSections"
|
164
169
|
else if isArray(desc)
|
165
|
-
|
170
|
+
dbg "is array"
|
166
171
|
for item in desc
|
172
|
+
dbgYield "allSections"
|
167
173
|
yield from @allSections(item)
|
168
|
-
|
174
|
+
dbgResume "allSections"
|
175
|
+
dbgReturn "allSections"
|
169
176
|
return
|
170
177
|
|
171
178
|
# ..........................................................
|
@@ -191,7 +198,7 @@ export class SectionMap
|
|
191
198
|
section: (name) ->
|
192
199
|
|
193
200
|
sect = @hSections[name]
|
194
|
-
assert
|
201
|
+
assert defined(sect), "No section named #{OL(name)}"
|
195
202
|
return sect
|
196
203
|
|
197
204
|
# ..........................................................
|
@@ -200,7 +207,7 @@ export class SectionMap
|
|
200
207
|
|
201
208
|
assert isSetName(name), "bad set name #{OL(name)}"
|
202
209
|
lSubTree = @hSets[name]
|
203
|
-
assert
|
210
|
+
assert defined(lSubTree), "no such set #{OL(name)}"
|
204
211
|
return @section(lSubTree[0])
|
205
212
|
|
206
213
|
# ..........................................................
|
@@ -209,16 +216,16 @@ export class SectionMap
|
|
209
216
|
|
210
217
|
assert isSetName(name), "bad set name #{OL(name)}"
|
211
218
|
lSubTree = @hSets[name]
|
212
|
-
assert
|
219
|
+
assert defined(lSubTree), "no such set #{OL(name)}"
|
213
220
|
return @section(lSubTree[lSubTree.length - 1])
|
214
221
|
|
215
222
|
# ..........................................................
|
216
223
|
|
217
224
|
checkTree: (tree) ->
|
218
225
|
|
219
|
-
|
226
|
+
dbgEnter "checkTree"
|
220
227
|
if isString(tree)
|
221
|
-
|
228
|
+
dbg "tree is a string"
|
222
229
|
assert isTAML(tree), "not TAML"
|
223
230
|
@lFullTree = fromTAML(tree)
|
224
231
|
else
|
@@ -229,7 +236,7 @@ export class SectionMap
|
|
229
236
|
if isSetName(@lFullTree[0])
|
230
237
|
LOGTAML 'lFullTree', @lFullTree
|
231
238
|
croak "tree cannot begin with a set name"
|
232
|
-
|
239
|
+
dbgReturn "checkTree"
|
233
240
|
return
|
234
241
|
|
235
242
|
# ..........................................................
|
package/src/SectionMap.js
CHANGED
@@ -8,16 +8,23 @@ import {
|
|
8
8
|
LOG,
|
9
9
|
LOGVALUE,
|
10
10
|
LOGTAML,
|
11
|
-
debug,
|
12
11
|
isTAML,
|
13
12
|
fromTAML
|
14
13
|
} from '@jdeighan/exceptions';
|
15
14
|
|
15
|
+
import {
|
16
|
+
dbg,
|
17
|
+
dbgEnter,
|
18
|
+
dbgReturn,
|
19
|
+
dbgYield,
|
20
|
+
dbgResume
|
21
|
+
} from '@jdeighan/exceptions/debug';
|
22
|
+
|
16
23
|
import {
|
17
24
|
pass,
|
18
25
|
undef,
|
19
|
-
|
20
|
-
|
26
|
+
defined,
|
27
|
+
notdefined,
|
21
28
|
OL,
|
22
29
|
isEmpty,
|
23
30
|
nonEmpty,
|
@@ -61,7 +68,7 @@ export var SectionMap = class SectionMap {
|
|
61
68
|
// should be <name> -> <function>
|
62
69
|
// <name> can be a section name or a set name
|
63
70
|
// <function> should be <block> -> <block>
|
64
|
-
|
71
|
+
dbgEnter("SectionMap", tree, this.hReplacers);
|
65
72
|
this.checkTree(tree);
|
66
73
|
this.checkReplacers(this.hReplacers);
|
67
74
|
this.hSections = {}; // --- {section name: Section Object}
|
@@ -69,49 +76,49 @@ export var SectionMap = class SectionMap {
|
|
69
76
|
ALL: this.lFullTree // --- {set name: array of parts}
|
70
77
|
};
|
71
78
|
this.init(this.lFullTree);
|
72
|
-
|
73
|
-
|
74
|
-
|
79
|
+
dbg('hSections', this.hSections);
|
80
|
+
dbg('hSets', this.hSets);
|
81
|
+
dbgReturn("SectionMap");
|
75
82
|
}
|
76
83
|
|
77
84
|
// ..........................................................
|
78
85
|
init(lTree) {
|
79
86
|
var firstItem, i, item, len;
|
80
|
-
|
87
|
+
dbgEnter("init", lTree);
|
81
88
|
assert(isArray(lTree), "not an array");
|
82
89
|
assert(nonEmpty(lTree), "empty array");
|
83
90
|
firstItem = lTree[0];
|
84
91
|
if (isSetName(firstItem)) {
|
85
|
-
|
92
|
+
dbg(`found set name ${OL(firstItem)}`);
|
86
93
|
lTree = lTree.slice(1);
|
87
94
|
this.mkSet(firstItem, lTree);
|
88
95
|
}
|
89
96
|
for (i = 0, len = lTree.length; i < len; i++) {
|
90
97
|
item = lTree[i];
|
91
98
|
if (isArray(item)) {
|
92
|
-
|
99
|
+
dbg("init subtree");
|
93
100
|
this.init(item);
|
94
101
|
} else if (isSectionName(item)) {
|
95
|
-
|
102
|
+
dbg(`mkSection ${OL(item)}`);
|
96
103
|
this.mkSection(item);
|
97
104
|
} else {
|
98
105
|
assert(isString(item), `Bad item in tree: ${OL(item)}`);
|
99
106
|
}
|
100
107
|
}
|
101
|
-
|
108
|
+
dbgReturn("init");
|
102
109
|
}
|
103
110
|
|
104
111
|
// ..........................................................
|
105
112
|
mkSet(name, lTree) {
|
106
113
|
assert(isArray(lTree), "tree is not an array");
|
107
114
|
assert(nonEmpty(lTree), "set without sections");
|
108
|
-
assert(
|
115
|
+
assert(notdefined(this.hSets[name]), `set ${OL(name)} already exists`);
|
109
116
|
this.hSets[name] = lTree;
|
110
117
|
}
|
111
118
|
|
112
119
|
// ..........................................................
|
113
120
|
mkSection(name) {
|
114
|
-
assert(
|
121
|
+
assert(notdefined(this.hSections[name]), "duplicate section name");
|
115
122
|
this.hSections[name] = new Section(name, this.hReplacers[name]);
|
116
123
|
}
|
117
124
|
|
@@ -124,19 +131,17 @@ export var SectionMap = class SectionMap {
|
|
124
131
|
// a set name
|
125
132
|
// an array of section or set names or literal strings
|
126
133
|
// i.e. it should NOT contain sub-arrays
|
127
|
-
if (isString(desc)) {
|
128
|
-
|
129
|
-
} else if (isArrayOfStrings(desc)) {
|
130
|
-
debug("enter SectionMap.getBlock()", desc);
|
134
|
+
if (isString(desc) || isArrayOfStrings(desc)) {
|
135
|
+
dbgEnter("SectionMap.getBlock", desc);
|
131
136
|
} else {
|
132
137
|
croak(`Bad desc: ${OL(desc)}`);
|
133
138
|
}
|
134
139
|
if (isSectionName(desc)) {
|
135
|
-
|
140
|
+
dbg("item is a section name");
|
136
141
|
// --- a section's getBlock() applies any replacer
|
137
142
|
block = this.section(desc).getBlock();
|
138
143
|
} else if (isSetName(desc)) {
|
139
|
-
|
144
|
+
dbg("item is a set name");
|
140
145
|
lBlocks = (function() {
|
141
146
|
var i, len, ref, results;
|
142
147
|
ref = this.hSets[desc];
|
@@ -155,16 +160,16 @@ export var SectionMap = class SectionMap {
|
|
155
160
|
}).call(this);
|
156
161
|
block = toBlock(lBlocks);
|
157
162
|
replacer = this.hReplacers[desc];
|
158
|
-
|
159
|
-
if (
|
163
|
+
dbg(`replacer for is ${OL(replacer)}`);
|
164
|
+
if (defined(replacer)) {
|
160
165
|
block = replacer(block);
|
161
166
|
}
|
162
167
|
} else if (isString(desc)) {
|
163
|
-
|
168
|
+
dbg("item is a literal string");
|
164
169
|
// --- a literal string
|
165
170
|
block = desc;
|
166
171
|
} else if (isArray(desc)) {
|
167
|
-
|
172
|
+
dbg("item is an array");
|
168
173
|
lBlocks = (function() {
|
169
174
|
var i, len, results;
|
170
175
|
results = [];
|
@@ -178,7 +183,7 @@ export var SectionMap = class SectionMap {
|
|
178
183
|
} else {
|
179
184
|
croak(`Bad arg: ${OL(desc)}`);
|
180
185
|
}
|
181
|
-
|
186
|
+
dbgReturn("SectionMap.getBlock", block);
|
182
187
|
return block;
|
183
188
|
}
|
184
189
|
|
@@ -187,28 +192,34 @@ export var SectionMap = class SectionMap {
|
|
187
192
|
// so only useful for isEmpty() and nonEmpty()
|
188
193
|
* allSections(desc = undef) {
|
189
194
|
var i, item, j, len, len1, name, ref;
|
190
|
-
|
191
|
-
if (
|
195
|
+
dbgEnter("allSections", desc);
|
196
|
+
if (notdefined(desc)) {
|
192
197
|
desc = this.lFullTree;
|
193
198
|
}
|
194
199
|
if (isSectionName(desc)) {
|
195
|
-
|
200
|
+
dbg("is section name");
|
201
|
+
dbgYield("allSections", this.section(desc));
|
196
202
|
yield this.section(desc);
|
203
|
+
dbgResume("allSections");
|
197
204
|
} else if (isSetName(desc)) {
|
198
|
-
|
205
|
+
dbg("is set name");
|
199
206
|
ref = this.hSets[desc];
|
200
207
|
for (i = 0, len = ref.length; i < len; i++) {
|
201
208
|
name = ref[i];
|
209
|
+
dbgYield("allSections");
|
202
210
|
yield* this.allSections(name);
|
211
|
+
dbgResume("allSections");
|
203
212
|
}
|
204
213
|
} else if (isArray(desc)) {
|
205
|
-
|
214
|
+
dbg("is array");
|
206
215
|
for (j = 0, len1 = desc.length; j < len1; j++) {
|
207
216
|
item = desc[j];
|
217
|
+
dbgYield("allSections");
|
208
218
|
yield* this.allSections(item);
|
219
|
+
dbgResume("allSections");
|
209
220
|
}
|
210
221
|
}
|
211
|
-
|
222
|
+
dbgReturn("allSections");
|
212
223
|
}
|
213
224
|
|
214
225
|
// ..........................................................
|
@@ -239,7 +250,7 @@ export var SectionMap = class SectionMap {
|
|
239
250
|
section(name) {
|
240
251
|
var sect;
|
241
252
|
sect = this.hSections[name];
|
242
|
-
assert(
|
253
|
+
assert(defined(sect), `No section named ${OL(name)}`);
|
243
254
|
return sect;
|
244
255
|
}
|
245
256
|
|
@@ -248,7 +259,7 @@ export var SectionMap = class SectionMap {
|
|
248
259
|
var lSubTree;
|
249
260
|
assert(isSetName(name), `bad set name ${OL(name)}`);
|
250
261
|
lSubTree = this.hSets[name];
|
251
|
-
assert(
|
262
|
+
assert(defined(lSubTree), `no such set ${OL(name)}`);
|
252
263
|
return this.section(lSubTree[0]);
|
253
264
|
}
|
254
265
|
|
@@ -257,15 +268,15 @@ export var SectionMap = class SectionMap {
|
|
257
268
|
var lSubTree;
|
258
269
|
assert(isSetName(name), `bad set name ${OL(name)}`);
|
259
270
|
lSubTree = this.hSets[name];
|
260
|
-
assert(
|
271
|
+
assert(defined(lSubTree), `no such set ${OL(name)}`);
|
261
272
|
return this.section(lSubTree[lSubTree.length - 1]);
|
262
273
|
}
|
263
274
|
|
264
275
|
// ..........................................................
|
265
276
|
checkTree(tree) {
|
266
|
-
|
277
|
+
dbgEnter("checkTree");
|
267
278
|
if (isString(tree)) {
|
268
|
-
|
279
|
+
dbg("tree is a string");
|
269
280
|
assert(isTAML(tree), "not TAML");
|
270
281
|
this.lFullTree = fromTAML(tree);
|
271
282
|
} else {
|
@@ -277,7 +288,7 @@ export var SectionMap = class SectionMap {
|
|
277
288
|
LOGTAML('lFullTree', this.lFullTree);
|
278
289
|
croak("tree cannot begin with a set name");
|
279
290
|
}
|
280
|
-
|
291
|
+
dbgReturn("checkTree");
|
281
292
|
}
|
282
293
|
|
283
294
|
// ..........................................................
|
package/src/fs.coffee
CHANGED
@@ -5,7 +5,8 @@ import urllib from 'url'
|
|
5
5
|
import fs from 'fs'
|
6
6
|
import NReadLines from 'n-readlines'
|
7
7
|
|
8
|
-
import {assert, croak,
|
8
|
+
import {assert, croak, LOG, fromTAML} from '@jdeighan/exceptions'
|
9
|
+
import {dbg, dbgEnter, dbgReturn} from '@jdeighan/exceptions/debug'
|
9
10
|
import {
|
10
11
|
undef, pass, defined, rtrim, isEmpty, nonEmpty, getOptions,
|
11
12
|
isString, isArray, isHash, isRegExp, isFunction, OL,
|
@@ -377,7 +378,7 @@ export parseSource = (source) ->
|
|
377
378
|
# }
|
378
379
|
# --- NOTE: source may be a file URL, e.g. import.meta.url
|
379
380
|
|
380
|
-
|
381
|
+
dbgEnter "parseSource", source
|
381
382
|
assert isString(source),\
|
382
383
|
"parseSource(): source not a string: #{OL(source)}"
|
383
384
|
if source == 'unit test'
|
@@ -414,7 +415,7 @@ export parseSource = (source) ->
|
|
414
415
|
([A-Za-z_]+)
|
415
416
|
$///)
|
416
417
|
hSourceInfo.purpose = lMatches[1]
|
417
|
-
|
418
|
+
dbgReturn "parseSource", hSourceInfo
|
418
419
|
return hSourceInfo
|
419
420
|
|
420
421
|
# ---------------------------------------------------------------------------
|
package/src/fs.js
CHANGED
@@ -13,11 +13,16 @@ import NReadLines from 'n-readlines';
|
|
13
13
|
import {
|
14
14
|
assert,
|
15
15
|
croak,
|
16
|
-
debug,
|
17
16
|
LOG,
|
18
17
|
fromTAML
|
19
18
|
} from '@jdeighan/exceptions';
|
20
19
|
|
20
|
+
import {
|
21
|
+
dbg,
|
22
|
+
dbgEnter,
|
23
|
+
dbgReturn
|
24
|
+
} from '@jdeighan/exceptions/debug';
|
25
|
+
|
21
26
|
import {
|
22
27
|
undef,
|
23
28
|
pass,
|
@@ -447,7 +452,7 @@ export var parseSource = function(source) {
|
|
447
452
|
// purpose
|
448
453
|
// }
|
449
454
|
// --- NOTE: source may be a file URL, e.g. import.meta.url
|
450
|
-
|
455
|
+
dbgEnter("parseSource", source);
|
451
456
|
assert(isString(source), `parseSource(): source not a string: ${OL(source)}`);
|
452
457
|
if (source === 'unit test') {
|
453
458
|
croak("A source of 'unit test' is deprecated");
|
@@ -483,7 +488,7 @@ export var parseSource = function(source) {
|
|
483
488
|
hSourceInfo.purpose = lMatches[1];
|
484
489
|
}
|
485
490
|
}
|
486
|
-
|
491
|
+
dbgReturn("parseSource", hSourceInfo);
|
487
492
|
return hSourceInfo;
|
488
493
|
};
|
489
494
|
|
package/src/fsa.coffee
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import {assert, croak} from '@jdeighan/exceptions'
|
4
4
|
import {LOG} from '@jdeighan/exceptions/log'
|
5
|
-
import {
|
5
|
+
import {dbg, dbgEnter, dbgReturn} from '@jdeighan/exceptions/debug'
|
6
6
|
import {
|
7
7
|
undef, defined, notdefined, words, isEmpty, nonEmpty,
|
8
8
|
isString, OL,
|
@@ -15,13 +15,13 @@ export class FSA
|
|
15
15
|
|
16
16
|
constructor: (block) ->
|
17
17
|
|
18
|
-
|
18
|
+
dbgEnter "FSA", block
|
19
19
|
assert isString(block), "block not a string"
|
20
20
|
@hTransitions = {}
|
21
21
|
lLines = toArray(block, 'noEmptyLines')
|
22
|
-
|
22
|
+
dbg 'lLines', lLines
|
23
23
|
for line,i in lLines
|
24
|
-
|
24
|
+
dbg "LINE #{i}", line
|
25
25
|
lWords = words(line)
|
26
26
|
if (lWords.length == 3)
|
27
27
|
[bState, token, eState] = lWords
|
@@ -30,7 +30,7 @@ export class FSA
|
|
30
30
|
[bState, token, eState, output] = lWords
|
31
31
|
else
|
32
32
|
croak "Invalid desc: #{OL(line)}"
|
33
|
-
|
33
|
+
dbg "LINE #{i}: #{OL(bState)} #{OL(token)} #{OL(eState)} #{OL(output)}"
|
34
34
|
assert nonEmpty(eState), "Invalid FSA description #{i}"
|
35
35
|
|
36
36
|
# --- tokens may be quoted (but may not contain whitespace),
|
@@ -38,7 +38,7 @@ export class FSA
|
|
38
38
|
if (i == 0)
|
39
39
|
assert (bState == 'start'), "Invalid FSA description #{i}"
|
40
40
|
token = @fixToken(token)
|
41
|
-
|
41
|
+
dbg 'token', token
|
42
42
|
if isEmpty(output)
|
43
43
|
output = undef
|
44
44
|
hTrans = @hTransitions[bState]
|
@@ -46,9 +46,9 @@ export class FSA
|
|
46
46
|
hTrans = @hTransitions[bState] = {}
|
47
47
|
assert notdefined(hTrans[token]), "Duplicate transition"
|
48
48
|
hTrans[token] = [eState, output]
|
49
|
-
|
49
|
+
dbg 'hTransitions', @hTransitions
|
50
50
|
@curState = 'start'
|
51
|
-
|
51
|
+
dbgReturn "FSA"
|
52
52
|
|
53
53
|
# ..........................................................
|
54
54
|
|
package/src/fsa.js
CHANGED
@@ -10,7 +10,9 @@ import {
|
|
10
10
|
} from '@jdeighan/exceptions/log';
|
11
11
|
|
12
12
|
import {
|
13
|
-
|
13
|
+
dbg,
|
14
|
+
dbgEnter,
|
15
|
+
dbgReturn
|
14
16
|
} from '@jdeighan/exceptions/debug';
|
15
17
|
|
16
18
|
import {
|
@@ -32,14 +34,14 @@ import {
|
|
32
34
|
export var FSA = class FSA {
|
33
35
|
constructor(block) {
|
34
36
|
var bState, eState, hTrans, i, j, lLines, lWords, len, line, output, token;
|
35
|
-
|
37
|
+
dbgEnter("FSA", block);
|
36
38
|
assert(isString(block), "block not a string");
|
37
39
|
this.hTransitions = {};
|
38
40
|
lLines = toArray(block, 'noEmptyLines');
|
39
|
-
|
41
|
+
dbg('lLines', lLines);
|
40
42
|
for (i = j = 0, len = lLines.length; j < len; i = ++j) {
|
41
43
|
line = lLines[i];
|
42
|
-
|
44
|
+
dbg(`LINE ${i}`, line);
|
43
45
|
lWords = words(line);
|
44
46
|
if (lWords.length === 3) {
|
45
47
|
[bState, token, eState] = lWords;
|
@@ -49,7 +51,7 @@ export var FSA = class FSA {
|
|
49
51
|
} else {
|
50
52
|
croak(`Invalid desc: ${OL(line)}`);
|
51
53
|
}
|
52
|
-
|
54
|
+
dbg(`LINE ${i}: ${OL(bState)} ${OL(token)} ${OL(eState)} ${OL(output)}`);
|
53
55
|
assert(nonEmpty(eState), `Invalid FSA description ${i}`);
|
54
56
|
// --- tokens may be quoted (but may not contain whitespace),
|
55
57
|
// but the quotes are stripped
|
@@ -57,7 +59,7 @@ export var FSA = class FSA {
|
|
57
59
|
assert(bState === 'start', `Invalid FSA description ${i}`);
|
58
60
|
}
|
59
61
|
token = this.fixToken(token);
|
60
|
-
|
62
|
+
dbg('token', token);
|
61
63
|
if (isEmpty(output)) {
|
62
64
|
output = undef;
|
63
65
|
}
|
@@ -68,9 +70,9 @@ export var FSA = class FSA {
|
|
68
70
|
assert(notdefined(hTrans[token]), "Duplicate transition");
|
69
71
|
hTrans[token] = [eState, output];
|
70
72
|
}
|
71
|
-
|
73
|
+
dbg('hTransitions', this.hTransitions);
|
72
74
|
this.curState = 'start';
|
73
|
-
|
75
|
+
dbgReturn("FSA");
|
74
76
|
}
|
75
77
|
|
76
78
|
// ..........................................................
|
package/src/utils.coffee
CHANGED
@@ -3,20 +3,20 @@
|
|
3
3
|
import {assert, croak} from '@jdeighan/exceptions'
|
4
4
|
import {LOG, sep_dash, sep_eq} from '@jdeighan/exceptions/log'
|
5
5
|
import {
|
6
|
-
undef, pass,
|
6
|
+
undef, pass, defined, notdefined,
|
7
7
|
deepCopy, escapeStr, unescapeStr, hasChar, quoted, OL,
|
8
8
|
isString, isNumber, isInteger, isHash, isArray, isBoolean,
|
9
9
|
isConstructor, isFunction, isRegExp, isObject, getClassName,
|
10
|
-
jsType,
|
10
|
+
jsType, oneof,
|
11
11
|
isEmpty, nonEmpty, chomp, rtrim, setCharsAt, words, getOptions,
|
12
12
|
} from '@jdeighan/exceptions/utils'
|
13
13
|
|
14
14
|
export {
|
15
|
-
undef, pass,
|
15
|
+
undef, pass, defined, notdefined, LOG, sep_dash, sep_eq,
|
16
16
|
deepCopy, escapeStr, unescapeStr, hasChar, quoted, OL,
|
17
17
|
isString, isNumber, isInteger, isHash, isArray, isBoolean,
|
18
18
|
isConstructor, isFunction, isRegExp, isObject, getClassName,
|
19
|
-
jsType,
|
19
|
+
jsType, oneof,
|
20
20
|
isEmpty, nonEmpty, chomp, rtrim, setCharsAt, words, getOptions,
|
21
21
|
}
|
22
22
|
|
@@ -68,12 +68,6 @@ export charCount = (str, ch) ->
|
|
68
68
|
|
69
69
|
# ---------------------------------------------------------------------------
|
70
70
|
|
71
|
-
export oneof = (word, lWords...) ->
|
72
|
-
|
73
|
-
return (lWords.indexOf(word) >= 0)
|
74
|
-
|
75
|
-
# ---------------------------------------------------------------------------
|
76
|
-
|
77
71
|
export removeKeys = (h, lKeys) =>
|
78
72
|
|
79
73
|
for key in lKeys
|
package/src/utils.js
CHANGED
@@ -16,9 +16,7 @@ import {
|
|
16
16
|
import {
|
17
17
|
undef,
|
18
18
|
pass,
|
19
|
-
def,
|
20
19
|
defined,
|
21
|
-
notdef,
|
22
20
|
notdefined,
|
23
21
|
deepCopy,
|
24
22
|
escapeStr,
|
@@ -38,6 +36,7 @@ import {
|
|
38
36
|
isObject,
|
39
37
|
getClassName,
|
40
38
|
jsType,
|
39
|
+
oneof,
|
41
40
|
isEmpty,
|
42
41
|
nonEmpty,
|
43
42
|
chomp,
|
@@ -50,9 +49,7 @@ import {
|
|
50
49
|
export {
|
51
50
|
undef,
|
52
51
|
pass,
|
53
|
-
def,
|
54
52
|
defined,
|
55
|
-
notdef,
|
56
53
|
notdefined,
|
57
54
|
LOG,
|
58
55
|
sep_dash,
|
@@ -75,6 +72,7 @@ export {
|
|
75
72
|
isObject,
|
76
73
|
getClassName,
|
77
74
|
jsType,
|
75
|
+
oneof,
|
78
76
|
isEmpty,
|
79
77
|
nonEmpty,
|
80
78
|
chomp,
|
@@ -125,11 +123,6 @@ export var charCount = function(str, ch) {
|
|
125
123
|
return count;
|
126
124
|
};
|
127
125
|
|
128
|
-
// ---------------------------------------------------------------------------
|
129
|
-
export var oneof = function(word, ...lWords) {
|
130
|
-
return lWords.indexOf(word) >= 0;
|
131
|
-
};
|
132
|
-
|
133
126
|
// ---------------------------------------------------------------------------
|
134
127
|
export var removeKeys = (h, lKeys) => {
|
135
128
|
var i, item, j, key, len, len1, value;
|