clarity-pattern-parser 11.0.23 → 11.0.24
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 +21 -21
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +21 -21
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +21 -21
- package/dist/index.js.map +1 -1
- package/dist/patterns/Optional.d.ts +1 -1
- package/package.json +1 -1
- 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.esm.js
CHANGED
|
@@ -523,20 +523,31 @@ class Cursor {
|
|
|
523
523
|
|
|
524
524
|
function execPattern(pattern, text, record = false) {
|
|
525
525
|
const cursor = new Cursor(text);
|
|
526
|
+
if (cursor.length === 0) {
|
|
527
|
+
return { ast: null, cursor };
|
|
528
|
+
}
|
|
526
529
|
record && cursor.startRecording();
|
|
527
|
-
|
|
528
|
-
const
|
|
530
|
+
let ast = pattern.parse(cursor);
|
|
531
|
+
const resultLength = ast == null ? 0 : ast.value.length;
|
|
532
|
+
if (ast != null) {
|
|
533
|
+
const isMatch = ast.value === text;
|
|
534
|
+
if (!isMatch && !cursor.hasError) {
|
|
535
|
+
ast = null;
|
|
536
|
+
cursor.recordErrorAt(resultLength, cursor.length, pattern);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
cursor.recordErrorAt(resultLength, cursor.length, pattern);
|
|
541
|
+
}
|
|
529
542
|
return {
|
|
530
|
-
ast:
|
|
543
|
+
ast: ast,
|
|
531
544
|
cursor
|
|
532
545
|
};
|
|
533
546
|
}
|
|
534
547
|
|
|
535
548
|
function testPattern(pattern, text, record = false) {
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
const ast = pattern.parse(cursor);
|
|
539
|
-
return (ast === null || ast === void 0 ? void 0 : ast.value.length) === text.length;
|
|
549
|
+
const result = execPattern(pattern, text, record);
|
|
550
|
+
return !result.cursor.hasError;
|
|
540
551
|
}
|
|
541
552
|
|
|
542
553
|
let idIndex$9 = 0;
|
|
@@ -600,9 +611,6 @@ class Literal {
|
|
|
600
611
|
_tryToParse(cursor) {
|
|
601
612
|
let passed = false;
|
|
602
613
|
const literalRuneLength = this._runes.length;
|
|
603
|
-
if (!cursor.hasNext) {
|
|
604
|
-
return false;
|
|
605
|
-
}
|
|
606
614
|
for (let i = 0; i < literalRuneLength; i++) {
|
|
607
615
|
const literalRune = this._runes[i];
|
|
608
616
|
const cursorRune = cursor.currentChar;
|
|
@@ -1986,19 +1994,11 @@ class Optional {
|
|
|
1986
1994
|
this._children = [pattern.clone()];
|
|
1987
1995
|
this._children[0].parent = this;
|
|
1988
1996
|
}
|
|
1989
|
-
test(text) {
|
|
1990
|
-
|
|
1991
|
-
this.parse(cursor);
|
|
1992
|
-
return !cursor.hasError;
|
|
1997
|
+
test(text, record = false) {
|
|
1998
|
+
return testPattern(this, text, record);
|
|
1993
1999
|
}
|
|
1994
2000
|
exec(text, record = false) {
|
|
1995
|
-
|
|
1996
|
-
record && cursor.startRecording();
|
|
1997
|
-
const ast = this.parse(cursor);
|
|
1998
|
-
return {
|
|
1999
|
-
ast: (ast === null || ast === void 0 ? void 0 : ast.value) === text ? ast : null,
|
|
2000
|
-
cursor
|
|
2001
|
-
};
|
|
2001
|
+
return execPattern(this, text, record);
|
|
2002
2002
|
}
|
|
2003
2003
|
parse(cursor) {
|
|
2004
2004
|
const firstIndex = cursor.index;
|