From 774a0a8f52c6b670b5fddebb620c28bf9e9177df Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 1 May 2021 14:53:15 +0200 Subject: [PATCH 1/2] Add match and case syntax --- grammars/MagicPython.cson | 17 +++ grammars/MagicPython.tmLanguage | 16 +++ grammars/src/MagicPython.syntax.yaml | 11 ++ test/atom-spec/python-spec.js | 189 +++++++++++++++++++++++++++ test/statements/match.py | 118 +++++++++++++++++ 5 files changed, 351 insertions(+) create mode 100644 test/statements/match.py diff --git a/grammars/MagicPython.cson b/grammars/MagicPython.cson index 6486dba4..486d9839 100644 --- a/grammars/MagicPython.cson +++ b/grammars/MagicPython.cson @@ -294,6 +294,23 @@ repository: ''' } + { + name: "keyword.control.flow.python" + comment: ''' + `match` and `case` are only soft keywords. Match if + followed by `:` or anything that allows for line continuation. + + ''' + match: ''' + (?x) + \\b(? + + + name + keyword.control.flow.python + comment + `match` and `case` are only soft keywords. Match if +followed by `:` or anything that allows for line continuation. + + match + (?x) + \b(?<!\.)( + match | case + )\b( + (?=.*[:\\]) | (?=\s*[\(\[\{]) + ) diff --git a/grammars/src/MagicPython.syntax.yaml b/grammars/src/MagicPython.syntax.yaml index 9c80c8b3..42cdfe53 100644 --- a/grammars/src/MagicPython.syntax.yaml +++ b/grammars/src/MagicPython.syntax.yaml @@ -381,6 +381,17 @@ repository: | from | elif | else | if | except | pass | raise | return | try | while | with )\b + - name: keyword.control.flow.python + comment: | + `match` and `case` are only soft keywords. Match if + followed by `:` or anything that allows for line continuation. + match: | + (?x) + \b(? Date: Mon, 3 May 2021 12:45:24 +0200 Subject: [PATCH 2/2] Improve regex and tests --- grammars/MagicPython.cson | 4 +- grammars/MagicPython.tmLanguage | 4 +- grammars/src/MagicPython.syntax.yaml | 4 +- test/atom-spec/python-spec.js | 219 +++++++++++++----------- test/statements/{match.py => match1.py} | 24 +-- test/statements/match2.py | 21 +++ 6 files changed, 154 insertions(+), 122 deletions(-) rename test/statements/{match.py => match1.py} (86%) create mode 100644 test/statements/match2.py diff --git a/grammars/MagicPython.cson b/grammars/MagicPython.cson index 486d9839..0e32aa04 100644 --- a/grammars/MagicPython.cson +++ b/grammars/MagicPython.cson @@ -303,9 +303,9 @@ repository: ''' match: ''' (?x) - \\b(? match (?x) - \b(?<!\.)( + (?:^\s*)\b( match | case - )\b( + )\b(?: (?=.*[:\\]) | (?=\s*[\(\[\{]) ) diff --git a/grammars/src/MagicPython.syntax.yaml b/grammars/src/MagicPython.syntax.yaml index 42cdfe53..a8596b53 100644 --- a/grammars/src/MagicPython.syntax.yaml +++ b/grammars/src/MagicPython.syntax.yaml @@ -387,9 +387,9 @@ repository: followed by `:` or anything that allows for line continuation. match: | (?x) - \b(?