precedent 1.0.13 → 1.0.15
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/.babelrc +5 -0
- package/.browserslistrc +1 -1
- package/dist/precedent.compatible.js +376 -3975
- package/dist/precedent.compatible.min.js +2 -22
- package/dist/precedent.compatible.min.js.map +1 -1
- package/dist/precedent.js +340 -3975
- package/dist/precedent.min.js +2 -22
- package/dist/precedent.min.js.map +1 -1
- package/package.json +49 -64
- package/source/Precedent.js +2 -7
- package/source/StringParser.js +94 -180
- package/source/WordTree.js +47 -45
- package/test/Precedent_tests.js +0 -26
- package/.browserslistrc_compatible +0 -1
- package/.browserslistrc_default +0 -1
- package/.travis.yml +0 -13
- package/bower.json +0 -27
- package/gulpfile-config.json +0 -11
- package/gulpfile-config_compatible.json +0 -11
- package/gulpfile-config_default.json +0 -11
- package/gulpfile.js +0 -164
package/package.json
CHANGED
|
@@ -1,67 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"author": "Steven Velozo <steven@velozo.com>",
|
|
26
|
-
"license": "MIT",
|
|
27
|
-
"bugs": {
|
|
28
|
-
"url": "https://github.com/stevenvelozo/precedent/issues"
|
|
29
|
-
},
|
|
30
|
-
"mocha": {
|
|
31
|
-
"diff": true,
|
|
32
|
-
"extension": [
|
|
33
|
-
"js"
|
|
2
|
+
"name": "precedent",
|
|
3
|
+
"version": "1.0.15",
|
|
4
|
+
"description": "Precedent Meta-Templating",
|
|
5
|
+
"main": "source/Precedent.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"precedent": "./bin/Precedent"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node source/Precedent.js",
|
|
11
|
+
"coverage": "./node_modules/.bin/nyc --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
|
|
12
|
+
"test": "./node_modules/.bin/mocha -u tdd -R spec",
|
|
13
|
+
"docker-dev-build-image": "docker build ./ -f Dockerfile_LUXURYCode -t retold/precedent:local",
|
|
14
|
+
"docker-dev-run": "docker run -it -d --name precedent-dev -p 30001:8080 -p 38086:8086 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/precedent\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" precedent-image:local",
|
|
15
|
+
"build": "npx quack build",
|
|
16
|
+
"docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t precedent-image:local",
|
|
17
|
+
"docker-dev-shell": "docker exec -it precedent-dev /bin/bash"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/stevenvelozo/precedent.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"logging"
|
|
34
25
|
],
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"vinyl-buffer": "^1.0.1",
|
|
62
|
-
"vinyl-source-stream": "^2.0.0"
|
|
63
|
-
},
|
|
64
|
-
"dependencies": {
|
|
65
|
-
"async": "^3.2.4"
|
|
66
|
-
}
|
|
26
|
+
"author": "Steven Velozo <steven@velozo.com>",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/stevenvelozo/precedent/issues"
|
|
30
|
+
},
|
|
31
|
+
"mocha": {
|
|
32
|
+
"diff": true,
|
|
33
|
+
"extension": [
|
|
34
|
+
"js"
|
|
35
|
+
],
|
|
36
|
+
"package": "./package.json",
|
|
37
|
+
"reporter": "spec",
|
|
38
|
+
"slow": "75",
|
|
39
|
+
"timeout": "5000",
|
|
40
|
+
"ui": "tdd",
|
|
41
|
+
"watch-files": [
|
|
42
|
+
"source/**/*.js",
|
|
43
|
+
"test/**/*.js"
|
|
44
|
+
],
|
|
45
|
+
"watch-ignore": [
|
|
46
|
+
"lib/vendor"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"quackage": "^1.0.14"
|
|
51
|
+
}
|
|
67
52
|
}
|
package/source/Precedent.js
CHANGED
|
@@ -37,11 +37,6 @@ class Precedent
|
|
|
37
37
|
return this.WordTree.addPattern(pPatternStart, pPatternEnd, pParser);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
addPatternAsync(pPatternStart, pPatternEnd, pParserPromise)
|
|
41
|
-
{
|
|
42
|
-
return this.WordTree.addPatternAsync(pPatternStart, pPatternEnd, pParserPromise);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
40
|
/**
|
|
46
41
|
* Parse a string with the existing parse tree
|
|
47
42
|
* @method parseString
|
|
@@ -49,9 +44,9 @@ class Precedent
|
|
|
49
44
|
* @param {object} pData - Data to pass in as the second argument
|
|
50
45
|
* @return {string} The result from the parser
|
|
51
46
|
*/
|
|
52
|
-
parseString(pString, pData
|
|
47
|
+
parseString(pString, pData)
|
|
53
48
|
{
|
|
54
|
-
return this.StringParser.parseString(pString, this.ParseTree, pData
|
|
49
|
+
return this.StringParser.parseString(pString, this.ParseTree, pData);
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
52
|
|
package/source/StringParser.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* String Parser
|
|
3
|
-
*
|
|
4
|
-
* @license MIT
|
|
5
|
-
*
|
|
6
3
|
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
-
*
|
|
8
4
|
* @description Parse a string, properly processing each matched token in the word tree.
|
|
9
5
|
*/
|
|
10
6
|
|
|
11
|
-
let libAsync = require('async');
|
|
12
|
-
|
|
13
7
|
class StringParser
|
|
14
8
|
{
|
|
15
9
|
/**
|
|
@@ -37,33 +31,13 @@ class StringParser
|
|
|
37
31
|
Output: '',
|
|
38
32
|
OutputBuffer: '',
|
|
39
33
|
|
|
40
|
-
Pattern:
|
|
34
|
+
Pattern: {},
|
|
41
35
|
|
|
42
36
|
PatternMatch: false,
|
|
43
|
-
|
|
37
|
+
PatternMatchEnd: false
|
|
44
38
|
});
|
|
45
39
|
}
|
|
46
40
|
|
|
47
|
-
/**
|
|
48
|
-
* Assign a node of the parser tree to be the next potential match.
|
|
49
|
-
* If the node has a PatternEnd property, it is a valid match and supercedes the last valid match (or becomes the initial match).
|
|
50
|
-
* @method assignNode
|
|
51
|
-
* @param {Object} pNode - A node on the parse tree to assign
|
|
52
|
-
* @param {Object} pParserState - The state object for the current parsing task
|
|
53
|
-
* @private
|
|
54
|
-
*/
|
|
55
|
-
assignNode (pNode, pParserState)
|
|
56
|
-
{
|
|
57
|
-
pParserState.PatternMatch = pNode;
|
|
58
|
-
|
|
59
|
-
// If the pattern has a END we can assume it has a parse function...
|
|
60
|
-
if (pParserState.PatternMatch.hasOwnProperty('PatternEnd'))
|
|
61
|
-
{
|
|
62
|
-
// ... this is the legitimate start of a pattern.
|
|
63
|
-
pParserState.Pattern = pParserState.PatternMatch;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
41
|
/**
|
|
68
42
|
* Append a character to the output buffer in the parser state.
|
|
69
43
|
* This output buffer is used when a potential match is being explored, or a match is being explored.
|
|
@@ -89,80 +63,18 @@ class StringParser
|
|
|
89
63
|
pParserState.OutputBuffer = '';
|
|
90
64
|
}
|
|
91
65
|
|
|
92
|
-
|
|
93
|
-
* Check if the pattern has ended. If it has, properly flush the buffer and start looking for new patterns.
|
|
94
|
-
* @method checkPatternEnd
|
|
95
|
-
* @param {Object} pParserState - The state object for the current parsing task
|
|
96
|
-
* @private
|
|
97
|
-
*/
|
|
98
|
-
checkPatternEnd (pParserState, pData)
|
|
99
|
-
{
|
|
100
|
-
if ((pParserState.OutputBuffer.length >= pParserState.Pattern.PatternEnd.length+pParserState.Pattern.PatternStart.length) &&
|
|
101
|
-
(pParserState.OutputBuffer.substr(-pParserState.Pattern.PatternEnd.length) === pParserState.Pattern.PatternEnd))
|
|
102
|
-
{
|
|
103
|
-
// ... this is the end of a pattern, cut off the end tag and parse it.
|
|
104
|
-
// Trim the start and end tags off the output buffer now
|
|
105
|
-
if (pParserState.Pattern.isAsync)
|
|
106
|
-
{
|
|
107
|
-
console.log(`Precedent ERROR: Async template detected for pattern ${pParserState.Pattern.PatternStart} ... ${pParserState.Pattern.PatternEnd} but the template engine is being run in non-async mode.`);
|
|
108
|
-
this.OutputBuffer = '';
|
|
109
|
-
// Flush the output buffer.
|
|
110
|
-
this.flushOutputBuffer(pParserState);
|
|
111
|
-
// End pattern mode
|
|
112
|
-
pParserState.Pattern = false;
|
|
113
|
-
pParserState.PatternMatch = false;
|
|
114
|
-
}
|
|
115
|
-
else
|
|
116
|
-
{
|
|
117
|
-
pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStart.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStart.length+pParserState.Pattern.PatternEnd.length)), pData);
|
|
118
|
-
// Flush the output buffer.
|
|
119
|
-
this.flushOutputBuffer(pParserState);
|
|
120
|
-
// End pattern mode
|
|
121
|
-
pParserState.Pattern = false;
|
|
122
|
-
pParserState.PatternMatch = false;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
checkPatternEndAsync (pParserState, pData, fCallback)
|
|
66
|
+
resetOutputBuffer (pParserState)
|
|
128
67
|
{
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (pError)
|
|
140
|
-
{
|
|
141
|
-
console.log(`Precedent ERROR: Async template error happened parsing ${pParserState.Pattern.PatternStart} ... ${pParserState.Pattern.PatternEnd}: ${pError}`);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
pParserState.OutputBuffer = pAsyncOutput;
|
|
145
|
-
// Flush the output buffer.
|
|
146
|
-
this.flushOutputBuffer(pParserState);
|
|
147
|
-
// End pattern mode
|
|
148
|
-
pParserState.Pattern = false;
|
|
149
|
-
pParserState.PatternMatch = false;
|
|
150
|
-
|
|
151
|
-
return fCallback();
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
else
|
|
155
|
-
{
|
|
156
|
-
pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStart.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStart.length+pParserState.Pattern.PatternEnd.length)), pData);
|
|
157
|
-
// Flush the output buffer.
|
|
158
|
-
this.flushOutputBuffer(pParserState);
|
|
159
|
-
// End pattern mode
|
|
160
|
-
pParserState.Pattern = false;
|
|
161
|
-
pParserState.PatternMatch = false;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return fCallback();
|
|
68
|
+
// Flush the output buffer.
|
|
69
|
+
this.flushOutputBuffer(pParserState);
|
|
70
|
+
// End pattern mode
|
|
71
|
+
pParserState.Pattern = false;
|
|
72
|
+
pParserState.PatternStartNode = false;
|
|
73
|
+
pParserState.StartPatternMatchComplete = false;
|
|
74
|
+
pParserState.EndPatternMatchBegan = false;
|
|
75
|
+
pParserState.PatternMatch = false;
|
|
76
|
+
|
|
77
|
+
return true;
|
|
166
78
|
}
|
|
167
79
|
|
|
168
80
|
/**
|
|
@@ -174,68 +86,93 @@ class StringParser
|
|
|
174
86
|
*/
|
|
175
87
|
parseCharacter (pCharacter, pParserState, pData)
|
|
176
88
|
{
|
|
177
|
-
//
|
|
178
|
-
if (
|
|
89
|
+
// If we are already in a pattern match traversal
|
|
90
|
+
if (pParserState.PatternMatch)
|
|
179
91
|
{
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
this.appendOutputBuffer(pCharacter, pParserState);
|
|
183
|
-
}
|
|
184
|
-
// (2) If we are in a pattern match (actively seeing if this is part of a new pattern token)
|
|
185
|
-
else if (pParserState.PatternMatch)
|
|
186
|
-
{
|
|
187
|
-
// If the pattern has a subpattern with this key
|
|
188
|
-
if (pParserState.PatternMatch.hasOwnProperty(pCharacter))
|
|
92
|
+
// If the pattern is still matching the start and we haven't passed the buffer
|
|
93
|
+
if (!pParserState.StartPatternMatchComplete && pParserState.Pattern.hasOwnProperty(pCharacter))
|
|
189
94
|
{
|
|
190
|
-
|
|
191
|
-
this.
|
|
95
|
+
pParserState.Pattern = pParserState.Pattern[pCharacter];
|
|
96
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
192
97
|
}
|
|
193
|
-
|
|
194
|
-
if (pParserState.Pattern)
|
|
98
|
+
else if (pParserState.EndPatternMatchBegan)
|
|
195
99
|
{
|
|
196
|
-
|
|
197
|
-
|
|
100
|
+
if (pParserState.Pattern.PatternEnd.hasOwnProperty(pCharacter))
|
|
101
|
+
{
|
|
102
|
+
// This leaf has a PatternEnd tree, so we will wait until that end is met.
|
|
103
|
+
pParserState.Pattern = pParserState.Pattern.PatternEnd[pCharacter];
|
|
104
|
+
// Flush the output buffer.
|
|
105
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
106
|
+
// If this last character is the end of the pattern, parse it.
|
|
107
|
+
if (pParserState.Pattern.hasOwnProperty('Parse'))
|
|
108
|
+
{
|
|
109
|
+
// Run the function
|
|
110
|
+
pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData);
|
|
111
|
+
return this.resetOutputBuffer(pParserState);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (pParserState.PatternStartNode.PatternEnd.hasOwnProperty(pCharacter))
|
|
115
|
+
{
|
|
116
|
+
// We broke out of the end -- see if this is a new start of the end.
|
|
117
|
+
pParserState.Pattern = pParserState.PatternStartNode.PatternEnd[pCharacter];
|
|
118
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
119
|
+
}
|
|
120
|
+
else
|
|
121
|
+
{
|
|
122
|
+
pParserState.EndPatternMatchBegan = false;
|
|
123
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
124
|
+
}
|
|
198
125
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
126
|
+
else if (pParserState.Pattern.hasOwnProperty('PatternEnd'))
|
|
127
|
+
{
|
|
128
|
+
if (!pParserState.StartPatternMatchComplete)
|
|
129
|
+
{
|
|
130
|
+
pParserState.StartPatternMatchComplete = true;
|
|
131
|
+
pParserState.PatternStartNode = pParserState.Pattern;
|
|
132
|
+
}
|
|
206
133
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
134
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
135
|
+
|
|
136
|
+
if (pParserState.Pattern.PatternEnd.hasOwnProperty(pCharacter))
|
|
137
|
+
{
|
|
138
|
+
// This is the first character of the end pattern.
|
|
139
|
+
pParserState.EndPatternMatchBegan = true;
|
|
140
|
+
// This leaf has a PatternEnd tree, so we will wait until that end is met.
|
|
141
|
+
pParserState.Pattern = pParserState.Pattern.PatternEnd[pCharacter];
|
|
142
|
+
// If this last character is the end of the pattern, parse it.
|
|
143
|
+
if (pParserState.Pattern.hasOwnProperty('Parse'))
|
|
144
|
+
{
|
|
145
|
+
// Run the t*mplate function
|
|
146
|
+
pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData);
|
|
147
|
+
return this.resetOutputBuffer(pParserState);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else
|
|
152
|
+
{
|
|
153
|
+
// We are in a pattern start but didn't match one; reset and start trying again from this character.
|
|
154
|
+
this.resetOutputBuffer(pParserState);
|
|
155
|
+
}
|
|
215
156
|
}
|
|
216
|
-
//
|
|
217
|
-
|
|
157
|
+
// If we aren't in a pattern match or pattern, and this isn't the start of a new pattern (RAW mode)....
|
|
158
|
+
if (!pParserState.PatternMatch)
|
|
218
159
|
{
|
|
219
|
-
//
|
|
220
|
-
if (pParserState.
|
|
160
|
+
// This may be the start of a new pattern....
|
|
161
|
+
if (pParserState.ParseTree.hasOwnProperty(pCharacter))
|
|
221
162
|
{
|
|
222
|
-
//
|
|
223
|
-
this.
|
|
163
|
+
// ... assign the root node as the matched node.
|
|
164
|
+
this.resetOutputBuffer(pParserState);
|
|
165
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
166
|
+
pParserState.Pattern = pParserState.ParseTree[pCharacter];
|
|
167
|
+
pParserState.PatternMatch = true;
|
|
168
|
+
return true;
|
|
224
169
|
}
|
|
225
|
-
|
|
226
|
-
if (pParserState.Pattern)
|
|
170
|
+
else
|
|
227
171
|
{
|
|
228
|
-
|
|
229
|
-
return this.checkPatternEndAsync(pParserState, pData, fCallback);
|
|
172
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
230
173
|
}
|
|
231
174
|
}
|
|
232
|
-
|
|
233
|
-
else
|
|
234
|
-
{
|
|
235
|
-
pParserState.Output += pCharacter;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return fCallback(null);
|
|
175
|
+
return false;
|
|
239
176
|
}
|
|
240
177
|
|
|
241
178
|
/**
|
|
@@ -244,42 +181,19 @@ class StringParser
|
|
|
244
181
|
* @param {string} pString - The string to parse.
|
|
245
182
|
* @param {Object} pParseTree - The parse tree to begin parsing from (usually root)
|
|
246
183
|
* @param {Object} pData - The data to pass to the function as a second parameter
|
|
247
|
-
* @param {function} fCallback - The callback function to call when the parse is complete
|
|
248
184
|
*/
|
|
249
|
-
parseString (pString, pParseTree, pData
|
|
185
|
+
parseString (pString, pParseTree, pData)
|
|
250
186
|
{
|
|
251
|
-
|
|
252
|
-
{
|
|
253
|
-
let tmpParserState = this.newParserState(pParseTree);
|
|
187
|
+
let tmpParserState = this.newParserState(pParseTree);
|
|
254
188
|
|
|
255
|
-
|
|
256
|
-
{
|
|
257
|
-
// TODO: This is not fast.
|
|
258
|
-
this.parseCharacter(pString[i], tmpParserState, pData, fCallback);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
this.flushOutputBuffer(tmpParserState);
|
|
262
|
-
|
|
263
|
-
return tmpParserState.Output;
|
|
264
|
-
}
|
|
265
|
-
else
|
|
189
|
+
for (var i = 0; i < pString.length; i++)
|
|
266
190
|
{
|
|
267
|
-
|
|
268
|
-
|
|
191
|
+
this.parseCharacter(pString[i], tmpParserState, pData);
|
|
192
|
+
}
|
|
269
193
|
|
|
270
|
-
|
|
271
|
-
(pCharacter, fCharacterCallback) =>
|
|
272
|
-
{
|
|
273
|
-
this.parseCharacterAsync(pCharacter, tmpParserState, pData, fCharacterCallback);
|
|
274
|
-
},
|
|
275
|
-
(pError) =>
|
|
276
|
-
{
|
|
277
|
-
// Flush the remaining data
|
|
278
|
-
this.flushOutputBuffer(tmpParserState);
|
|
279
|
-
fCallback(pError, tmpParserState.Output);
|
|
280
|
-
});
|
|
194
|
+
this.flushOutputBuffer(tmpParserState);
|
|
281
195
|
|
|
282
|
-
|
|
196
|
+
return tmpParserState.Output;
|
|
283
197
|
}
|
|
284
198
|
}
|
|
285
199
|
|
package/source/WordTree.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Word Tree
|
|
3
|
-
*
|
|
4
|
-
* @license MIT
|
|
5
|
-
*
|
|
6
3
|
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
-
*
|
|
8
4
|
* @description Create a tree (directed graph) of Javascript objects, one character per object.
|
|
9
5
|
*/
|
|
10
6
|
|
|
@@ -23,76 +19,82 @@ class WordTree
|
|
|
23
19
|
* @method addChild
|
|
24
20
|
* @param {Object} pTree - A parse tree to push the characters into
|
|
25
21
|
* @param {string} pPattern - The string to add to the tree
|
|
26
|
-
* @param {number} pIndex - The index of the character in the pattern
|
|
27
22
|
* @returns {Object} The resulting leaf node that was added (or found)
|
|
28
23
|
* @private
|
|
29
24
|
*/
|
|
30
|
-
addChild (pTree, pPattern
|
|
25
|
+
addChild (pTree, pPattern)
|
|
31
26
|
{
|
|
32
|
-
if (!pTree.hasOwnProperty(pPattern
|
|
33
|
-
|
|
27
|
+
if (!pTree.hasOwnProperty(pPattern))
|
|
28
|
+
{
|
|
29
|
+
pTree[pPattern] = {};
|
|
30
|
+
}
|
|
34
31
|
|
|
35
|
-
return pTree[pPattern
|
|
32
|
+
return pTree[pPattern];
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
41
|
-
* @param {
|
|
42
|
-
* @param {
|
|
43
|
-
* @
|
|
35
|
+
/**
|
|
36
|
+
* Add a child character to a Parse Tree PatternEnd subtree
|
|
37
|
+
* @method addChild
|
|
38
|
+
* @param {Object} pTree - A parse tree to push the characters into
|
|
39
|
+
* @param {string} pPattern - The string to add to the tree
|
|
40
|
+
* @returns {Object} The resulting leaf node that was added (or found)
|
|
41
|
+
* @private
|
|
44
42
|
*/
|
|
45
|
-
|
|
43
|
+
addEndChild (pTree, pPattern)
|
|
46
44
|
{
|
|
47
|
-
if (
|
|
48
|
-
|
|
45
|
+
if (!pTree.hasOwnProperty('PatternEnd'))
|
|
46
|
+
{
|
|
47
|
+
pTree.PatternEnd = {};
|
|
48
|
+
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
return false;
|
|
52
|
-
|
|
53
|
-
let tmpLeaf = this.ParseTree;
|
|
54
|
-
|
|
55
|
-
// Add the tree of leaves iteratively
|
|
56
|
-
for (var i = 0; i < pPatternStart.length; i++)
|
|
57
|
-
tmpLeaf = this.addChild(tmpLeaf, pPatternStart, i);
|
|
50
|
+
pTree.PatternEnd[pPattern] = {};
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
tmpLeaf.PatternEnd = ((typeof(pPatternEnd) === 'string') && (pPatternEnd.length > 0)) ? pPatternEnd : pPatternStart;
|
|
61
|
-
tmpLeaf.Parse = (typeof(pParser) === 'function') ? pParser :
|
|
62
|
-
(typeof(pParser) === 'string') ? () => { return pParser; } :
|
|
63
|
-
(pData) => { return pData; };
|
|
64
|
-
tmpLeaf.isPromise = false;
|
|
65
|
-
|
|
66
|
-
return true;
|
|
52
|
+
return pTree.PatternEnd[pPattern];
|
|
67
53
|
}
|
|
68
54
|
|
|
69
|
-
/** Add a Pattern to the Parse Tree
|
|
55
|
+
/** Add a Pattern to the Parse Tree
|
|
70
56
|
* @method addPattern
|
|
71
57
|
* @param {Object} pPatternStart - The starting string for the pattern (e.g. "${")
|
|
72
58
|
* @param {string} pPatternEnd - The ending string for the pattern (e.g. "}")
|
|
73
|
-
* @param {
|
|
59
|
+
* @param {function} fParser - The function to parse if this is the matched pattern, once the Pattern End is met. If this is a string, a simple replacement occurs.
|
|
74
60
|
* @return {bool} True if adding the pattern was successful
|
|
75
61
|
*/
|
|
76
|
-
|
|
62
|
+
addPattern (pPatternStart, pPatternEnd, fParser)
|
|
77
63
|
{
|
|
78
64
|
if (pPatternStart.length < 1)
|
|
65
|
+
{
|
|
79
66
|
return false;
|
|
67
|
+
}
|
|
80
68
|
|
|
81
69
|
if ((typeof(pPatternEnd) === 'string') && (pPatternEnd.length < 1))
|
|
70
|
+
{
|
|
82
71
|
return false;
|
|
72
|
+
}
|
|
83
73
|
|
|
84
74
|
let tmpLeaf = this.ParseTree;
|
|
85
75
|
|
|
86
76
|
// Add the tree of leaves iteratively
|
|
87
77
|
for (var i = 0; i < pPatternStart.length; i++)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
tmpLeaf.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
78
|
+
{
|
|
79
|
+
tmpLeaf = this.addChild(tmpLeaf, pPatternStart[i], i);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!tmpLeaf.hasOwnProperty('PatternEnd'))
|
|
83
|
+
{
|
|
84
|
+
tmpLeaf.PatternEnd = {};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let tmpPatternEnd = (typeof(pPatternEnd) === 'string') ? pPatternEnd : pPatternStart;
|
|
88
|
+
for (let i = 0; i < tmpPatternEnd.length; i++)
|
|
89
|
+
{
|
|
90
|
+
tmpLeaf = this.addEndChild(tmpLeaf, tmpPatternEnd[i], i);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
tmpLeaf.PatternStartString = pPatternStart;
|
|
94
|
+
tmpLeaf.PatternEndString = tmpPatternEnd;
|
|
95
|
+
tmpLeaf.Parse = (typeof(fParser) === 'function') ? fParser :
|
|
96
|
+
(typeof(fParser) === 'string') ? () => { return fParser; } :
|
|
97
|
+
(pData) => { return pData; };
|
|
96
98
|
|
|
97
99
|
return true;
|
|
98
100
|
}
|
package/test/Precedent_tests.js
CHANGED
|
@@ -30,12 +30,6 @@ var configPrecedent = (pModule) =>
|
|
|
30
30
|
pModule.addPattern('<^', '^>', (pHash, pData)=>{return `hash of [${pHash}] from pData is ${pData[pHash]}`});
|
|
31
31
|
// This just escapes out pairs of $
|
|
32
32
|
pModule.addPattern('$');
|
|
33
|
-
|
|
34
|
-
pModule.addPatternAsync('<%Async', '%>',
|
|
35
|
-
(pHash, pData, fCallback)=>
|
|
36
|
-
{
|
|
37
|
-
return fCallback(null, `ASYNC DATA IS [${pHash}]`);
|
|
38
|
-
});
|
|
39
33
|
};
|
|
40
34
|
|
|
41
35
|
suite
|
|
@@ -159,23 +153,6 @@ suite
|
|
|
159
153
|
}
|
|
160
154
|
);
|
|
161
155
|
test
|
|
162
|
-
(
|
|
163
|
-
'Async Function',
|
|
164
|
-
(fDone) =>
|
|
165
|
-
{
|
|
166
|
-
var tmpTestString = 'The <^SomeValue^> pData and Async <%AsyncThe Funny String%> up in here and a $comment$ as well.';
|
|
167
|
-
var tmpExpectedResult = 'The hash of [SomeValue] from pData is AirbornLight pData up in here and a comment as well.';
|
|
168
|
-
var testPrecedent = loadPrecedentModule();
|
|
169
|
-
configPrecedent(testPrecedent);
|
|
170
|
-
var tmpResult = testPrecedent.parseString(tmpTestString, {SomeValue:'AirbornLight'},
|
|
171
|
-
(pError, pValue) =>
|
|
172
|
-
{
|
|
173
|
-
Expect(pValue).to.equal('The hash of [SomeValue] from pData is AirbornLight pData and Async ASYNC DATA IS [The Funny String] up in here and a comment as well.');
|
|
174
|
-
return fDone();
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
);
|
|
178
|
-
test
|
|
179
156
|
(
|
|
180
157
|
'Bad pattern start parameter...',
|
|
181
158
|
(fDone) =>
|
|
@@ -214,9 +191,6 @@ suite
|
|
|
214
191
|
'Match this <<> and this <<here> please.',
|
|
215
192
|
'Match this MEDIUM_MATCH and this MEDIUM_MATCH please.',
|
|
216
193
|
|
|
217
|
-
'Match this <<EXTRA> and this <<here> please.',
|
|
218
|
-
'Match this MEDIUM_MATCH and this MEDIUM_MATCH please.',
|
|
219
|
-
|
|
220
194
|
'Match this <<EXTRALONG> and this <<here> please.',
|
|
221
195
|
'Match this EXTRA_LONG_MATCH and this MEDIUM_MATCH please.',
|
|
222
196
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
> 0.01%
|
package/.browserslistrc_default
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
since 2018
|