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.
@@ -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;
@@ -1,5 +1,5 @@
1
1
  import { Regex } from "../../patterns/Regex";
2
2
 
3
- export const literal = new Regex("literal", "\"(?:\\\\[\"\\\\]|[^\n\"\\\\])*\"");
3
+ export const literal = new Regex("literal", '"((?:\\\\.|[^"\\\\])*)"');
4
4
 
5
5