clarity-pattern-parser 8.4.12 → 8.4.14
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/grammar/Grammar.d.ts +1 -0
- package/dist/index.browser.js +20 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +20 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/grammar/Grammar.test.ts +11 -0
- package/src/grammar/Grammar.ts +15 -2
- package/src/grammar/patterns/literal.ts +1 -1
package/src/grammar/Grammar.ts
CHANGED
|
@@ -186,7 +186,7 @@ export class Grammar {
|
|
|
186
186
|
const importStatements = importStatement.findAll(n => n.name === "import-name" || n.name === "import-alias");
|
|
187
187
|
|
|
188
188
|
importStatements.forEach((node) => {
|
|
189
|
-
if (node.name === "import-name" && node.parent?.name === "import-alias"){
|
|
189
|
+
if (node.name === "import-name" && node.parent?.name === "import-alias") {
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
192
|
|
|
@@ -263,13 +263,26 @@ export class Grammar {
|
|
|
263
263
|
private _buildLiteral(statementNode: Node) {
|
|
264
264
|
const nameNode = statementNode.find(n => n.name === "name") as Node;
|
|
265
265
|
const literalNode = statementNode.find(n => n.name === "literal") as Node;
|
|
266
|
-
const value = literalNode.value.slice(1, literalNode.value.length - 1);
|
|
267
266
|
const name = nameNode.value;
|
|
267
|
+
const value = this._resolveStringValue(literalNode.value.slice(1, -1));
|
|
268
268
|
const literal = new Literal(name, value);
|
|
269
269
|
|
|
270
270
|
this._parseContext.patternsByName.set(name, literal)
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
+
private _resolveStringValue(value: string) {
|
|
274
|
+
return value.replace(/\\n/g, '\n')
|
|
275
|
+
.replace(/\\r/g, '\r')
|
|
276
|
+
.replace(/\\t/g, '\t')
|
|
277
|
+
.replace(/\\b/g, '\b')
|
|
278
|
+
.replace(/\\f/g, '\f')
|
|
279
|
+
.replace(/\\v/g, '\v')
|
|
280
|
+
.replace(/\\0/g, '\0')
|
|
281
|
+
.replace(/\\x([0-9A-Fa-f]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
|
|
282
|
+
.replace(/\\u([0-9A-Fa-f]{4})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
|
|
283
|
+
.replace(/\\(.)/g, '$1');
|
|
284
|
+
}
|
|
285
|
+
|
|
273
286
|
private _buildRegex(statementNode: Node) {
|
|
274
287
|
const nameNode = statementNode.find(n => n.name === "name") as Node;
|
|
275
288
|
const regexNode = statementNode.find(n => n.name === "regex-literal") as Node;
|