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/package.json CHANGED
@@ -1,67 +1,52 @@
1
1
  {
2
- "name": "precedent",
3
- "version": "1.0.13",
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 127.0.0.1:12340:8080 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/precedent\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" retold/precedent:local",
15
- "build": "./node_modules/.bin/gulp build",
16
- "build-compatible": "GULP_CUSTOM_BUILD_TARGET=compatible ./node_modules/.bin/gulp build"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "https://github.com/stevenvelozo/precedent.git"
21
- },
22
- "keywords": [
23
- "logging"
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
- "package": "./package.json",
36
- "reporter": "spec",
37
- "slow": "75",
38
- "timeout": "5000",
39
- "ui": "tdd",
40
- "watch-files": [
41
- "source/**/*.js",
42
- "test/**/*.js"
43
- ],
44
- "watch-ignore": [
45
- "lib/vendor"
46
- ]
47
- },
48
- "devDependencies": {
49
- "@babel/core": "^7.21.5",
50
- "@babel/preset-env": "^7.21.5",
51
- "browserify": "^17.0.0",
52
- "chai": "4.3.7",
53
- "gulp": "^4.0.2",
54
- "gulp-babel": "^8.0.0",
55
- "gulp-env": "^0.4.0",
56
- "gulp-sourcemaps": "^3.0.0",
57
- "gulp-terser": "^2.1.0",
58
- "gulp-util": "^3.0.8",
59
- "mocha": "10.2.0",
60
- "nyc": "^15.1.0",
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
  }
@@ -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, fCallback)
47
+ parseString(pString, pData)
53
48
  {
54
- return this.StringParser.parseString(pString, this.ParseTree, pData, fCallback);
49
+ return this.StringParser.parseString(pString, this.ParseTree, pData);
55
50
  }
56
51
  }
57
52
 
@@ -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: false,
34
+ Pattern: {},
41
35
 
42
36
  PatternMatch: false,
43
- PatternMatchOutputBuffer: ''
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
- if ((pParserState.OutputBuffer.length >= pParserState.Pattern.PatternEnd.length+pParserState.Pattern.PatternStart.length) &&
130
- (pParserState.OutputBuffer.substr(-pParserState.Pattern.PatternEnd.length) === pParserState.Pattern.PatternEnd))
131
- {
132
- // ... this is the end of a pattern, cut off the end tag and parse it.
133
- // Trim the start and end tags off the output buffer now
134
- if (pParserState.Pattern.isAsync)
135
- {
136
- return pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStart.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStart.length+pParserState.Pattern.PatternEnd.length)), pData,
137
- (pError, pAsyncOutput) =>
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
- // (1) If we aren't in a pattern match, and we aren't potentially matching, and this may be the start of a new pattern....
178
- if (!pParserState.PatternMatch && pParserState.ParseTree.hasOwnProperty(pCharacter))
89
+ // If we are already in a pattern match traversal
90
+ if (pParserState.PatternMatch)
179
91
  {
180
- // ... assign the node as the matched node.
181
- this.assignNode(pParserState.ParseTree[pCharacter], pParserState);
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
- // Continue matching patterns.
191
- this.assignNode(pParserState.PatternMatch[pCharacter], pParserState);
95
+ pParserState.Pattern = pParserState.Pattern[pCharacter];
96
+ this.appendOutputBuffer(pCharacter, pParserState);
192
97
  }
193
- this.appendOutputBuffer(pCharacter, pParserState);
194
- if (pParserState.Pattern)
98
+ else if (pParserState.EndPatternMatchBegan)
195
99
  {
196
- // ... Check if this is the end of the pattern (if we are matching a valid pattern)...
197
- this.checkPatternEnd(pParserState, pData);
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
- // (3) If we aren't in a pattern match or pattern, and this isn't the start of a new pattern (RAW mode)....
201
- else
202
- {
203
- pParserState.Output += pCharacter;
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
- parseCharacterAsync (pCharacter, pParserState, pData, fCallback)
208
- {
209
- // (1) If we aren't in a pattern match, and we aren't potentially matching, and this may be the start of a new pattern....
210
- if (!pParserState.PatternMatch && pParserState.ParseTree.hasOwnProperty(pCharacter))
211
- {
212
- // ... assign the node as the matched node.
213
- this.assignNode(pParserState.ParseTree[pCharacter], pParserState);
214
- this.appendOutputBuffer(pCharacter, pParserState);
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
- // (2) If we are in a pattern match (actively seeing if this is part of a new pattern token)
217
- else if (pParserState.PatternMatch)
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
- // If the pattern has a subpattern with this key
220
- if (pParserState.PatternMatch.hasOwnProperty(pCharacter))
160
+ // This may be the start of a new pattern....
161
+ if (pParserState.ParseTree.hasOwnProperty(pCharacter))
221
162
  {
222
- // Continue matching patterns.
223
- this.assignNode(pParserState.PatternMatch[pCharacter], pParserState);
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
- this.appendOutputBuffer(pCharacter, pParserState);
226
- if (pParserState.Pattern)
170
+ else
227
171
  {
228
- // ... Check if this is the end of the pattern (if we are matching a valid pattern)...
229
- return this.checkPatternEndAsync(pParserState, pData, fCallback);
172
+ this.appendOutputBuffer(pCharacter, pParserState);
230
173
  }
231
174
  }
232
- // (3) If we aren't in a pattern match or pattern, and this isn't the start of a new pattern (RAW mode)....
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, fCallback)
185
+ parseString (pString, pParseTree, pData)
250
186
  {
251
- if (typeof(fCallback) !== 'function')
252
- {
253
- let tmpParserState = this.newParserState(pParseTree);
187
+ let tmpParserState = this.newParserState(pParseTree);
254
188
 
255
- for (var i = 0; i < pString.length; i++)
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
- // This is the async mode
268
- let tmpParserState = this.newParserState(pParseTree);
191
+ this.parseCharacter(pString[i], tmpParserState, pData);
192
+ }
269
193
 
270
- libAsync.eachSeries(pString,
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
 
@@ -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, pIndex)
25
+ addChild (pTree, pPattern)
31
26
  {
32
- if (!pTree.hasOwnProperty(pPattern[pIndex]))
33
- pTree[pPattern[pIndex]] = {};
27
+ if (!pTree.hasOwnProperty(pPattern))
28
+ {
29
+ pTree[pPattern] = {};
30
+ }
34
31
 
35
- return pTree[pPattern[pIndex]];
32
+ return pTree[pPattern];
36
33
  }
37
34
 
38
- /** Add a Pattern to the Parse Tree
39
- * @method addPattern
40
- * @param {Object} pPatternStart - The starting string for the pattern (e.g. "${")
41
- * @param {string} pPatternEnd - The ending string for the pattern (e.g. "}")
42
- * @param {number} pParser - 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.
43
- * @return {bool} True if adding the pattern was successful
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
- addPattern (pPatternStart, pPatternEnd, pParser)
43
+ addEndChild (pTree, pPattern)
46
44
  {
47
- if (pPatternStart.length < 1)
48
- return false;
45
+ if (!pTree.hasOwnProperty('PatternEnd'))
46
+ {
47
+ pTree.PatternEnd = {};
48
+ }
49
49
 
50
- if ((typeof(pPatternEnd) === 'string') && (pPatternEnd.length < 1))
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
- tmpLeaf.PatternStart = pPatternStart;
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 (asynchronous)
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 {number} pParserAsync - The function (with an asynchronous callback) to parse if this is the matched pattern, once the Pattern End is met. If this is a string, a simple replacement occurs.
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
- addPatternAsync (pPatternStart, pPatternEnd, pParserAsync)
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
- tmpLeaf = this.addChild(tmpLeaf, pPatternStart, i);
89
-
90
- tmpLeaf.PatternStart = pPatternStart;
91
- tmpLeaf.PatternEnd = ((typeof(pPatternEnd) === 'string') && (pPatternEnd.length > 0)) ? pPatternEnd : pPatternStart;
92
- tmpLeaf.Parse = (typeof(pParserAsync) === 'function') ? pParserAsync :
93
- (typeof(pParserAsync) === 'string') ? (pHash, pData, fCallback) => { fCallback(pParserPromise); } :
94
- (pHash, pData, fCallback) => { return fCallback(pHash); };
95
- tmpLeaf.isAsync = true;
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
  }
@@ -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%
@@ -1 +0,0 @@
1
- since 2018