precedent 1.0.14 → 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/dist/precedent.compatible.js +246 -177
- package/dist/precedent.compatible.min.js +2 -2
- package/dist/precedent.compatible.min.js.map +1 -1
- package/dist/precedent.js +124 -91
- package/dist/precedent.min.js +2 -2
- package/dist/precedent.min.js.map +1 -1
- package/package.json +49 -62
- package/source/StringParser.js +92 -61
- package/source/WordTree.js +50 -12
- package/test/Precedent_tests.js +0 -3
- 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
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
1
9
|
(function (f) {
|
|
2
|
-
if (typeof exports === "object" && typeof module !== "undefined") {
|
|
10
|
+
if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object" && typeof module !== "undefined") {
|
|
3
11
|
module.exports = f();
|
|
4
12
|
} else if (typeof define === "function" && define.amd) {
|
|
5
13
|
define([], f);
|
|
@@ -45,20 +53,6 @@
|
|
|
45
53
|
return r;
|
|
46
54
|
}()({
|
|
47
55
|
1: [function (require, module, exports) {
|
|
48
|
-
/**
|
|
49
|
-
* Simple browser shim loader - assign the npm module to a window global automatically
|
|
50
|
-
*
|
|
51
|
-
* @author <steven@velozo.com>
|
|
52
|
-
*/
|
|
53
|
-
var libNPMModuleWrapper = require('./Precedent.js');
|
|
54
|
-
if (typeof window == 'object' && !window.hasOwnProperty('Precedent')) {
|
|
55
|
-
window.Precedent = libNPMModuleWrapper;
|
|
56
|
-
}
|
|
57
|
-
module.exports = libNPMModuleWrapper;
|
|
58
|
-
}, {
|
|
59
|
-
"./Precedent.js": 2
|
|
60
|
-
}],
|
|
61
|
-
2: [function (require, module, exports) {
|
|
62
56
|
/**
|
|
63
57
|
* Precedent Meta-Templating
|
|
64
58
|
*
|
|
@@ -68,13 +62,14 @@
|
|
|
68
62
|
*
|
|
69
63
|
* @description Process text streams, parsing out meta-template expressions.
|
|
70
64
|
*/
|
|
71
|
-
var libWordTree = require(
|
|
72
|
-
var libStringParser = require(
|
|
73
|
-
|
|
65
|
+
var libWordTree = require("./WordTree.js");
|
|
66
|
+
var libStringParser = require("./StringParser.js");
|
|
67
|
+
var Precedent = /*#__PURE__*/function () {
|
|
74
68
|
/**
|
|
75
69
|
* Precedent Constructor
|
|
76
70
|
*/
|
|
77
|
-
|
|
71
|
+
function Precedent() {
|
|
72
|
+
_classCallCheck(this, Precedent);
|
|
78
73
|
this.WordTree = new libWordTree();
|
|
79
74
|
this.StringParser = new libStringParser();
|
|
80
75
|
this.ParseTree = this.WordTree.ParseTree;
|
|
@@ -88,38 +83,45 @@
|
|
|
88
83
|
* @param {number} pIndex - callback function
|
|
89
84
|
* @return {bool} True if adding the pattern was successful
|
|
90
85
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
_createClass(Precedent, [{
|
|
87
|
+
key: "addPattern",
|
|
88
|
+
value: function addPattern(pPatternStart, pPatternEnd, pParser) {
|
|
89
|
+
return this.WordTree.addPattern(pPatternStart, pPatternEnd, pParser);
|
|
90
|
+
}
|
|
94
91
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Parse a string with the existing parse tree
|
|
94
|
+
* @method parseString
|
|
95
|
+
* @param {string} pString - The string to parse
|
|
96
|
+
* @param {object} pData - Data to pass in as the second argument
|
|
97
|
+
* @return {string} The result from the parser
|
|
98
|
+
*/
|
|
99
|
+
}, {
|
|
100
|
+
key: "parseString",
|
|
101
|
+
value: function parseString(pString, pData) {
|
|
102
|
+
return this.StringParser.parseString(pString, this.ParseTree, pData);
|
|
103
|
+
}
|
|
104
|
+
}]);
|
|
105
|
+
return Precedent;
|
|
106
|
+
}();
|
|
106
107
|
module.exports = Precedent;
|
|
107
108
|
}, {
|
|
108
|
-
"./StringParser.js":
|
|
109
|
-
"./WordTree.js":
|
|
109
|
+
"./StringParser.js": 2,
|
|
110
|
+
"./WordTree.js": 3
|
|
110
111
|
}],
|
|
111
|
-
|
|
112
|
+
2: [function (require, module, exports) {
|
|
112
113
|
/**
|
|
113
114
|
* String Parser
|
|
114
115
|
* @author Steven Velozo <steven@velozo.com>
|
|
115
116
|
* @description Parse a string, properly processing each matched token in the word tree.
|
|
116
117
|
*/
|
|
117
|
-
|
|
118
|
-
class StringParser {
|
|
118
|
+
var StringParser = /*#__PURE__*/function () {
|
|
119
119
|
/**
|
|
120
120
|
* StringParser Constructor
|
|
121
121
|
*/
|
|
122
|
-
|
|
122
|
+
function StringParser() {
|
|
123
|
+
_classCallCheck(this, StringParser);
|
|
124
|
+
}
|
|
123
125
|
|
|
124
126
|
/**
|
|
125
127
|
* Create a fresh parsing state object to work with.
|
|
@@ -128,141 +130,170 @@
|
|
|
128
130
|
* @return {Object} A new parser state object for running a character parser on
|
|
129
131
|
* @private
|
|
130
132
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Assign a node of the parser tree to be the next potential match.
|
|
145
|
-
* If the node has a PatternEnd property, it is a valid match and supercedes the last valid match (or becomes the initial match).
|
|
146
|
-
* @method assignNode
|
|
147
|
-
* @param {Object} pNode - A node on the parse tree to assign
|
|
148
|
-
* @param {Object} pParserState - The state object for the current parsing task
|
|
149
|
-
* @private
|
|
150
|
-
*/
|
|
151
|
-
assignNode(pNode, pParserState) {
|
|
152
|
-
pParserState.PatternMatch = pNode;
|
|
153
|
-
|
|
154
|
-
// If the pattern has a END we can assume it has a parse function...
|
|
155
|
-
if (pParserState.PatternMatch.hasOwnProperty('PatternEnd')) {
|
|
156
|
-
// ... this is the legitimate start of a pattern.
|
|
157
|
-
pParserState.Pattern = pParserState.PatternMatch;
|
|
133
|
+
_createClass(StringParser, [{
|
|
134
|
+
key: "newParserState",
|
|
135
|
+
value: function newParserState(pParseTree) {
|
|
136
|
+
return {
|
|
137
|
+
ParseTree: pParseTree,
|
|
138
|
+
Asynchronous: false,
|
|
139
|
+
Output: '',
|
|
140
|
+
OutputBuffer: '',
|
|
141
|
+
Pattern: {},
|
|
142
|
+
PatternMatch: false,
|
|
143
|
+
PatternMatchEnd: false
|
|
144
|
+
};
|
|
158
145
|
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Append a character to the output buffer in the parser state.
|
|
163
|
-
* This output buffer is used when a potential match is being explored, or a match is being explored.
|
|
164
|
-
* @method appendOutputBuffer
|
|
165
|
-
* @param {string} pCharacter - The character to append
|
|
166
|
-
* @param {Object} pParserState - The state object for the current parsing task
|
|
167
|
-
* @private
|
|
168
|
-
*/
|
|
169
|
-
appendOutputBuffer(pCharacter, pParserState) {
|
|
170
|
-
pParserState.OutputBuffer += pCharacter;
|
|
171
|
-
}
|
|
172
146
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Append a character to the output buffer in the parser state.
|
|
149
|
+
* This output buffer is used when a potential match is being explored, or a match is being explored.
|
|
150
|
+
* @method appendOutputBuffer
|
|
151
|
+
* @param {string} pCharacter - The character to append
|
|
152
|
+
* @param {Object} pParserState - The state object for the current parsing task
|
|
153
|
+
* @private
|
|
154
|
+
*/
|
|
155
|
+
}, {
|
|
156
|
+
key: "appendOutputBuffer",
|
|
157
|
+
value: function appendOutputBuffer(pCharacter, pParserState) {
|
|
158
|
+
pParserState.OutputBuffer += pCharacter;
|
|
159
|
+
}
|
|
183
160
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
pParserState.OutputBuffer =
|
|
161
|
+
/**
|
|
162
|
+
* Flush the output buffer to the output and clear it.
|
|
163
|
+
* @method flushOutputBuffer
|
|
164
|
+
* @param {Object} pParserState - The state object for the current parsing task
|
|
165
|
+
* @private
|
|
166
|
+
*/
|
|
167
|
+
}, {
|
|
168
|
+
key: "flushOutputBuffer",
|
|
169
|
+
value: function flushOutputBuffer(pParserState) {
|
|
170
|
+
pParserState.Output += pParserState.OutputBuffer;
|
|
171
|
+
pParserState.OutputBuffer = '';
|
|
172
|
+
}
|
|
173
|
+
}, {
|
|
174
|
+
key: "resetOutputBuffer",
|
|
175
|
+
value: function resetOutputBuffer(pParserState) {
|
|
195
176
|
// Flush the output buffer.
|
|
196
177
|
this.flushOutputBuffer(pParserState);
|
|
197
178
|
// End pattern mode
|
|
198
179
|
pParserState.Pattern = false;
|
|
180
|
+
pParserState.PatternStartNode = false;
|
|
181
|
+
pParserState.StartPatternMatchComplete = false;
|
|
182
|
+
pParserState.EndPatternMatchBegan = false;
|
|
199
183
|
pParserState.PatternMatch = false;
|
|
184
|
+
return true;
|
|
200
185
|
}
|
|
201
|
-
}
|
|
202
186
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
//
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Parse a character in the buffer.
|
|
189
|
+
* @method parseCharacter
|
|
190
|
+
* @param {string} pCharacter - The character to append
|
|
191
|
+
* @param {Object} pParserState - The state object for the current parsing task
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
}, {
|
|
195
|
+
key: "parseCharacter",
|
|
196
|
+
value: function parseCharacter(pCharacter, pParserState, pData) {
|
|
197
|
+
// If we are already in a pattern match traversal
|
|
198
|
+
if (pParserState.PatternMatch) {
|
|
199
|
+
// If the pattern is still matching the start and we haven't passed the buffer
|
|
200
|
+
if (!pParserState.StartPatternMatchComplete && pParserState.Pattern.hasOwnProperty(pCharacter)) {
|
|
201
|
+
pParserState.Pattern = pParserState.Pattern[pCharacter];
|
|
202
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
203
|
+
} else if (pParserState.EndPatternMatchBegan) {
|
|
204
|
+
if (pParserState.Pattern.PatternEnd.hasOwnProperty(pCharacter)) {
|
|
205
|
+
// This leaf has a PatternEnd tree, so we will wait until that end is met.
|
|
206
|
+
pParserState.Pattern = pParserState.Pattern.PatternEnd[pCharacter];
|
|
207
|
+
// Flush the output buffer.
|
|
208
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
209
|
+
// If this last character is the end of the pattern, parse it.
|
|
210
|
+
if (pParserState.Pattern.hasOwnProperty('Parse')) {
|
|
211
|
+
// Run the function
|
|
212
|
+
pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length + pParserState.Pattern.PatternEndString.length)), pData);
|
|
213
|
+
return this.resetOutputBuffer(pParserState);
|
|
214
|
+
}
|
|
215
|
+
} else if (pParserState.PatternStartNode.PatternEnd.hasOwnProperty(pCharacter)) {
|
|
216
|
+
// We broke out of the end -- see if this is a new start of the end.
|
|
217
|
+
pParserState.Pattern = pParserState.PatternStartNode.PatternEnd[pCharacter];
|
|
218
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
219
|
+
} else {
|
|
220
|
+
pParserState.EndPatternMatchBegan = false;
|
|
221
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
222
|
+
}
|
|
223
|
+
} else if (pParserState.Pattern.hasOwnProperty('PatternEnd')) {
|
|
224
|
+
if (!pParserState.StartPatternMatchComplete) {
|
|
225
|
+
pParserState.StartPatternMatchComplete = true;
|
|
226
|
+
pParserState.PatternStartNode = pParserState.Pattern;
|
|
227
|
+
}
|
|
228
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
229
|
+
if (pParserState.Pattern.PatternEnd.hasOwnProperty(pCharacter)) {
|
|
230
|
+
// This is the first character of the end pattern.
|
|
231
|
+
pParserState.EndPatternMatchBegan = true;
|
|
232
|
+
// This leaf has a PatternEnd tree, so we will wait until that end is met.
|
|
233
|
+
pParserState.Pattern = pParserState.Pattern.PatternEnd[pCharacter];
|
|
234
|
+
// If this last character is the end of the pattern, parse it.
|
|
235
|
+
if (pParserState.Pattern.hasOwnProperty('Parse')) {
|
|
236
|
+
// Run the t*mplate function
|
|
237
|
+
pParserState.OutputBuffer = pParserState.Pattern.Parse(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length + pParserState.Pattern.PatternEndString.length)), pData);
|
|
238
|
+
return this.resetOutputBuffer(pParserState);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
// We are in a pattern start but didn't match one; reset and start trying again from this character.
|
|
243
|
+
this.resetOutputBuffer(pParserState);
|
|
244
|
+
}
|
|
223
245
|
}
|
|
224
|
-
this
|
|
225
|
-
if (pParserState.
|
|
226
|
-
//
|
|
227
|
-
|
|
246
|
+
// If we aren't in a pattern match or pattern, and this isn't the start of a new pattern (RAW mode)....
|
|
247
|
+
if (!pParserState.PatternMatch) {
|
|
248
|
+
// This may be the start of a new pattern....
|
|
249
|
+
if (pParserState.ParseTree.hasOwnProperty(pCharacter)) {
|
|
250
|
+
// ... assign the root node as the matched node.
|
|
251
|
+
this.resetOutputBuffer(pParserState);
|
|
252
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
253
|
+
pParserState.Pattern = pParserState.ParseTree[pCharacter];
|
|
254
|
+
pParserState.PatternMatch = true;
|
|
255
|
+
return true;
|
|
256
|
+
} else {
|
|
257
|
+
this.appendOutputBuffer(pCharacter, pParserState);
|
|
258
|
+
}
|
|
228
259
|
}
|
|
260
|
+
return false;
|
|
229
261
|
}
|
|
230
|
-
// (3) If we aren't in a pattern match or pattern, and this isn't the start of a new pattern (RAW mode)....
|
|
231
|
-
else {
|
|
232
|
-
pParserState.Output += pCharacter;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
262
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
this.
|
|
263
|
+
/**
|
|
264
|
+
* Parse a string for matches, and process any template segments that occur.
|
|
265
|
+
* @method parseString
|
|
266
|
+
* @param {string} pString - The string to parse.
|
|
267
|
+
* @param {Object} pParseTree - The parse tree to begin parsing from (usually root)
|
|
268
|
+
* @param {Object} pData - The data to pass to the function as a second parameter
|
|
269
|
+
*/
|
|
270
|
+
}, {
|
|
271
|
+
key: "parseString",
|
|
272
|
+
value: function parseString(pString, pParseTree, pData) {
|
|
273
|
+
var tmpParserState = this.newParserState(pParseTree);
|
|
274
|
+
for (var i = 0; i < pString.length; i++) {
|
|
275
|
+
this.parseCharacter(pString[i], tmpParserState, pData);
|
|
276
|
+
}
|
|
277
|
+
this.flushOutputBuffer(tmpParserState);
|
|
278
|
+
return tmpParserState.Output;
|
|
247
279
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
280
|
+
}]);
|
|
281
|
+
return StringParser;
|
|
282
|
+
}();
|
|
252
283
|
module.exports = StringParser;
|
|
253
284
|
}, {}],
|
|
254
|
-
|
|
285
|
+
3: [function (require, module, exports) {
|
|
255
286
|
/**
|
|
256
287
|
* Word Tree
|
|
257
288
|
* @author Steven Velozo <steven@velozo.com>
|
|
258
289
|
* @description Create a tree (directed graph) of Javascript objects, one character per object.
|
|
259
290
|
*/
|
|
260
|
-
|
|
261
|
-
class WordTree {
|
|
291
|
+
var WordTree = /*#__PURE__*/function () {
|
|
262
292
|
/**
|
|
263
293
|
* WordTree Constructor
|
|
264
294
|
*/
|
|
265
|
-
|
|
295
|
+
function WordTree() {
|
|
296
|
+
_classCallCheck(this, WordTree);
|
|
266
297
|
this.ParseTree = {};
|
|
267
298
|
}
|
|
268
299
|
|
|
@@ -271,39 +302,77 @@
|
|
|
271
302
|
* @method addChild
|
|
272
303
|
* @param {Object} pTree - A parse tree to push the characters into
|
|
273
304
|
* @param {string} pPattern - The string to add to the tree
|
|
274
|
-
* @param {number} pIndex - The index of the character in the pattern
|
|
275
305
|
* @returns {Object} The resulting leaf node that was added (or found)
|
|
276
306
|
* @private
|
|
277
307
|
*/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
308
|
+
_createClass(WordTree, [{
|
|
309
|
+
key: "addChild",
|
|
310
|
+
value: function addChild(pTree, pPattern) {
|
|
311
|
+
if (!pTree.hasOwnProperty(pPattern)) {
|
|
312
|
+
pTree[pPattern] = {};
|
|
313
|
+
}
|
|
314
|
+
return pTree[pPattern];
|
|
315
|
+
}
|
|
282
316
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
317
|
+
/**
|
|
318
|
+
* Add a child character to a Parse Tree PatternEnd subtree
|
|
319
|
+
* @method addChild
|
|
320
|
+
* @param {Object} pTree - A parse tree to push the characters into
|
|
321
|
+
* @param {string} pPattern - The string to add to the tree
|
|
322
|
+
* @returns {Object} The resulting leaf node that was added (or found)
|
|
323
|
+
* @private
|
|
324
|
+
*/
|
|
325
|
+
}, {
|
|
326
|
+
key: "addEndChild",
|
|
327
|
+
value: function addEndChild(pTree, pPattern) {
|
|
328
|
+
if (!pTree.hasOwnProperty('PatternEnd')) {
|
|
329
|
+
pTree.PatternEnd = {};
|
|
330
|
+
}
|
|
331
|
+
pTree.PatternEnd[pPattern] = {};
|
|
332
|
+
return pTree.PatternEnd[pPattern];
|
|
333
|
+
}
|
|
294
334
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
335
|
+
/** Add a Pattern to the Parse Tree
|
|
336
|
+
* @method addPattern
|
|
337
|
+
* @param {Object} pPatternStart - The starting string for the pattern (e.g. "${")
|
|
338
|
+
* @param {string} pPatternEnd - The ending string for the pattern (e.g. "}")
|
|
339
|
+
* @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.
|
|
340
|
+
* @return {bool} True if adding the pattern was successful
|
|
341
|
+
*/
|
|
342
|
+
}, {
|
|
343
|
+
key: "addPattern",
|
|
344
|
+
value: function addPattern(pPatternStart, pPatternEnd, fParser) {
|
|
345
|
+
if (pPatternStart.length < 1) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
if (typeof pPatternEnd === 'string' && pPatternEnd.length < 1) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
var tmpLeaf = this.ParseTree;
|
|
352
|
+
|
|
353
|
+
// Add the tree of leaves iteratively
|
|
354
|
+
for (var i = 0; i < pPatternStart.length; i++) {
|
|
355
|
+
tmpLeaf = this.addChild(tmpLeaf, pPatternStart[i], i);
|
|
356
|
+
}
|
|
357
|
+
if (!tmpLeaf.hasOwnProperty('PatternEnd')) {
|
|
358
|
+
tmpLeaf.PatternEnd = {};
|
|
359
|
+
}
|
|
360
|
+
var tmpPatternEnd = typeof pPatternEnd === 'string' ? pPatternEnd : pPatternStart;
|
|
361
|
+
for (var _i = 0; _i < tmpPatternEnd.length; _i++) {
|
|
362
|
+
tmpLeaf = this.addEndChild(tmpLeaf, tmpPatternEnd[_i], _i);
|
|
363
|
+
}
|
|
364
|
+
tmpLeaf.PatternStartString = pPatternStart;
|
|
365
|
+
tmpLeaf.PatternEndString = tmpPatternEnd;
|
|
366
|
+
tmpLeaf.Parse = typeof fParser === 'function' ? fParser : typeof fParser === 'string' ? function () {
|
|
367
|
+
return fParser;
|
|
368
|
+
} : function (pData) {
|
|
369
|
+
return pData;
|
|
370
|
+
};
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
}]);
|
|
374
|
+
return WordTree;
|
|
375
|
+
}();
|
|
307
376
|
module.exports = WordTree;
|
|
308
377
|
}, {}]
|
|
309
378
|
}, {}, [1])(1);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Precedent=t()}}((function(){return function t(e,r,n){function a(
|
|
1
|
+
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,_toPropertyKey(n.key),n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"===_typeof(e)?e:String(e)}function _toPrimitive(t,e){if("object"!==_typeof(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}function _typeof(t){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(t)}!function(t){if("object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Precedent=t()}}((function(){return function t(e,r,n){function a(f,i){if(!r[f]){if(!e[f]){var o="function"==typeof require&&require;if(!i&&o)return o(f,!0);if(u)return u(f,!0);var s=new Error("Cannot find module '"+f+"'");throw s.code="MODULE_NOT_FOUND",s}var p=r[f]={exports:{}};e[f][0].call(p.exports,(function(t){return a(e[f][1][t]||t)}),p,p.exports,t,e,r,n)}return r[f].exports}for(var u="function"==typeof require&&require,f=0;f<n.length;f++)a(n[f]);return a}({1:[function(t,e,r){
|
|
2
2
|
/**
|
|
3
3
|
* Precedent Meta-Templating
|
|
4
4
|
*
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @description Process text streams, parsing out meta-template expressions.
|
|
10
10
|
*/
|
|
11
|
-
var n=t("./WordTree.js"),a=t("./StringParser.js")
|
|
11
|
+
var n=t("./WordTree.js"),a=t("./StringParser.js"),u=function(){function t(){_classCallCheck(this,t),this.WordTree=new n,this.StringParser=new a,this.ParseTree=this.WordTree.ParseTree}return _createClass(t,[{key:"addPattern",value:function(t,e,r){return this.WordTree.addPattern(t,e,r)}},{key:"parseString",value:function(t,e){return this.StringParser.parseString(t,this.ParseTree,e)}}]),t}();e.exports=u},{"./StringParser.js":2,"./WordTree.js":3}],2:[function(t,e,r){var n=function(){function t(){_classCallCheck(this,t)}return _createClass(t,[{key:"newParserState",value:function(t){return{ParseTree:t,Asynchronous:!1,Output:"",OutputBuffer:"",Pattern:{},PatternMatch:!1,PatternMatchEnd:!1}}},{key:"appendOutputBuffer",value:function(t,e){e.OutputBuffer+=t}},{key:"flushOutputBuffer",value:function(t){t.Output+=t.OutputBuffer,t.OutputBuffer=""}},{key:"resetOutputBuffer",value:function(t){return this.flushOutputBuffer(t),t.Pattern=!1,t.PatternStartNode=!1,t.StartPatternMatchComplete=!1,t.EndPatternMatchBegan=!1,t.PatternMatch=!1,!0}},{key:"parseCharacter",value:function(t,e,r){if(e.PatternMatch)if(!e.StartPatternMatchComplete&&e.Pattern.hasOwnProperty(t))e.Pattern=e.Pattern[t],this.appendOutputBuffer(t,e);else if(e.EndPatternMatchBegan)if(e.Pattern.PatternEnd.hasOwnProperty(t)){if(e.Pattern=e.Pattern.PatternEnd[t],this.appendOutputBuffer(t,e),e.Pattern.hasOwnProperty("Parse"))return e.OutputBuffer=e.Pattern.Parse(e.OutputBuffer.substr(e.Pattern.PatternStartString.length,e.OutputBuffer.length-(e.Pattern.PatternStartString.length+e.Pattern.PatternEndString.length)),r),this.resetOutputBuffer(e)}else e.PatternStartNode.PatternEnd.hasOwnProperty(t)?(e.Pattern=e.PatternStartNode.PatternEnd[t],this.appendOutputBuffer(t,e)):(e.EndPatternMatchBegan=!1,this.appendOutputBuffer(t,e));else if(e.Pattern.hasOwnProperty("PatternEnd")){if(e.StartPatternMatchComplete||(e.StartPatternMatchComplete=!0,e.PatternStartNode=e.Pattern),this.appendOutputBuffer(t,e),e.Pattern.PatternEnd.hasOwnProperty(t)&&(e.EndPatternMatchBegan=!0,e.Pattern=e.Pattern.PatternEnd[t],e.Pattern.hasOwnProperty("Parse")))return e.OutputBuffer=e.Pattern.Parse(e.OutputBuffer.substr(e.Pattern.PatternStartString.length,e.OutputBuffer.length-(e.Pattern.PatternStartString.length+e.Pattern.PatternEndString.length)),r),this.resetOutputBuffer(e)}else this.resetOutputBuffer(e);if(!e.PatternMatch){if(e.ParseTree.hasOwnProperty(t))return this.resetOutputBuffer(e),this.appendOutputBuffer(t,e),e.Pattern=e.ParseTree[t],e.PatternMatch=!0,!0;this.appendOutputBuffer(t,e)}return!1}},{key:"parseString",value:function(t,e,r){for(var n=this.newParserState(e),a=0;a<t.length;a++)this.parseCharacter(t[a],n,r);return this.flushOutputBuffer(n),n.Output}}]),t}();e.exports=n},{}],3:[function(t,e,r){var n=function(){function t(){_classCallCheck(this,t),this.ParseTree={}}return _createClass(t,[{key:"addChild",value:function(t,e){return t.hasOwnProperty(e)||(t[e]={}),t[e]}},{key:"addEndChild",value:function(t,e){return t.hasOwnProperty("PatternEnd")||(t.PatternEnd={}),t.PatternEnd[e]={},t.PatternEnd[e]}},{key:"addPattern",value:function(t,e,r){if(t.length<1)return!1;if("string"==typeof e&&e.length<1)return!1;for(var n=this.ParseTree,a=0;a<t.length;a++)n=this.addChild(n,t[a],a);n.hasOwnProperty("PatternEnd")||(n.PatternEnd={});for(var u="string"==typeof e?e:t,f=0;f<u.length;f++)n=this.addEndChild(n,u[f],f);return n.PatternStartString=t,n.PatternEndString=u,n.Parse="function"==typeof r?r:"string"==typeof r?function(){return r}:function(t){return t},!0}}]),t}();e.exports=n},{}]},{},[1])(1)}));
|
|
12
12
|
//# sourceMappingURL=precedent.compatible.min.js.map
|