Skip to content

Incorrect verbatim string regex. #7

Open
@RocketRide9

Description

@RocketRide9

Currently regex matches characters until latest appearance of """. Which leads to such bugs:

Image

Adding ? to regex should fix that, but I don't how to test patched grammar. Here is the patch if someone wants to test it and submit MR:

diff --git a/grammar.js b/grammar.js
index c503e69..51ea8c9 100644
--- a/grammar.js
+++ b/grammar.js
@@ -279,7 +279,7 @@ module.exports = grammar({
       seq('$(', $._expression, ')'),
       seq('$', $.identifier)
     ),
-    verbatim_string: $=> /"""(.|\n)*"""/,
+    verbatim_string: $=> /""".*?"""/s,
 
     literal: $ => choice(
         $.boolean,

Also replaced (.|\n) with s regex option, which makes . to match newlines. It performs slightly faster according to regex101.com and is more idiomatic IMO.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions