clarity-pattern-parser
Advanced tools
Comparing version
{ | ||
"name": "clarity-pattern-parser", | ||
"version": "11.1.5", | ||
"version": "11.2.0", | ||
"description": "Parsing Library for Typescript and Javascript.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -14,2 +14,3 @@ import { Sequence } from "../patterns/Sequence"; | ||
import { Expression } from "../patterns/Expression"; | ||
import { Cursor } from "../patterns/Cursor"; | ||
@@ -772,2 +773,11 @@ describe("Grammar", () => { | ||
test("Take Until", () => { | ||
const { scriptText } = patterns` | ||
script-text = ?->| "</script" | ||
`; | ||
const result = scriptText.parse(new Cursor("function(){}</script")); | ||
expect(result?.value).toBe("function(){}"); | ||
}); | ||
}); |
@@ -14,2 +14,3 @@ import { Node } from "../ast/Node"; | ||
import { Expression } from "../patterns/Expression"; | ||
import { TakeUntil } from "../patterns/TakeUntil"; | ||
import { RightAssociated } from "../patterns/RightAssociated"; | ||
@@ -34,2 +35,3 @@ import { generateErrorMessage } from "../patterns/generate_error_message"; | ||
"alias-literal": true, | ||
"take-until-literal": true, | ||
"configurable-anonymous-pattern": true | ||
@@ -185,2 +187,6 @@ }; | ||
} | ||
case "take-until-literal": { | ||
this._saveTakeUntil(n); | ||
break; | ||
} | ||
case "configurable-anonymous-pattern": { | ||
@@ -202,2 +208,3 @@ this._saveConfigurableAnonymous(n); | ||
private _saveLiteral(statementNode: Node) { | ||
@@ -329,2 +336,5 @@ const nameNode = statementNode.find(n => n.name === "name") as Node; | ||
} | ||
case "take-until-literal": { | ||
return this._buildTakeUntil(name, node); | ||
} | ||
case "complex-anonymous-pattern": { | ||
@@ -430,2 +440,20 @@ return this._buildComplexAnonymousPattern(node); | ||
private _saveTakeUntil(statementNode: Node) { | ||
const nameNode = statementNode.find(n => n.name === "name") as Node; | ||
const name = nameNode.value; | ||
const takeUntilNode = statementNode.find(n => n.name === "take-until-literal") as Node; | ||
const takeUntil = this._buildTakeUntil(name, takeUntilNode); | ||
this._applyDecorators(statementNode, takeUntil); | ||
this._parseContext.patternsByName.set(name, takeUntil); | ||
} | ||
private _buildTakeUntil(name: string, takeUntilNode: Node) { | ||
const patternNode = takeUntilNode.children[takeUntilNode.children.length - 1]; | ||
const untilPattern = this._buildPattern(patternNode); | ||
return new TakeUntil(name, untilPattern); | ||
} | ||
private _saveConfigurableAnonymous(node: Node) { | ||
@@ -450,3 +478,3 @@ const nameNode = node.find(n => n.name === "name") as Node; | ||
const importStatements = ast.findAll(n => { | ||
return n.name === "import-from" || n.name === "param-name-with-default-value" | ||
return n.name === "import-from" || n.name === "param-name-with-default-value"; | ||
}); | ||
@@ -453,0 +481,0 @@ |
@@ -17,2 +17,3 @@ import { Options } from "../../patterns/Options"; | ||
export const anonymousWrappedLiterals = new Options("anonymous-wrapped-literals", [ | ||
new Reference("take-until-literal"), | ||
new Reference("options-literal"), | ||
@@ -19,0 +20,0 @@ new Reference("sequence-literal"), |
@@ -8,2 +8,3 @@ import { Options } from "../../patterns/Options"; | ||
import { anonymousPattern } from "./anonymousPattern"; | ||
import { takeUntilLiteral } from "./takeUtilLiteral"; | ||
import { Sequence } from "../../patterns/Sequence"; | ||
@@ -24,2 +25,3 @@ import { Literal } from "../../patterns/Literal"; | ||
repeatLiteral, | ||
takeUntilLiteral, | ||
aliasLiteral, | ||
@@ -29,2 +31,2 @@ optionsLiteral, | ||
configurableAnonymousPattern, | ||
], true); | ||
], true); |
1514980
0.55%205
1.49%26302
0.88%