clarity-pattern-parser
Advanced tools
Comparing version 2.0.12 to 2.0.13
@@ -100,2 +100,50 @@ "use strict"; | ||
} | ||
}, { | ||
key: "getAllParseStacks", | ||
value: function getAllParseStacks() { | ||
var stacks = this.astNodes.reduce(function (acc, node) { | ||
var container = acc[acc.length - 1]; | ||
if (node.startIndex === 0) { | ||
container = []; | ||
acc.push(container); | ||
} | ||
container.push(node); | ||
return acc; | ||
}, []); // There are times when the matching will fail and hit again on the same node. | ||
// This filters them out. | ||
// We simply check to see if there is any overlap with the previous one, | ||
// and if there is we don't add it. This is why we move backwards. | ||
var cleanedStack = stacks.map(function (stack) { | ||
var cleanedStack = []; | ||
for (var x = stack.length - 1; x >= 0; x--) { | ||
var currentNode = stack[x]; | ||
var previousNode = stack[x + 1]; | ||
if (previousNode == null) { | ||
cleanedStack.unshift(currentNode); | ||
} else { | ||
var left = Math.max(currentNode.startIndex, previousNode.startIndex); | ||
var right = Math.min(currentNode.endIndex, previousNode.endIndex); | ||
var isOverlapping = left <= right; | ||
if (!isOverlapping) { | ||
cleanedStack.unshift(currentNode); | ||
} | ||
} | ||
} | ||
return cleanedStack; | ||
}); | ||
return cleanedStack; | ||
} | ||
}, { | ||
key: "getLastParseStack", | ||
value: function getLastParseStack() { | ||
var stacks = this.getAllParseStacks(); | ||
return stacks[stacks.length - 1] || []; | ||
} | ||
}]); | ||
@@ -102,0 +150,0 @@ |
@@ -9,2 +9,4 @@ "use strict"; | ||
var _sentence = _interopRequireDefault(require("./patterns/sentence.js")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -89,2 +91,34 @@ | ||
}; | ||
exports["CursorHistory: getAllParseStacks."] = function () { | ||
var text = "Pat went to the"; | ||
var cursor = new _index.Cursor(text); | ||
cursor.startRecording(); | ||
_sentence.default.parse(cursor); | ||
var stacks = cursor.history.getAllParseStacks(); | ||
}; | ||
exports["CursorHistory: getLastParseStack."] = function () { | ||
var text = "Pat went to the"; | ||
var cursor = new _index.Cursor(text); | ||
cursor.startRecording(); | ||
_sentence.default.parse(cursor); | ||
var stack = cursor.history.getLastParseStack(); | ||
_assert.default.equal(stack.length, 5); | ||
_assert.default.equal(stack[0].name, "pat"); | ||
_assert.default.equal(stack[1].name, "space"); | ||
_assert.default.equal(stack[2].name, "went-to"); | ||
_assert.default.equal(stack[3].name, "space"); | ||
_assert.default.equal(stack[4].name, "the"); | ||
}; | ||
//# sourceMappingURL=CursorHistory.js.map |
@@ -39,2 +39,18 @@ "use strict"; | ||
var inspection = textInspector.inspect(text, _sentence.default); | ||
_assert.default.equal(inspection.error.startIndex, 4); | ||
_assert.default.equal(inspection.error.endIndex, 7); | ||
_assert.default.equal(inspection.error.text, "wzoo"); | ||
_assert.default.equal(inspection.match.startIndex, 0); | ||
_assert.default.equal(inspection.match.endIndex, 3); | ||
_assert.default.equal(inspection.match.text, "Pat "); | ||
_assert.default.equal(inspection.tokens, null); | ||
_assert.default.equal(inspection.isComplete, false); | ||
}; | ||
@@ -46,2 +62,16 @@ | ||
var inspection = textInspector.inspect(text, _sentence.default); | ||
_assert.default.equal(inspection.error.startIndex, 0); | ||
_assert.default.equal(inspection.error.endIndex, 3); | ||
_assert.default.equal(inspection.error.text, "bank"); | ||
_assert.default.equal(inspection.tokens, null); | ||
_assert.default.equal(inspection.pattern, null); | ||
_assert.default.equal(inspection.match, null); | ||
_assert.default.equal(inspection.isComplete, false); | ||
}; | ||
@@ -53,2 +83,16 @@ | ||
var inspection = textInspector.inspect(text, _sentence.default); | ||
_assert.default.equal(inspection.error.startIndex, 0); | ||
_assert.default.equal(inspection.error.endIndex, 9); | ||
_assert.default.equal(inspection.error.text, "store bank"); | ||
_assert.default.equal(inspection.tokens, null); | ||
_assert.default.equal(inspection.pattern, null); | ||
_assert.default.equal(inspection.match, null); | ||
_assert.default.equal(inspection.isComplete, false); | ||
}; | ||
@@ -60,2 +104,16 @@ | ||
var inspection = textInspector.inspect(text, _sentence.default); | ||
_assert.default.equal(inspection.match.startIndex, 0); | ||
_assert.default.equal(inspection.match.endIndex, 6); | ||
_assert.default.equal(inspection.match.text, "Pat wen"); | ||
_assert.default.equal(inspection.tokens.options.length, 1); | ||
_assert.default.equal(inspection.tokens.options[0], "t to"); | ||
_assert.default.equal(inspection.isComplete, false); | ||
_assert.default.equal(inspection.error, null); | ||
}; | ||
@@ -67,8 +125,16 @@ | ||
var inspection = textInspector.inspect(text, _sentence.default); | ||
}; | ||
exports["TextInspector: No match with error."] = function () { | ||
var text = "Jared left "; | ||
var textInspector = new _TextInspector.default(); | ||
var inspection = textInspector.inspect(text, _sentence.default); | ||
_assert.default.equal(inspection.error, null); | ||
_assert.default.equal(inspection.tokens.options.length, 2); | ||
_assert.default.equal(inspection.tokens.options[0], "Pat"); | ||
_assert.default.equal(inspection.tokens.options[1], "Dan"); | ||
_assert.default.equal(inspection.pattern, null); | ||
_assert.default.equal(inspection.match, null); | ||
_assert.default.equal(inspection.isComplete, false); | ||
}; | ||
@@ -80,2 +146,14 @@ | ||
var inspection = textInspector.inspect(text, _sentence.default); | ||
_assert.default.equal(inspection.error, null); | ||
_assert.default.equal(inspection.tokens, null); | ||
_assert.default.equal(inspection.match.startIndex, 0); | ||
_assert.default.equal(inspection.match.endIndex, 22); | ||
_assert.default.equal(inspection.match.text, "Pat went to a big store"); | ||
_assert.default.equal(inspection.isComplete, true); | ||
}; | ||
@@ -87,2 +165,14 @@ | ||
var inspection = _TextInspector.default.inspect(text, _sentence.default); | ||
_assert.default.equal(inspection.error, null); | ||
_assert.default.equal(inspection.tokens, null); | ||
_assert.default.equal(inspection.match.startIndex, 0); | ||
_assert.default.equal(inspection.match.endIndex, 22); | ||
_assert.default.equal(inspection.match.text, "Pat went to a big store"); | ||
_assert.default.equal(inspection.isComplete, true); | ||
}; | ||
@@ -101,2 +191,20 @@ | ||
var inspection = _TextInspector.default.inspect("Show me ", either); | ||
_assert.default.equal(inspection.error, null); | ||
_assert.default.equal(inspection.tokens.startIndex, 8); | ||
_assert.default.equal(inspection.tokens.options.length, 2); | ||
_assert.default.equal(inspection.tokens.options[0], "the money"); | ||
_assert.default.equal(inspection.tokens.options[1], "your license"); | ||
_assert.default.equal(inspection.match.startIndex, 0); | ||
_assert.default.equal(inspection.match.endIndex, 7); | ||
_assert.default.equal(inspection.match.text, "Show me "); | ||
_assert.default.equal(inspection.isComplete, false); | ||
}; | ||
@@ -108,67 +216,81 @@ | ||
inspection = _TextInspector.default.inspect("{\"blah\":", _json.default); | ||
_assert.default.equal(inspection.error, null); | ||
_assert.default.equal(inspection.tokens.startIndex, 8); | ||
_assert.default.equal(inspection.tokens.options.length, 9); | ||
_assert.default.equal(inspection.tokens.options[0], " "); | ||
_assert.default.equal(inspection.tokens.options[1], "number"); | ||
_assert.default.equal(inspection.tokens.options[2], "'"); | ||
_assert.default.equal(inspection.tokens.options[3], "\""); | ||
_assert.default.equal(inspection.tokens.options[4], "true"); | ||
_assert.default.equal(inspection.tokens.options[5], "false"); | ||
_assert.default.equal(inspection.tokens.options[6], "null"); | ||
_assert.default.equal(inspection.tokens.options[7], "{"); | ||
_assert.default.equal(inspection.tokens.options[8], "["); | ||
_assert.default.equal(inspection.match.startIndex, 0); | ||
_assert.default.equal(inspection.match.endIndex, 7); | ||
_assert.default.equal(inspection.match.text, "{\"blah\":"); | ||
_assert.default.equal(inspection.isComplete, false); | ||
inspection = _TextInspector.default.inspect("{\"blah\":{", _json.default); | ||
_assert.default.equal(inspection.error, null); | ||
_assert.default.equal(inspection.tokens.startIndex, 9); | ||
_assert.default.equal(inspection.tokens.options.length, 4); | ||
_assert.default.equal(inspection.tokens.options[0], " "); | ||
_assert.default.equal(inspection.tokens.options[1], "'"); | ||
_assert.default.equal(inspection.tokens.options[2], "\""); | ||
_assert.default.equal(inspection.tokens.options[3], "}"); | ||
_assert.default.equal(inspection.match.startIndex, 0); | ||
_assert.default.equal(inspection.match.endIndex, 8); | ||
_assert.default.equal(inspection.match.text, "{\"blah\":{"); | ||
_assert.default.equal(inspection.isComplete, false); | ||
inspection = _TextInspector.default.inspect("{\"blah\":0.9", _json.default); | ||
}; | ||
exports["TextInspector: json inspect timing."] = function () { | ||
var inspection = _TextInspector.default.inspect("{", _json.default); | ||
_assert.default.equal(inspection.error, null); | ||
var largeObject = [{ | ||
firstName: "John", | ||
lastName: "Doe", | ||
age: 10 | ||
}, { | ||
firstName: "Jack", | ||
lastName: "Doe", | ||
age: 20 | ||
}, { | ||
firstName: "Joe", | ||
lastName: "Doe", | ||
age: 50 | ||
}, { | ||
firstName: "John", | ||
lastName: "Smith", | ||
age: 80 | ||
}, { | ||
firstName: "Joe", | ||
lastName: "Smith", | ||
age: 10 | ||
}, { | ||
firstName: "John", | ||
lastName: "Doe", | ||
age: 10 | ||
}, { | ||
firstName: "Jack", | ||
lastName: "Doe", | ||
age: 20 | ||
}, { | ||
firstName: "Joe", | ||
lastName: "Doe", | ||
age: 50 | ||
}, { | ||
firstName: "John", | ||
lastName: "Smith", | ||
age: 80 | ||
}, { | ||
firstName: "Joe", | ||
lastName: "Smith", | ||
age: 10 | ||
}]; | ||
var smallObject = [{ | ||
firstName: "John", | ||
lastName: "Doe", | ||
age: 10 | ||
}]; | ||
var largeJson = JSON.stringify(largeObject); | ||
var smallJson = JSON.stringify(smallObject); | ||
var startTime = Date.now(); //inspection = TextInspector.inspect(`{"blah":`, json); | ||
//inspection = TextInspector.inspect(`{"blah":{`, json); | ||
_assert.default.equal(inspection.tokens.startIndex, 11); | ||
for (var x = 0; x < 1; x++) { | ||
inspection = _TextInspector.default.inspect(largeJson, _json.default); | ||
} | ||
_assert.default.equal(inspection.tokens.options.length, 3); | ||
var endTime = Date.now(); | ||
var duration = endTime - startTime; | ||
_assert.default.equal(inspection.tokens.options[0], " "); | ||
_assert.default.equal(inspection.tokens.options[1], ","); | ||
_assert.default.equal(inspection.tokens.options[2], "}"); | ||
_assert.default.equal(inspection.match.startIndex, 0); | ||
_assert.default.equal(inspection.match.endIndex, 10); | ||
_assert.default.equal(inspection.match.text, "{\"blah\":0.9"); | ||
_assert.default.equal(inspection.isComplete, false); | ||
}; | ||
//# sourceMappingURL=TextInspector.js.map |
@@ -38,2 +38,3 @@ "use strict"; | ||
this.options = []; | ||
this.parseStack = []; | ||
} | ||
@@ -58,3 +59,4 @@ | ||
}, | ||
isComplete: false | ||
isComplete: false, | ||
parseStack: [] | ||
}; | ||
@@ -64,2 +66,3 @@ } | ||
this.parse(); | ||
this.saveParseStack(); | ||
this.saveMatchedText(); | ||
@@ -76,3 +79,4 @@ this.saveMatch(); | ||
tokens: this.tokens, | ||
isComplete: this.cursor.didSuccessfullyParse() | ||
isComplete: this.cursor.didSuccessfullyParse(), | ||
parseStack: this.parseStack | ||
}; | ||
@@ -92,2 +96,4 @@ } | ||
this.tokens = null; | ||
this.options = []; | ||
this.parseStack = []; | ||
} | ||
@@ -104,2 +110,7 @@ }, { | ||
}, { | ||
key: "saveParseStack", | ||
value: function saveParseStack() { | ||
this.parseStack = this.cursor.history.getLastParseStack(); | ||
} | ||
}, { | ||
key: "saveMatchedText", | ||
@@ -106,0 +117,0 @@ value: function saveMatchedText() { |
{ | ||
"name": "clarity-pattern-parser", | ||
"type": "module", | ||
"version": "2.0.12", | ||
"version": "2.0.13", | ||
"description": "", | ||
@@ -6,0 +6,0 @@ "main": "./lib/index.js", |
@@ -79,2 +79,53 @@ export default class CursorHistory { | ||
} | ||
getAllParseStacks() { | ||
const stacks = this.astNodes.reduce((acc, node) => { | ||
let container = acc[acc.length - 1]; | ||
if (node.startIndex === 0) { | ||
container = []; | ||
acc.push(container); | ||
} | ||
container.push(node); | ||
return acc; | ||
}, []); | ||
// There are times when the matching will fail and hit again on the same node. | ||
// This filters them out. | ||
// We simply check to see if there is any overlap with the previous one, | ||
// and if there is we don't add it. This is why we move backwards. | ||
const cleanedStack = stacks.map((stack) => { | ||
const cleanedStack = []; | ||
for (let x = stack.length - 1; x >= 0; x--) { | ||
const currentNode = stack[x]; | ||
const previousNode = stack[x + 1]; | ||
if (previousNode == null) { | ||
cleanedStack.unshift(currentNode); | ||
} else { | ||
const left = Math.max( | ||
currentNode.startIndex, | ||
previousNode.startIndex | ||
); | ||
const right = Math.min(currentNode.endIndex, previousNode.endIndex); | ||
const isOverlapping = left <= right; | ||
if (!isOverlapping) { | ||
cleanedStack.unshift(currentNode); | ||
} | ||
} | ||
} | ||
return cleanedStack; | ||
}); | ||
return cleanedStack; | ||
} | ||
getLastParseStack() { | ||
const stacks = this.getAllParseStacks(); | ||
return stacks[stacks.length - 1] || []; | ||
} | ||
} |
import CursorHistory from "../CursorHistory.js"; | ||
import assert from "assert"; | ||
import { ValuePattern, ValueNode } from "../index.js"; | ||
import { ValuePattern, ValueNode, Cursor } from "../index.js"; | ||
import sentence from "./patterns/sentence.js"; | ||
@@ -76,1 +77,32 @@ exports["CursorHistory: addMatch"] = () => { | ||
}; | ||
exports[ | ||
"CursorHistory: getAllParseStacks." | ||
] = () => { | ||
const text = "Pat went to the"; | ||
const cursor = new Cursor(text); | ||
cursor.startRecording(); | ||
sentence.parse(cursor); | ||
const stacks = cursor.history.getAllParseStacks(); | ||
}; | ||
exports[ | ||
"CursorHistory: getLastParseStack." | ||
] = () => { | ||
const text = "Pat went to the"; | ||
const cursor = new Cursor(text); | ||
cursor.startRecording(); | ||
sentence.parse(cursor); | ||
const stack = cursor.history.getLastParseStack(); | ||
assert.equal(stack.length, 5); | ||
assert.equal(stack[0].name, "pat"); | ||
assert.equal(stack[1].name, "space"); | ||
assert.equal(stack[2].name, "went-to"); | ||
assert.equal(stack[3].name, "space"); | ||
assert.equal(stack[4].name, "the"); | ||
}; |
@@ -26,2 +26,11 @@ import TextInspector from "../TextInspector.js"; | ||
const inspection = textInspector.inspect(text, sentence); | ||
assert.equal(inspection.error.startIndex, 4); | ||
assert.equal(inspection.error.endIndex, 7); | ||
assert.equal(inspection.error.text, "wzoo"); | ||
assert.equal(inspection.match.startIndex, 0); | ||
assert.equal(inspection.match.endIndex, 3); | ||
assert.equal(inspection.match.text, "Pat "); | ||
assert.equal(inspection.tokens, null); | ||
assert.equal(inspection.isComplete, false); | ||
}; | ||
@@ -34,2 +43,10 @@ | ||
const inspection = textInspector.inspect(text, sentence); | ||
assert.equal(inspection.error.startIndex, 0); | ||
assert.equal(inspection.error.endIndex, 3); | ||
assert.equal(inspection.error.text, "bank"); | ||
assert.equal(inspection.tokens, null); | ||
assert.equal(inspection.pattern, null); | ||
assert.equal(inspection.match, null); | ||
assert.equal(inspection.isComplete, false); | ||
}; | ||
@@ -44,2 +61,10 @@ | ||
const inspection = textInspector.inspect(text, sentence); | ||
assert.equal(inspection.error.startIndex, 0); | ||
assert.equal(inspection.error.endIndex, 9); | ||
assert.equal(inspection.error.text, "store bank"); | ||
assert.equal(inspection.tokens, null); | ||
assert.equal(inspection.pattern, null); | ||
assert.equal(inspection.match, null); | ||
assert.equal(inspection.isComplete, false); | ||
}; | ||
@@ -52,2 +77,10 @@ | ||
const inspection = textInspector.inspect(text, sentence); | ||
assert.equal(inspection.match.startIndex, 0); | ||
assert.equal(inspection.match.endIndex, 6); | ||
assert.equal(inspection.match.text, "Pat wen"); | ||
assert.equal(inspection.tokens.options.length, 1); | ||
assert.equal(inspection.tokens.options[0], "t to"); | ||
assert.equal(inspection.isComplete, false); | ||
assert.equal(inspection.error, null); | ||
}; | ||
@@ -60,9 +93,10 @@ | ||
const inspection = textInspector.inspect(text, sentence); | ||
}; | ||
exports["TextInspector: No match with error."] = () => { | ||
const text = "Jared left "; | ||
const textInspector = new TextInspector(); | ||
const inspection = textInspector.inspect(text, sentence); | ||
assert.equal(inspection.error, null); | ||
assert.equal(inspection.tokens.options.length, 2); | ||
assert.equal(inspection.tokens.options[0], "Pat"); | ||
assert.equal(inspection.tokens.options[1], "Dan"); | ||
assert.equal(inspection.pattern, null); | ||
assert.equal(inspection.match, null); | ||
assert.equal(inspection.isComplete, false); | ||
}; | ||
@@ -75,2 +109,9 @@ | ||
const inspection = textInspector.inspect(text, sentence); | ||
assert.equal(inspection.error, null); | ||
assert.equal(inspection.tokens, null); | ||
assert.equal(inspection.match.startIndex, 0); | ||
assert.equal(inspection.match.endIndex, 22); | ||
assert.equal(inspection.match.text, "Pat went to a big store"); | ||
assert.equal(inspection.isComplete, true); | ||
}; | ||
@@ -81,2 +122,9 @@ | ||
const inspection = TextInspector.inspect(text, sentence); | ||
assert.equal(inspection.error, null); | ||
assert.equal(inspection.tokens, null); | ||
assert.equal(inspection.match.startIndex, 0); | ||
assert.equal(inspection.match.endIndex, 22); | ||
assert.equal(inspection.match.text, "Pat went to a big store"); | ||
assert.equal(inspection.isComplete, true); | ||
}; | ||
@@ -95,2 +143,12 @@ | ||
const inspection = TextInspector.inspect("Show me ", either); | ||
assert.equal(inspection.error, null); | ||
assert.equal(inspection.tokens.startIndex, 8); | ||
assert.equal(inspection.tokens.options.length, 2); | ||
assert.equal(inspection.tokens.options[0], "the money"); | ||
assert.equal(inspection.tokens.options[1], "your license"); | ||
assert.equal(inspection.match.startIndex, 0); | ||
assert.equal(inspection.match.endIndex, 7); | ||
assert.equal(inspection.match.text, "Show me "); | ||
assert.equal(inspection.isComplete, false); | ||
}; | ||
@@ -102,84 +160,47 @@ | ||
inspection = TextInspector.inspect(`{"blah":`, json); | ||
inspection = TextInspector.inspect(`{"blah":{`, json); | ||
inspection = TextInspector.inspect(`{"blah":0.9`, json); | ||
}; | ||
exports["TextInspector: json inspect timing."] = () => { | ||
let inspection = TextInspector.inspect("{", json); | ||
const largeObject = [ | ||
{ | ||
firstName: "John", | ||
lastName: "Doe", | ||
age: 10, | ||
}, | ||
{ | ||
firstName: "Jack", | ||
lastName: "Doe", | ||
age: 20, | ||
}, | ||
{ | ||
firstName: "Joe", | ||
lastName: "Doe", | ||
age: 50, | ||
}, | ||
{ | ||
firstName: "John", | ||
lastName: "Smith", | ||
age: 80, | ||
}, | ||
{ | ||
firstName: "Joe", | ||
lastName: "Smith", | ||
age: 10, | ||
}, | ||
{ | ||
firstName: "John", | ||
lastName: "Doe", | ||
age: 10, | ||
}, | ||
{ | ||
firstName: "Jack", | ||
lastName: "Doe", | ||
age: 20, | ||
}, | ||
{ | ||
firstName: "Joe", | ||
lastName: "Doe", | ||
age: 50, | ||
}, | ||
{ | ||
firstName: "John", | ||
lastName: "Smith", | ||
age: 80, | ||
}, | ||
{ | ||
firstName: "Joe", | ||
lastName: "Smith", | ||
age: 10, | ||
}, | ||
]; | ||
assert.equal(inspection.error, null); | ||
assert.equal(inspection.tokens.startIndex, 8); | ||
assert.equal(inspection.tokens.options.length, 9); | ||
assert.equal(inspection.tokens.options[0], " "); | ||
assert.equal(inspection.tokens.options[1], "number"); | ||
assert.equal(inspection.tokens.options[2], "'"); | ||
assert.equal(inspection.tokens.options[3], "\""); | ||
assert.equal(inspection.tokens.options[4], "true"); | ||
assert.equal(inspection.tokens.options[5], "false"); | ||
assert.equal(inspection.tokens.options[6], "null"); | ||
assert.equal(inspection.tokens.options[7], "{"); | ||
assert.equal(inspection.tokens.options[8], "["); | ||
assert.equal(inspection.match.startIndex, 0); | ||
assert.equal(inspection.match.endIndex, 7); | ||
assert.equal(inspection.match.text, `{"blah":`); | ||
assert.equal(inspection.isComplete, false); | ||
const smallObject = [ | ||
{ | ||
firstName: "John", | ||
lastName: "Doe", | ||
age: 10, | ||
}, | ||
]; | ||
inspection = TextInspector.inspect(`{"blah":{`, json); | ||
const largeJson = JSON.stringify(largeObject); | ||
const smallJson = JSON.stringify(smallObject); | ||
assert.equal(inspection.error, null); | ||
assert.equal(inspection.tokens.startIndex, 9); | ||
assert.equal(inspection.tokens.options.length, 4); | ||
assert.equal(inspection.tokens.options[0], " "); | ||
assert.equal(inspection.tokens.options[1], "'"); | ||
assert.equal(inspection.tokens.options[2], "\""); | ||
assert.equal(inspection.tokens.options[3], "}"); | ||
assert.equal(inspection.match.startIndex, 0); | ||
assert.equal(inspection.match.endIndex, 8); | ||
assert.equal(inspection.match.text, `{"blah":{`); | ||
assert.equal(inspection.isComplete, false); | ||
const startTime = Date.now(); | ||
//inspection = TextInspector.inspect(`{"blah":`, json); | ||
//inspection = TextInspector.inspect(`{"blah":{`, json); | ||
inspection = TextInspector.inspect(`{"blah":0.9`, json); | ||
for (let x = 0; x < 1; x++) { | ||
inspection = TextInspector.inspect(largeJson, json); | ||
} | ||
const endTime = Date.now(); | ||
const duration = endTime - startTime; | ||
assert.equal(inspection.error, null); | ||
assert.equal(inspection.tokens.startIndex, 11); | ||
assert.equal(inspection.tokens.options.length, 3); | ||
assert.equal(inspection.tokens.options[0], " "); | ||
assert.equal(inspection.tokens.options[1], ","); | ||
assert.equal(inspection.tokens.options[2], "}"); | ||
assert.equal(inspection.match.startIndex, 0); | ||
assert.equal(inspection.match.endIndex, 10); | ||
assert.equal(inspection.match.text, `{"blah":0.9`); | ||
assert.equal(inspection.isComplete, false); | ||
}; |
@@ -15,2 +15,3 @@ import { Cursor } from "./index.js"; | ||
this.options = []; | ||
this.parseStack = []; | ||
} | ||
@@ -36,2 +37,3 @@ | ||
isComplete: false, | ||
parseStack: [] | ||
}; | ||
@@ -41,2 +43,3 @@ } | ||
this.parse(); | ||
this.saveParseStack(); | ||
this.saveMatchedText(); | ||
@@ -55,2 +58,3 @@ this.saveMatch(); | ||
isComplete: this.cursor.didSuccessfullyParse(), | ||
parseStack: this.parseStack | ||
}; | ||
@@ -69,2 +73,4 @@ } | ||
this.tokens = null; | ||
this.options = []; | ||
this.parseStack = []; | ||
} | ||
@@ -80,2 +86,6 @@ | ||
saveParseStack() { | ||
this.parseStack = this.cursor.history.getLastParseStack(); | ||
} | ||
saveMatchedText() { | ||
@@ -82,0 +92,0 @@ if (this.patternMatch.astNode != null) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
885749
13222