]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix handling of standalone match/case with newlines/comments (#2760)
authorBatuhan Taskaya <isidentical@gmail.com>
Mon, 10 Jan 2022 20:22:07 +0000 (23:22 +0300)
committerGitHub <noreply@github.com>
Mon, 10 Jan 2022 20:22:07 +0000 (12:22 -0800)
Resolves #2759

CHANGES.md
src/blib2to3/pgen2/parse.py
tests/data/pattern_matching_style.py

index a1c8ccb0b7d739b5449b2f21c0ffab5510c11221..748dbca70195620e85f96aec5b7455600bc2e51d 100644 (file)
@@ -26,6 +26,8 @@
   be formatted. (#2526)
 - Speed-up the new backtracking parser about 4X in general (enabled when
   `--target-version` is set to 3.10 and higher). (#2728)
+- Fix handling of standalone `match()` or `case()` when there is a trailing newline or a
+  comment inside of the parentheses. (#2760)
 
 ### Packaging
 
index 8fe9667289796bf16d2186b17a81a3b8cf1a6ece..4a23d538b493659a448d941bcc3801fc2abd5b82 100644 (file)
@@ -269,6 +269,10 @@ class Parser(object):
                     break
 
                 next_token_type, next_token_value, *_ = proxy.eat(counter)
+                if next_token_type in (tokenize.COMMENT, tokenize.NL):
+                    counter += 1
+                    continue
+
                 if next_token_type == tokenize.OP:
                     next_token_type = grammar.opmap[next_token_value]
 
index c1c0aeedb70391de28543ef62ff013b29b2a9b16..8e18ce2ada6dda70dd8c82d2733034b807e44384 100644 (file)
@@ -6,10 +6,52 @@ match something:
     ): print(1)
     case c(
         very_complex=True,
-        perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1
+        perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1,
     ): print(2)
     case a: pass
 
+match(
+    arg # comment
+)
+
+match(
+)
+
+match(
+
+
+)
+
+case(
+    arg # comment
+)
+
+case(
+)
+
+case(
+
+
+)
+
+
+re.match(
+    something # fast
+)
+re.match(
+
+
+
+)
+match match(
+
+
+):
+    case case(
+        arg, # comment
+    ):
+        pass
+
 # output
 
 match something:
@@ -20,8 +62,30 @@ match something:
     ):
         print(1)
     case c(
-        very_complex=True, perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1
+        very_complex=True,
+        perhaps_even_loooooooooooooooooooooooooooooooooooooong=-1,
     ):
         print(2)
     case a:
         pass
+
+match(arg)  # comment
+
+match()
+
+match()
+
+case(arg)  # comment
+
+case()
+
+case()
+
+
+re.match(something)  # fast
+re.match()
+match match():
+    case case(
+        arg,  # comment
+    ):
+        pass