clarity-pattern-parser 11.0.20 → 11.0.21
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 +8 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +8 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/grammar/Grammar.test.ts +2 -1
- package/src/grammar/Grammar.ts +7 -4
- package/src/patterns/Expression.ts +2 -0
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import { Grammar } from "./Grammar";
|
|
|
10
10
|
import { Optional } from "../patterns/Optional";
|
|
11
11
|
import { Context } from "../patterns/Context";
|
|
12
12
|
import { patterns } from "./patterns";
|
|
13
|
+
import { Expression } from "../patterns/Expression";
|
|
13
14
|
|
|
14
15
|
describe("Grammar", () => {
|
|
15
16
|
test("Literal", () => {
|
|
@@ -517,7 +518,7 @@ debugger;
|
|
|
517
518
|
],
|
|
518
519
|
true
|
|
519
520
|
),
|
|
520
|
-
new
|
|
521
|
+
new Expression("anonymous", [
|
|
521
522
|
new Reference("pattern"),
|
|
522
523
|
new Reference("pattern")
|
|
523
524
|
])
|
package/src/grammar/Grammar.ts
CHANGED
|
@@ -280,6 +280,10 @@ export class Grammar {
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
private _isRecursivePattern(name: string, pattern: Pattern) {
|
|
283
|
+
if (pattern.type === "reference") {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
|
|
283
287
|
if (pattern.children.length === 0) {
|
|
284
288
|
return false;
|
|
285
289
|
}
|
|
@@ -287,10 +291,9 @@ export class Grammar {
|
|
|
287
291
|
const firstChild = pattern.children[0];
|
|
288
292
|
const lastChild = pattern.children[pattern.children.length - 1];
|
|
289
293
|
const isLongEnough = pattern.children.length >= 2;
|
|
290
|
-
return pattern.type === "
|
|
291
|
-
(
|
|
292
|
-
|
|
293
|
-
(lastChild.name === name));
|
|
294
|
+
return (pattern.type === "sequence" && isLongEnough &&
|
|
295
|
+
(firstChild.name === name) ||
|
|
296
|
+
(lastChild.name === name));
|
|
294
297
|
}
|
|
295
298
|
|
|
296
299
|
private _buildPattern(node: Node): Pattern {
|