From 4c385e5daddc6790a1e371598efba88771cb47ae Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Fri, 28 Jul 2023 10:37:05 +0100 Subject: [PATCH 1/2] Add python support for match/case This adds match & case as keywords, used by python 3.10 structural pattern matching ( https://peps.python.org/pep-0634/ ) --- lib/rouge/lexers/python.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rouge/lexers/python.rb b/lib/rouge/lexers/python.rb index b47b64aa76..09d2041a6d 100644 --- a/lib/rouge/lexers/python.rb +++ b/lib/rouge/lexers/python.rb @@ -21,7 +21,7 @@ def self.keywords assert break continue del elif else except exec finally for global if lambda pass print raise return try while yield as with from import yield - async await nonlocal + async await nonlocal match case ) end From f9ef7092f1fadfa4dd07c84e13f9407745384daf Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Fri, 28 Jul 2023 10:44:57 +0100 Subject: [PATCH 2/2] add pattern matching example to samples --- spec/visual/samples/python | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/visual/samples/python b/spec/visual/samples/python index b9fbf4e818..0c3456f670 100644 --- a/spec/visual/samples/python +++ b/spec/visual/samples/python @@ -218,3 +218,10 @@ def do_nothing(): app = FastAPI() FastAPIInstrumentor.instrument_app(app) + +# Structural pattern matching (PEP634) +match point: + case Point(x, y) if x == y: + print(f"The point is located on the diagonal Y=X at {x}.") + case Point(x, y): + print(f"Point is not on the diagonal.")