@jdeighan/coffee-utils 6.0.5 → 6.0.8
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/package.json +1 -1
- package/src/call_stack.coffee +13 -9
- package/src/call_stack.js +16 -11
- package/src/log_utils.coffee +2 -0
- package/src/log_utils.js +3 -0
- package/src/taml.coffee +30 -3
- package/src/taml.js +35 -3
package/package.json
CHANGED
package/src/call_stack.coffee
CHANGED
@@ -25,27 +25,31 @@ export class CallStack
|
|
25
25
|
call: (funcName, hInfo) ->
|
26
26
|
|
27
27
|
if doDebugStack
|
28
|
-
|
28
|
+
prefix = ' '.repeat(@lStack.length)
|
29
|
+
LOG "#{prefix}[--> CALL #{funcName}]"
|
29
30
|
@lStack.push({funcName, hInfo})
|
30
31
|
return
|
31
32
|
|
32
33
|
# ........................................................................
|
33
34
|
|
34
|
-
returnFrom: (
|
35
|
+
returnFrom: (fName) ->
|
35
36
|
|
36
|
-
if doDebugStack
|
37
|
-
LOG "[RETURN FROM #{funcName}]"
|
38
37
|
if @lStack.length == 0
|
39
|
-
LOG "returnFrom('#{
|
38
|
+
LOG "returnFrom('#{fName}') but stack is empty"
|
40
39
|
return undef
|
41
|
-
|
42
|
-
|
40
|
+
{funcName, hInfo} = @lStack.pop()
|
41
|
+
while (funcName != fName) && (@lStack.length > 0)
|
42
|
+
LOG "[MISSING RETURN FROM #{funcName} (return from #{fName})]"
|
43
43
|
{funcName, hInfo} = @lStack.pop()
|
44
|
-
|
44
|
+
|
45
|
+
if doDebugStack
|
46
|
+
prefix = ' '.repeat(@lStack.length)
|
47
|
+
LOG "#{prefix}[<-- BACK #{fName}]"
|
48
|
+
if (funcName == fName)
|
45
49
|
return hInfo
|
46
50
|
else
|
47
51
|
@dump()
|
48
|
-
LOG "returnFrom('#{
|
52
|
+
LOG "BAD returnFrom('#{fName}')"
|
49
53
|
return undef
|
50
54
|
|
51
55
|
# ........................................................................
|
package/src/call_stack.js
CHANGED
@@ -28,30 +28,35 @@ export var CallStack = class CallStack {
|
|
28
28
|
|
29
29
|
// ........................................................................
|
30
30
|
call(funcName, hInfo) {
|
31
|
+
var prefix;
|
31
32
|
if (doDebugStack) {
|
32
|
-
|
33
|
+
prefix = ' '.repeat(this.lStack.length);
|
34
|
+
LOG(`${prefix}[--> CALL ${funcName}]`);
|
33
35
|
}
|
34
36
|
this.lStack.push({funcName, hInfo});
|
35
37
|
}
|
36
38
|
|
37
39
|
// ........................................................................
|
38
|
-
returnFrom(
|
39
|
-
var
|
40
|
-
if (doDebugStack) {
|
41
|
-
LOG(`[RETURN FROM ${funcName}]`);
|
42
|
-
}
|
40
|
+
returnFrom(fName) {
|
41
|
+
var funcName, hInfo, prefix;
|
43
42
|
if (this.lStack.length === 0) {
|
44
|
-
LOG(`returnFrom('${
|
43
|
+
LOG(`returnFrom('${fName}') but stack is empty`);
|
45
44
|
return undef;
|
46
45
|
}
|
47
|
-
|
48
|
-
|
46
|
+
({funcName, hInfo} = this.lStack.pop());
|
47
|
+
while ((funcName !== fName) && (this.lStack.length > 0)) {
|
48
|
+
LOG(`[MISSING RETURN FROM ${funcName} (return from ${fName})]`);
|
49
49
|
({funcName, hInfo} = this.lStack.pop());
|
50
|
-
|
50
|
+
}
|
51
|
+
if (doDebugStack) {
|
52
|
+
prefix = ' '.repeat(this.lStack.length);
|
53
|
+
LOG(`${prefix}[<-- BACK ${fName}]`);
|
54
|
+
}
|
55
|
+
if (funcName === fName) {
|
51
56
|
return hInfo;
|
52
57
|
} else {
|
53
58
|
this.dump();
|
54
|
-
LOG(`returnFrom('${
|
59
|
+
LOG(`BAD returnFrom('${fName}')`);
|
55
60
|
return undef;
|
56
61
|
}
|
57
62
|
}
|
package/src/log_utils.coffee
CHANGED
package/src/log_utils.js
CHANGED
package/src/taml.coffee
CHANGED
@@ -5,11 +5,13 @@ import yaml from 'js-yaml'
|
|
5
5
|
import {
|
6
6
|
assert, undef, oneline, isString,
|
7
7
|
} from '@jdeighan/coffee-utils'
|
8
|
-
import {untabify, tabify} from '@jdeighan/coffee-utils/indent'
|
8
|
+
import {untabify, tabify, splitLine} from '@jdeighan/coffee-utils/indent'
|
9
9
|
import {log, tamlStringify} from '@jdeighan/coffee-utils/log'
|
10
10
|
import {slurp} from '@jdeighan/coffee-utils/fs'
|
11
11
|
import {debug} from '@jdeighan/coffee-utils/debug'
|
12
|
-
import {
|
12
|
+
import {
|
13
|
+
firstLine, blockToArray, arrayToBlock,
|
14
|
+
} from '@jdeighan/coffee-utils/block'
|
13
15
|
|
14
16
|
# ---------------------------------------------------------------------------
|
15
17
|
# isTAML - is the string valid TAML?
|
@@ -18,6 +20,12 @@ export isTAML = (text) ->
|
|
18
20
|
|
19
21
|
return isString(text) && (firstLine(text).indexOf('---') == 0)
|
20
22
|
|
23
|
+
# ---------------------------------------------------------------------------
|
24
|
+
|
25
|
+
squote = (text) ->
|
26
|
+
|
27
|
+
return "'" + text.replace(/'/g, "''") + "'"
|
28
|
+
|
21
29
|
# ---------------------------------------------------------------------------
|
22
30
|
# taml - convert valid TAML string to a JavaScript value
|
23
31
|
|
@@ -28,8 +36,27 @@ export taml = (text) ->
|
|
28
36
|
debug "return undef from taml() - text is not defined"
|
29
37
|
return undef
|
30
38
|
assert isTAML(text), "taml(): string #{oneline(text)} isn't TAML"
|
39
|
+
|
40
|
+
lLines = for line in blockToArray(text)
|
41
|
+
[level, str] = splitLine(line)
|
42
|
+
prefix = ' '.repeat(level)
|
43
|
+
if lMatches = line.match(///^
|
44
|
+
([A-Za-z_][A-Za-z0-9_]*) # the key
|
45
|
+
\s*
|
46
|
+
:
|
47
|
+
\s*
|
48
|
+
(.*)
|
49
|
+
$///)
|
50
|
+
[_, key, text] = lMatches
|
51
|
+
if isEmpty(text) || text.match(/\d+(?:\.\d*)$/)
|
52
|
+
prefix + str
|
53
|
+
else
|
54
|
+
prefix + key + ':' + ' ' + squote(text)
|
55
|
+
else
|
56
|
+
prefix + str
|
57
|
+
|
31
58
|
debug "return from taml()"
|
32
|
-
return yaml.load(
|
59
|
+
return yaml.load(arrayToBlock(lLines), {skipInvalid: true})
|
33
60
|
|
34
61
|
# ---------------------------------------------------------------------------
|
35
62
|
# slurpTAML - read TAML from a file
|
package/src/taml.js
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
// Generated by CoffeeScript 2.6.1
|
2
2
|
// taml.coffee
|
3
|
+
var squote;
|
4
|
+
|
3
5
|
import yaml from 'js-yaml';
|
4
6
|
|
5
7
|
import {
|
@@ -11,7 +13,8 @@ import {
|
|
11
13
|
|
12
14
|
import {
|
13
15
|
untabify,
|
14
|
-
tabify
|
16
|
+
tabify,
|
17
|
+
splitLine
|
15
18
|
} from '@jdeighan/coffee-utils/indent';
|
16
19
|
|
17
20
|
import {
|
@@ -28,7 +31,9 @@ import {
|
|
28
31
|
} from '@jdeighan/coffee-utils/debug';
|
29
32
|
|
30
33
|
import {
|
31
|
-
firstLine
|
34
|
+
firstLine,
|
35
|
+
blockToArray,
|
36
|
+
arrayToBlock
|
32
37
|
} from '@jdeighan/coffee-utils/block';
|
33
38
|
|
34
39
|
// ---------------------------------------------------------------------------
|
@@ -37,17 +42,44 @@ export var isTAML = function(text) {
|
|
37
42
|
return isString(text) && (firstLine(text).indexOf('---') === 0);
|
38
43
|
};
|
39
44
|
|
45
|
+
// ---------------------------------------------------------------------------
|
46
|
+
squote = function(text) {
|
47
|
+
return "'" + text.replace(/'/g, "''") + "'";
|
48
|
+
};
|
49
|
+
|
40
50
|
// ---------------------------------------------------------------------------
|
41
51
|
// taml - convert valid TAML string to a JavaScript value
|
42
52
|
export var taml = function(text) {
|
53
|
+
var _, key, lLines, lMatches, level, line, prefix, str;
|
43
54
|
debug(`enter taml(${oneline(text)})`);
|
44
55
|
if (text == null) {
|
45
56
|
debug("return undef from taml() - text is not defined");
|
46
57
|
return undef;
|
47
58
|
}
|
48
59
|
assert(isTAML(text), `taml(): string ${oneline(text)} isn't TAML`);
|
60
|
+
lLines = (function() {
|
61
|
+
var i, len, ref, results;
|
62
|
+
ref = blockToArray(text);
|
63
|
+
results = [];
|
64
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
65
|
+
line = ref[i];
|
66
|
+
[level, str] = splitLine(line);
|
67
|
+
prefix = ' '.repeat(level);
|
68
|
+
if (lMatches = line.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*:\s*(.*)$/)) { // the key
|
69
|
+
[_, key, text] = lMatches;
|
70
|
+
if (isEmpty(text) || text.match(/\d+(?:\.\d*)$/)) {
|
71
|
+
results.push(prefix + str);
|
72
|
+
} else {
|
73
|
+
results.push(prefix + key + ':' + ' ' + squote(text));
|
74
|
+
}
|
75
|
+
} else {
|
76
|
+
results.push(prefix + str);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
return results;
|
80
|
+
})();
|
49
81
|
debug("return from taml()");
|
50
|
-
return yaml.load(
|
82
|
+
return yaml.load(arrayToBlock(lLines), {
|
51
83
|
skipInvalid: true
|
52
84
|
});
|
53
85
|
};
|