clarity-pattern-parser 11.0.23 → 11.0.25
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/dist/index.browser.js +26 -23
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +26 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +26 -23
- package/dist/index.js.map +1 -1
- package/dist/patterns/Expression.d.ts +1 -0
- package/dist/patterns/Optional.d.ts +1 -1
- package/package.json +1 -1
- package/src/patterns/Expression.ts +7 -3
- package/src/patterns/FiniteRepeat.test.ts +2 -2
- package/src/patterns/Literal.ts +0 -4
- package/src/patterns/Optional.test.ts +1 -1
- package/src/patterns/Optional.ts +5 -14
- package/src/patterns/execPattern.ts +24 -8
- package/src/patterns/testPattern.ts +4 -7
- package/src/query/query.test.ts +2 -1
package/dist/index.browser.js
CHANGED
|
@@ -529,20 +529,31 @@
|
|
|
529
529
|
|
|
530
530
|
function execPattern(pattern, text, record = false) {
|
|
531
531
|
const cursor = new Cursor(text);
|
|
532
|
+
if (cursor.length === 0) {
|
|
533
|
+
return { ast: null, cursor };
|
|
534
|
+
}
|
|
532
535
|
record && cursor.startRecording();
|
|
533
|
-
|
|
534
|
-
const
|
|
536
|
+
let ast = pattern.parse(cursor);
|
|
537
|
+
const resultLength = ast == null ? 0 : ast.value.length;
|
|
538
|
+
if (ast != null) {
|
|
539
|
+
const isMatch = ast.value === text;
|
|
540
|
+
if (!isMatch && !cursor.hasError) {
|
|
541
|
+
ast = null;
|
|
542
|
+
cursor.recordErrorAt(resultLength, cursor.length, pattern);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
cursor.recordErrorAt(resultLength, cursor.length, pattern);
|
|
547
|
+
}
|
|
535
548
|
return {
|
|
536
|
-
ast:
|
|
549
|
+
ast: ast,
|
|
537
550
|
cursor
|
|
538
551
|
};
|
|
539
552
|
}
|
|
540
553
|
|
|
541
554
|
function testPattern(pattern, text, record = false) {
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
const ast = pattern.parse(cursor);
|
|
545
|
-
return (ast === null || ast === void 0 ? void 0 : ast.value.length) === text.length;
|
|
555
|
+
const result = execPattern(pattern, text, record);
|
|
556
|
+
return !result.cursor.hasError;
|
|
546
557
|
}
|
|
547
558
|
|
|
548
559
|
let idIndex$9 = 0;
|
|
@@ -606,9 +617,6 @@
|
|
|
606
617
|
_tryToParse(cursor) {
|
|
607
618
|
let passed = false;
|
|
608
619
|
const literalRuneLength = this._runes.length;
|
|
609
|
-
if (!cursor.hasNext) {
|
|
610
|
-
return false;
|
|
611
|
-
}
|
|
612
620
|
for (let i = 0; i < literalRuneLength; i++) {
|
|
613
621
|
const literalRune = this._runes[i];
|
|
614
622
|
const cursorRune = cursor.currentChar;
|
|
@@ -1992,19 +2000,11 @@
|
|
|
1992
2000
|
this._children = [pattern.clone()];
|
|
1993
2001
|
this._children[0].parent = this;
|
|
1994
2002
|
}
|
|
1995
|
-
test(text) {
|
|
1996
|
-
|
|
1997
|
-
this.parse(cursor);
|
|
1998
|
-
return !cursor.hasError;
|
|
2003
|
+
test(text, record = false) {
|
|
2004
|
+
return testPattern(this, text, record);
|
|
1999
2005
|
}
|
|
2000
2006
|
exec(text, record = false) {
|
|
2001
|
-
|
|
2002
|
-
record && cursor.startRecording();
|
|
2003
|
-
const ast = this.parse(cursor);
|
|
2004
|
-
return {
|
|
2005
|
-
ast: (ast === null || ast === void 0 ? void 0 : ast.value) === text ? ast : null,
|
|
2006
|
-
cursor
|
|
2007
|
-
};
|
|
2007
|
+
return execPattern(this, text, record);
|
|
2008
2008
|
}
|
|
2009
2009
|
parse(cursor) {
|
|
2010
2010
|
const firstIndex = cursor.index;
|
|
@@ -2824,12 +2824,15 @@
|
|
|
2824
2824
|
}
|
|
2825
2825
|
return pattern.name === this.name;
|
|
2826
2826
|
}
|
|
2827
|
-
|
|
2828
|
-
this._firstIndex = cursor.index;
|
|
2827
|
+
build() {
|
|
2829
2828
|
if (!this._hasOrganized) {
|
|
2830
2829
|
this._hasOrganized = true;
|
|
2831
2830
|
this._organizePatterns(this._originalPatterns);
|
|
2832
2831
|
}
|
|
2832
|
+
}
|
|
2833
|
+
parse(cursor) {
|
|
2834
|
+
this._firstIndex = cursor.index;
|
|
2835
|
+
this.build();
|
|
2833
2836
|
// If there are not any atom nodes then nothing can be found.
|
|
2834
2837
|
if (this._atomPatterns.length < 1) {
|
|
2835
2838
|
cursor.moveTo(this._firstIndex);
|