summaryrefslogtreecommitdiffstats
path: root/Parser/Python.asdl
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2021-04-29 05:58:44 (GMT)
committerGitHub <noreply@github.com>2021-04-29 05:58:44 (GMT)
commit1e7b858575d0ad782939f86aae4a2fa1c29e9f14 (patch)
tree9445a7a82905c5bb253564853f33dacfceac6e93 /Parser/Python.asdl
parente52ab42cedd2a5ef4c3c1a47d0cf96a8f06d051f (diff)
downloadcpython-1e7b858575d0ad782939f86aae4a2fa1c29e9f14.zip
cpython-1e7b858575d0ad782939f86aae4a2fa1c29e9f14.tar.gz
cpython-1e7b858575d0ad782939f86aae4a2fa1c29e9f14.tar.bz2
bpo-43892: Make match patterns explicit in the AST (GH-25585)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
Diffstat (limited to 'Parser/Python.asdl')
-rw-r--r--Parser/Python.asdl20
1 files changed, 15 insertions, 5 deletions
diff --git a/Parser/Python.asdl b/Parser/Python.asdl
index e224f5f..85225fc 100644
--- a/Parser/Python.asdl
+++ b/Parser/Python.asdl
@@ -89,10 +89,6 @@ module Python
-- can appear only in Subscript
| Slice(expr? lower, expr? upper, expr? step)
- -- only used in patterns
- | MatchAs(expr pattern, identifier name)
- | MatchOr(expr* patterns)
-
-- col_offset is the byte offset in the utf8 string the parser uses
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
@@ -128,7 +124,21 @@ module Python
withitem = (expr context_expr, expr? optional_vars)
- match_case = (expr pattern, expr? guard, stmt* body)
+ match_case = (pattern pattern, expr? guard, stmt* body)
+
+ pattern = MatchValue(expr value)
+ | MatchSingleton(constant value)
+ | MatchSequence(pattern* patterns)
+ | MatchMapping(expr* keys, pattern* patterns, identifier? rest)
+ | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)
+
+ | MatchStar(identifier? name)
+ -- The optional "rest" MatchMapping parameter handles capturing extra mapping keys
+
+ | MatchAs(pattern? pattern, identifier? name)
+ | MatchOr(pattern* patterns)
+
+ attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
type_ignore = TypeIgnore(int lineno, string tag)
}