diff --git a/parser/build.rs b/parser/build.rs index f9a3439..e693601 100644 --- a/parser/build.rs +++ b/parser/build.rs @@ -119,6 +119,7 @@ fn gen_phf(out_dir: &Path) { .entry("async", "Tok::Async") .entry("await", "Tok::Await") .entry("break", "Tok::Break") + .entry("case", "Tok::Case") .entry("class", "Tok::Class") .entry("continue", "Tok::Continue") .entry("def", "Tok::Def") @@ -135,6 +136,7 @@ fn gen_phf(out_dir: &Path) { .entry("in", "Tok::In") .entry("is", "Tok::Is") .entry("lambda", "Tok::Lambda") + .entry("match", "Tok::Match") .entry("nonlocal", "Tok::Nonlocal") .entry("not", "Tok::Not") .entry("or", "Tok::Or") diff --git a/parser/python.lalrpop b/parser/python.lalrpop index 749c07d..9b3d226 100644 --- a/parser/python.lalrpop +++ b/parser/python.lalrpop @@ -348,6 +348,7 @@ AssertStatement: ast::Stmt = { }; CompoundStatement: ast::Stmt = { + MatchStatement, IfStatement, WhileStatement, ForStatement, @@ -357,6 +358,561 @@ CompoundStatement: ast::Stmt = { ClassDef, }; +MatchStatement: ast::Stmt = { + "match" ":" "\n" Indent Dedent => { + ast::Stmt { + location, + end_location: Some(end_location), + custom: (), + node: ast::StmtKind::Match { + subject: Box::new(subject), + cases + } + } + }, + "match" "," ":" "\n" Indent Dedent => { + ast::Stmt { + location, + end_location: Some(end_location), + custom: (), + node: ast::StmtKind::Match { + subject: Box::new(subject), + cases + } + } + }, + "match" "," > ","? ":" "\n" Indent Dedent => { + let mut subjects = subjects; + subjects.insert(0, subject); + ast::Stmt { + custom: (), + location, + end_location: Some(end_location), + node: ast::StmtKind::Match { + subject: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Tuple { + elts: subjects, + ctx: ast::ExprContext::Load, + }, + }), + cases + } + } + } +} + +MatchCase: ast::MatchCase = { + "case" ":" => { + ast::MatchCase { + pattern, + guard: guard.map(Box::new), + body + } + }, +} + +Guard: ast::Expr = { + "if" => { + guard + } +} + +Patterns: ast::Pattern = { + "," => ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node: ast::PatternKind::MatchSequence { + patterns: vec![pattern] + }, + }, + "," > ","? => { + let mut patterns = patterns; + patterns.insert(0, pattern); + ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node: ast::PatternKind::MatchSequence { + patterns + }, + } + }, + => pattern +} + +Pattern: ast::Pattern = { + => pattern, + => pattern, +} + +AsPattern: ast::Pattern = { + "as" =>? { + if name == "_" { + Err(LexicalError { + error: LexicalErrorType::OtherError("cannot use '_' as a target".to_string()), + location, + })? + } else { + Ok(ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node: ast::PatternKind::MatchAs { + pattern: Some(Box::new(pattern)), + name: Some(name), + }, + }) + } + }, +} + +OrPattern: ast::Pattern = { + => pattern, + )+> => { + let mut patterns = patterns; + patterns.insert(0, pattern); + ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node: ast::PatternKind::MatchOr { patterns } + } + } +} + +ClosedPattern: ast::Pattern = { + => ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node, + }, + => ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node, + }, + => ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node, + }, + => ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node, + }, + => ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node, + }, + => ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node, + }, + => ast::Pattern { + location, + end_location: Some(end_location), + custom: (), + node, + }, +} + +SequencePattern: ast::PatternKind = { + // A single-item tuple is a special case: it's a group pattern, _not_ a sequence pattern. + "(" ")" => pattern.node, + "(" ")" => ast::PatternKind::MatchSequence { + patterns: vec![], + }, + "(" "," > ")" => { + let mut patterns = patterns; + patterns.insert(0, pattern); + ast::PatternKind::MatchSequence { + patterns + } + }, + "[" > "]" => ast::PatternKind::MatchSequence { + patterns + }, +} + +StarPattern: ast::PatternKind = { + "*" => ast::PatternKind::MatchStar { + name: if name == "_" { None } else { Some(name) } + }, +} + +LiteralPattern: ast::PatternKind = { + "None" => ast::PatternKind::MatchSingleton { + value: ast::Constant::None + }, + "True" => ast::PatternKind::MatchSingleton { + value: true.into() + }, + "False" => ast::PatternKind::MatchSingleton { + value: false.into() + }, + => ast::PatternKind::MatchValue { + value: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value, kind: None } + }) + }, + "-" => ast::PatternKind::MatchValue { + value: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::UnaryOp { + op: ast::Unaryop::USub, + operand: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value, kind: None } + }) + } + }) + }, + => ast::PatternKind::MatchValue { + value: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::BinOp { + left: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value: left, kind: None } + }), + op, + right: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value: right, kind: None } + }), + } + }) + }, + "-" => ast::PatternKind::MatchValue { + value: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::BinOp { + left: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::UnaryOp { + op: ast::Unaryop::USub, + operand: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value: left, kind: None } + }) + } + }), + op, + right: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value: right, kind: None } + }), + } + }) + }, + =>? Ok(ast::PatternKind::MatchValue { + value: Box::new(parse_strings(s)?) + }), +} + +CapturePattern: ast::PatternKind = { + => ast::PatternKind::MatchAs { + pattern: None, + name: if name == "_" { None } else { Some(name) } + }, +} + +MatchName: ast::Expr = { + => ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Name { id: name, ctx: ast::ExprContext::Load }, + }, +} + +MatchNameOrAttr: ast::Expr = { + "." => ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Attribute { + value: Box::new(name), + attr, + ctx: ast::ExprContext::Load, + }, + }, + "." => ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Attribute { + value: Box::new(e), + attr, + ctx: ast::ExprContext::Load, + } + } +} + +ValuePattern: ast::PatternKind = { + => ast::PatternKind::MatchValue { + value: Box::new(e) + }, +} + +MappingKey: ast::Expr = { + "None" => ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { + value: ast::Constant::None, + kind: None, + }, + }, + "True" => ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { + value: true.into(), + kind: None, + }, + }, + "False" => ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { + value: false.into(), + kind: None, + }, + }, + => ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value, kind: None } + }, + "-" => ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::UnaryOp { + op: ast::Unaryop::USub, + operand: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value, kind: None } + }) + } + }, + => ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::BinOp { + left: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value: left, kind: None } + }), + op, + right: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value: right, kind: None } + }), + } + }, + "-" => ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::BinOp { + left: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::UnaryOp { + op: ast::Unaryop::USub, + operand: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value: left, kind: None } + }) + } + }), + op, + right: Box::new(ast::Expr { + location, + end_location: Some(end_location), + custom: (), + node: ast::ExprKind::Constant { value: right, kind: None } + }), + } + }, + =>? Ok(parse_strings(s)?), + MatchNameOrAttr, +} + +MatchMappingEntry: (ast::Expr, ast::Pattern) = { + ":" => (k, v), +}; + +MappingPattern: ast::PatternKind = { + "{" "}" => { + return ast::PatternKind::MatchMapping { + keys: vec![], + patterns: vec![], + rest: None, + }; + }, + "{" > "}" => { + let (keys, patterns) = e + .into_iter() + .unzip(); + return ast::PatternKind::MatchMapping { + keys, + patterns, + rest: None, + }; + }, + "{" "**" "}" => { + return ast::PatternKind::MatchMapping { + keys: vec![], + patterns: vec![], + rest: Some(rest), + }; + }, + "{" > "," "**" "}" => { + let (keys, patterns) = e + .into_iter() + .unzip(); + return ast::PatternKind::MatchMapping { + keys, + patterns, + rest: Some(rest), + }; + }, +} + +MatchKeywordEntry: (String, ast::Pattern) = { + "=" => (k, v), +}; + +ClassPattern: ast::PatternKind = { + "(" > "," > ","? ")" => { + let (kwd_attrs, kwd_patterns) = kwds + .into_iter() + .unzip(); + ast::PatternKind::MatchClass { + cls: Box::new(e), + patterns, + kwd_attrs, + kwd_patterns, + } + }, + "(" > ","? ")" => { + ast::PatternKind::MatchClass { + cls: Box::new(e), + patterns, + kwd_attrs: vec![], + kwd_patterns: vec![], + } + }, + "(" > ","? ")" => { + let (kwd_attrs, kwd_patterns) = kwds + .into_iter() + .unzip(); + ast::PatternKind::MatchClass { + cls: Box::new(e), + patterns: vec![], + kwd_attrs, + kwd_patterns, + } + }, + "(" ")" => { + ast::PatternKind::MatchClass { + cls: Box::new(e), + patterns: vec![], + kwd_attrs: vec![], + kwd_patterns: vec![], + } + }, + "(" > "," > ","? ")" => { + let (kwd_attrs, kwd_patterns) = kwds + .into_iter() + .unzip(); + ast::PatternKind::MatchClass { + cls: Box::new(e), + patterns, + kwd_attrs, + kwd_patterns, + } + }, + "(" > ","? ")" => { + ast::PatternKind::MatchClass { + cls: Box::new(e), + patterns, + kwd_attrs: vec![], + kwd_patterns: vec![], + } + }, + "(" > ","? ")" => { + let (kwd_attrs, kwd_patterns) = kwds + .into_iter() + .unzip(); + ast::PatternKind::MatchClass { + cls: Box::new(e), + patterns: vec![], + kwd_attrs, + kwd_patterns, + } + }, + "(" ")" => { + ast::PatternKind::MatchClass { + cls: Box::new(e), + patterns: vec![], + kwd_attrs: vec![], + kwd_patterns: vec![], + } + }, +} + IfStatement: ast::Stmt = { "if" ":" => { // Determine last else: @@ -734,7 +1290,7 @@ ParameterListStarArgs: (Option>, Vec, Vec: ast::Expr = { "(" "**" > ")" =>? { Err(LexicalError{ error : LexicalErrorType::OtherError("cannot use double starred expression here".to_string()), - location: location, + location, }.into()) }, "{" "}" => { @@ -1463,6 +2019,8 @@ extern { "return" => lexer::Tok::Return, "try" => lexer::Tok::Try, "while" => lexer::Tok::While, + "match" => lexer::Tok::Match, + "case" => lexer::Tok::Case, "with" => lexer::Tok::With, "yield" => lexer::Tok::Yield, "True" => lexer::Tok::True, diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 5c7c964..4715dd9 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -131,4 +131,5 @@ mod string; #[rustfmt::skip] mod python; mod context; +mod soft_keywords; pub mod token; diff --git a/parser/src/parser.rs b/parser/src/parser.rs index a0ded0d..65f9ea4 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -14,6 +14,7 @@ use crate::lexer::{LexResult, Tok}; pub use crate::mode::Mode; +use crate::soft_keywords::SoftKeywordTransformer; use crate::{ast, error::ParseError, lexer, python}; use ast::Location; use itertools::Itertools; @@ -188,9 +189,8 @@ pub fn parse_tokens( let tokenizer = iter::once(Ok(marker_token)) .chain(lxr) .filter_ok(|(_, tok, _)| !matches!(tok, Tok::Comment { .. } | Tok::NonLogicalNewline)); - python::TopParser::new() - .parse(tokenizer) + .parse(SoftKeywordTransformer::new(tokenizer, mode).into_iter()) .map_err(|e| crate::error::parse_error_from_lalrpop(e, source_path)) } @@ -462,4 +462,205 @@ except* OSError as e: assert!(parse(&source, Mode::Module, "").is_ok()); assert!(parse(&source, Mode::Interactive, "").is_ok()); } + + #[test] + fn test_match_as_identifier() { + let parse_ast = parse_program( + r#" +match *a + b, c # ((match * a) + b), c +match *(a + b), c # (match * (a + b)), c +match (*a + b, c) # match ((*(a + b)), c) +match -a * b + c # (match - (a * b)) + c +match -(a * b) + c # (match - (a * b)) + c +match (-a) * b + c # (match (-(a * b))) + c +match ().a # (match()).a +match (()).a # (match(())).a +match ((),).a # (match(())).a +match [a].b # (match[a]).b +match [a,].b # (match[(a,)]).b (not (match[a]).b) +match [(a,)].b # (match[(a,)]).b +match()[a: + b] # (match())[a: b] +if match := 1: pass +match match: + case 1: pass + case 2: + pass +"#, + "", + ) + .unwrap(); + insta::assert_debug_snapshot!(parse_ast); + } + + #[test] + fn test_match_complex() { + let source = r#"# Cases sampled from Lib/test/test_patma.py + +# case test_patma_098 +match x: + case -0j: + y = 0 +# case test_patma_142 +match x: + case bytes(z): + y = 0 +# case test_patma_073 +match x: + case 0 if 0: + y = 0 + case 0 if 1: + y = 1 +# case test_patma_006 +match 3: + case 0 | 1 | 2 | 3: + x = True +# case test_patma_049 +match x: + case [0, 1] | [1, 0]: + y = 0 +# case black_check_sequence_then_mapping +match x: + case [*_]: + return "seq" + case {}: + return "map" +# case test_patma_035 +match x: + case {0: [1, 2, {}]}: + y = 0 + case {0: [1, 2, {}] | True} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}: + y = 1 + case []: + y = 2 +# case test_patma_107 +match x: + case 0.25 + 1.75j: + y = 0 +# case test_patma_097 +match x: + case -0j: + y = 0 +# case test_patma_007 +match 4: + case 0 | 1 | 2 | 3: + x = True +# case test_patma_154 +match x: + case 0 if x: + y = 0 +# case test_patma_134 +match x: + case {1: 0}: + y = 0 + case {0: 0}: + y = 1 + case {**z}: + y = 2 +# case test_patma_185 +match Seq(): + case [*_]: + y = 0 +# case test_patma_063 +match x: + case 1: + y = 0 + case 1: + y = 1 +# case test_patma_248 +match x: + case {"foo": bar}: + y = bar +# case test_patma_019 +match (0, 1, 2): + case [0, 1, *x, 2]: + y = 0 +# case test_patma_052 +match x: + case [0]: + y = 0 + case [1, 0] if (x := x[:0]): + y = 1 + case [1, 0]: + y = 2 +# case test_patma_191 +match w: + case [x, y, *_]: + z = 0 +# case test_patma_110 +match x: + case -0.25 - 1.75j: + y = 0 +# case test_patma_151 +match (x,): + case [y]: + z = 0 +# case test_patma_114 +match x: + case A.B.C.D: + y = 0 +# case test_patma_232 +match x: + case None: + y = 0 +# case test_patma_058 +match x: + case 0: + y = 0 +# case test_patma_233 +match x: + case False: + y = 0 +# case test_patma_078 +match x: + case []: + y = 0 + case [""]: + y = 1 + case "": + y = 2 +# case test_patma_156 +match x: + case z: + y = 0 +# case test_patma_189 +match w: + case [x, y, *rest]: + z = 0 +# case test_patma_042 +match x: + case (0 as z) | (1 as z) | (2 as z) if z == x % 2: + y = 0 +# case test_patma_034 +match x: + case {0: [1, 2, {}]}: + y = 0 + case {0: [1, 2, {}] | False} | {1: [[]]} | {0: [1, 2, {}]} | [] | "X" | {}: + y = 1 + case []: + y = 2 +# case test_patma_123 +match (0, 1, 2): + case 0, *x: + y = 0 +# case test_patma_126 +match (0, 1, 2): + case *x, 2,: + y = 0 +# case test_patma_151 +match x,: + case y,: + z = 0 +# case test_patma_152 +match w, x: + case y, z: + v = 0 +# case test_patma_153 +match w := x,: + case y as v,: + z = 0 +"#; + let parse_ast = parse_program(source, "").unwrap(); + insta::assert_debug_snapshot!(parse_ast); + } } diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__match_as_identifier.snap b/parser/src/snapshots/rustpython_parser__parser__tests__match_as_identifier.snap new file mode 100644 index 0000000..2568cc7 --- /dev/null +++ b/parser/src/snapshots/rustpython_parser__parser__tests__match_as_identifier.snap @@ -0,0 +1,1674 @@ +--- +source: compiler/parser/src/parser.rs +expression: parse_ast +--- +[ + Located { + location: Location { + row: 2, + column: 0, + }, + end_location: Some( + Location { + row: 2, + column: 15, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 2, + column: 0, + }, + end_location: Some( + Location { + row: 2, + column: 15, + }, + ), + custom: (), + node: Tuple { + elts: [ + Located { + location: Location { + row: 2, + column: 0, + }, + end_location: Some( + Location { + row: 2, + column: 12, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 2, + column: 0, + }, + end_location: Some( + Location { + row: 2, + column: 8, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 2, + column: 0, + }, + end_location: Some( + Location { + row: 2, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + op: Mult, + right: Located { + location: Location { + row: 2, + column: 7, + }, + end_location: Some( + Location { + row: 2, + column: 8, + }, + ), + custom: (), + node: Name { + id: "a", + ctx: Load, + }, + }, + }, + }, + op: Add, + right: Located { + location: Location { + row: 2, + column: 11, + }, + end_location: Some( + Location { + row: 2, + column: 12, + }, + ), + custom: (), + node: Name { + id: "b", + ctx: Load, + }, + }, + }, + }, + Located { + location: Location { + row: 2, + column: 14, + }, + end_location: Some( + Location { + row: 2, + column: 15, + }, + ), + custom: (), + node: Name { + id: "c", + ctx: Load, + }, + }, + ], + ctx: Load, + }, + }, + }, + }, + Located { + location: Location { + row: 3, + column: 0, + }, + end_location: Some( + Location { + row: 3, + column: 17, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 3, + column: 0, + }, + end_location: Some( + Location { + row: 3, + column: 17, + }, + ), + custom: (), + node: Tuple { + elts: [ + Located { + location: Location { + row: 3, + column: 0, + }, + end_location: Some( + Location { + row: 3, + column: 14, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 3, + column: 0, + }, + end_location: Some( + Location { + row: 3, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + op: Mult, + right: Located { + location: Location { + row: 3, + column: 8, + }, + end_location: Some( + Location { + row: 3, + column: 13, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 3, + column: 8, + }, + end_location: Some( + Location { + row: 3, + column: 9, + }, + ), + custom: (), + node: Name { + id: "a", + ctx: Load, + }, + }, + op: Add, + right: Located { + location: Location { + row: 3, + column: 12, + }, + end_location: Some( + Location { + row: 3, + column: 13, + }, + ), + custom: (), + node: Name { + id: "b", + ctx: Load, + }, + }, + }, + }, + }, + }, + Located { + location: Location { + row: 3, + column: 16, + }, + end_location: Some( + Location { + row: 3, + column: 17, + }, + ), + custom: (), + node: Name { + id: "c", + ctx: Load, + }, + }, + ], + ctx: Load, + }, + }, + }, + }, + Located { + location: Location { + row: 4, + column: 0, + }, + end_location: Some( + Location { + row: 4, + column: 17, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 4, + column: 0, + }, + end_location: Some( + Location { + row: 4, + column: 17, + }, + ), + custom: (), + node: Call { + func: Located { + location: Location { + row: 4, + column: 0, + }, + end_location: Some( + Location { + row: 4, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + args: [ + Located { + location: Location { + row: 4, + column: 7, + }, + end_location: Some( + Location { + row: 4, + column: 13, + }, + ), + custom: (), + node: Starred { + value: Located { + location: Location { + row: 4, + column: 8, + }, + end_location: Some( + Location { + row: 4, + column: 13, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 4, + column: 8, + }, + end_location: Some( + Location { + row: 4, + column: 9, + }, + ), + custom: (), + node: Name { + id: "a", + ctx: Load, + }, + }, + op: Add, + right: Located { + location: Location { + row: 4, + column: 12, + }, + end_location: Some( + Location { + row: 4, + column: 13, + }, + ), + custom: (), + node: Name { + id: "b", + ctx: Load, + }, + }, + }, + }, + ctx: Load, + }, + }, + Located { + location: Location { + row: 4, + column: 15, + }, + end_location: Some( + Location { + row: 4, + column: 16, + }, + ), + custom: (), + node: Name { + id: "c", + ctx: Load, + }, + }, + ], + keywords: [], + }, + }, + }, + }, + Located { + location: Location { + row: 5, + column: 0, + }, + end_location: Some( + Location { + row: 5, + column: 16, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 5, + column: 0, + }, + end_location: Some( + Location { + row: 5, + column: 16, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 5, + column: 0, + }, + end_location: Some( + Location { + row: 5, + column: 12, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 5, + column: 0, + }, + end_location: Some( + Location { + row: 5, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + op: Sub, + right: Located { + location: Location { + row: 5, + column: 7, + }, + end_location: Some( + Location { + row: 5, + column: 12, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 5, + column: 7, + }, + end_location: Some( + Location { + row: 5, + column: 8, + }, + ), + custom: (), + node: Name { + id: "a", + ctx: Load, + }, + }, + op: Mult, + right: Located { + location: Location { + row: 5, + column: 11, + }, + end_location: Some( + Location { + row: 5, + column: 12, + }, + ), + custom: (), + node: Name { + id: "b", + ctx: Load, + }, + }, + }, + }, + }, + }, + op: Add, + right: Located { + location: Location { + row: 5, + column: 15, + }, + end_location: Some( + Location { + row: 5, + column: 16, + }, + ), + custom: (), + node: Name { + id: "c", + ctx: Load, + }, + }, + }, + }, + }, + }, + Located { + location: Location { + row: 6, + column: 0, + }, + end_location: Some( + Location { + row: 6, + column: 18, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 6, + column: 0, + }, + end_location: Some( + Location { + row: 6, + column: 18, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 6, + column: 0, + }, + end_location: Some( + Location { + row: 6, + column: 14, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 6, + column: 0, + }, + end_location: Some( + Location { + row: 6, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + op: Sub, + right: Located { + location: Location { + row: 6, + column: 8, + }, + end_location: Some( + Location { + row: 6, + column: 13, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 6, + column: 8, + }, + end_location: Some( + Location { + row: 6, + column: 9, + }, + ), + custom: (), + node: Name { + id: "a", + ctx: Load, + }, + }, + op: Mult, + right: Located { + location: Location { + row: 6, + column: 12, + }, + end_location: Some( + Location { + row: 6, + column: 13, + }, + ), + custom: (), + node: Name { + id: "b", + ctx: Load, + }, + }, + }, + }, + }, + }, + op: Add, + right: Located { + location: Location { + row: 6, + column: 17, + }, + end_location: Some( + Location { + row: 6, + column: 18, + }, + ), + custom: (), + node: Name { + id: "c", + ctx: Load, + }, + }, + }, + }, + }, + }, + Located { + location: Location { + row: 7, + column: 0, + }, + end_location: Some( + Location { + row: 7, + column: 18, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 7, + column: 0, + }, + end_location: Some( + Location { + row: 7, + column: 18, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 7, + column: 0, + }, + end_location: Some( + Location { + row: 7, + column: 14, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 7, + column: 0, + }, + end_location: Some( + Location { + row: 7, + column: 10, + }, + ), + custom: (), + node: Call { + func: Located { + location: Location { + row: 7, + column: 0, + }, + end_location: Some( + Location { + row: 7, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + args: [ + Located { + location: Location { + row: 7, + column: 7, + }, + end_location: Some( + Location { + row: 7, + column: 9, + }, + ), + custom: (), + node: UnaryOp { + op: USub, + operand: Located { + location: Location { + row: 7, + column: 8, + }, + end_location: Some( + Location { + row: 7, + column: 9, + }, + ), + custom: (), + node: Name { + id: "a", + ctx: Load, + }, + }, + }, + }, + ], + keywords: [], + }, + }, + op: Mult, + right: Located { + location: Location { + row: 7, + column: 13, + }, + end_location: Some( + Location { + row: 7, + column: 14, + }, + ), + custom: (), + node: Name { + id: "b", + ctx: Load, + }, + }, + }, + }, + op: Add, + right: Located { + location: Location { + row: 7, + column: 17, + }, + end_location: Some( + Location { + row: 7, + column: 18, + }, + ), + custom: (), + node: Name { + id: "c", + ctx: Load, + }, + }, + }, + }, + }, + }, + Located { + location: Location { + row: 8, + column: 0, + }, + end_location: Some( + Location { + row: 8, + column: 10, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 8, + column: 0, + }, + end_location: Some( + Location { + row: 8, + column: 10, + }, + ), + custom: (), + node: Attribute { + value: Located { + location: Location { + row: 8, + column: 0, + }, + end_location: Some( + Location { + row: 8, + column: 8, + }, + ), + custom: (), + node: Call { + func: Located { + location: Location { + row: 8, + column: 0, + }, + end_location: Some( + Location { + row: 8, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + args: [], + keywords: [], + }, + }, + attr: "a", + ctx: Load, + }, + }, + }, + }, + Located { + location: Location { + row: 9, + column: 0, + }, + end_location: Some( + Location { + row: 9, + column: 12, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 9, + column: 0, + }, + end_location: Some( + Location { + row: 9, + column: 12, + }, + ), + custom: (), + node: Attribute { + value: Located { + location: Location { + row: 9, + column: 0, + }, + end_location: Some( + Location { + row: 9, + column: 10, + }, + ), + custom: (), + node: Call { + func: Located { + location: Location { + row: 9, + column: 0, + }, + end_location: Some( + Location { + row: 9, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + args: [ + Located { + location: Location { + row: 9, + column: 7, + }, + end_location: Some( + Location { + row: 9, + column: 9, + }, + ), + custom: (), + node: Tuple { + elts: [], + ctx: Load, + }, + }, + ], + keywords: [], + }, + }, + attr: "a", + ctx: Load, + }, + }, + }, + }, + Located { + location: Location { + row: 10, + column: 0, + }, + end_location: Some( + Location { + row: 10, + column: 13, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 10, + column: 0, + }, + end_location: Some( + Location { + row: 10, + column: 13, + }, + ), + custom: (), + node: Attribute { + value: Located { + location: Location { + row: 10, + column: 0, + }, + end_location: Some( + Location { + row: 10, + column: 11, + }, + ), + custom: (), + node: Call { + func: Located { + location: Location { + row: 10, + column: 0, + }, + end_location: Some( + Location { + row: 10, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + args: [ + Located { + location: Location { + row: 10, + column: 7, + }, + end_location: Some( + Location { + row: 10, + column: 9, + }, + ), + custom: (), + node: Tuple { + elts: [], + ctx: Load, + }, + }, + ], + keywords: [], + }, + }, + attr: "a", + ctx: Load, + }, + }, + }, + }, + Located { + location: Location { + row: 11, + column: 0, + }, + end_location: Some( + Location { + row: 11, + column: 11, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 11, + column: 0, + }, + end_location: Some( + Location { + row: 11, + column: 11, + }, + ), + custom: (), + node: Attribute { + value: Located { + location: Location { + row: 11, + column: 0, + }, + end_location: Some( + Location { + row: 11, + column: 9, + }, + ), + custom: (), + node: Subscript { + value: Located { + location: Location { + row: 11, + column: 0, + }, + end_location: Some( + Location { + row: 11, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + slice: Located { + location: Location { + row: 11, + column: 7, + }, + end_location: Some( + Location { + row: 11, + column: 8, + }, + ), + custom: (), + node: Name { + id: "a", + ctx: Load, + }, + }, + ctx: Load, + }, + }, + attr: "b", + ctx: Load, + }, + }, + }, + }, + Located { + location: Location { + row: 12, + column: 0, + }, + end_location: Some( + Location { + row: 12, + column: 12, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 12, + column: 0, + }, + end_location: Some( + Location { + row: 12, + column: 12, + }, + ), + custom: (), + node: Attribute { + value: Located { + location: Location { + row: 12, + column: 0, + }, + end_location: Some( + Location { + row: 12, + column: 10, + }, + ), + custom: (), + node: Subscript { + value: Located { + location: Location { + row: 12, + column: 0, + }, + end_location: Some( + Location { + row: 12, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + slice: Located { + location: Location { + row: 12, + column: 7, + }, + end_location: Some( + Location { + row: 12, + column: 9, + }, + ), + custom: (), + node: Tuple { + elts: [ + Located { + location: Location { + row: 12, + column: 7, + }, + end_location: Some( + Location { + row: 12, + column: 8, + }, + ), + custom: (), + node: Name { + id: "a", + ctx: Load, + }, + }, + ], + ctx: Load, + }, + }, + ctx: Load, + }, + }, + attr: "b", + ctx: Load, + }, + }, + }, + }, + Located { + location: Location { + row: 13, + column: 0, + }, + end_location: Some( + Location { + row: 13, + column: 14, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 13, + column: 0, + }, + end_location: Some( + Location { + row: 13, + column: 14, + }, + ), + custom: (), + node: Attribute { + value: Located { + location: Location { + row: 13, + column: 0, + }, + end_location: Some( + Location { + row: 13, + column: 12, + }, + ), + custom: (), + node: Subscript { + value: Located { + location: Location { + row: 13, + column: 0, + }, + end_location: Some( + Location { + row: 13, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + slice: Located { + location: Location { + row: 13, + column: 7, + }, + end_location: Some( + Location { + row: 13, + column: 11, + }, + ), + custom: (), + node: Tuple { + elts: [ + Located { + location: Location { + row: 13, + column: 8, + }, + end_location: Some( + Location { + row: 13, + column: 9, + }, + ), + custom: (), + node: Name { + id: "a", + ctx: Load, + }, + }, + ], + ctx: Load, + }, + }, + ctx: Load, + }, + }, + attr: "b", + ctx: Load, + }, + }, + }, + }, + Located { + location: Location { + row: 14, + column: 0, + }, + end_location: Some( + Location { + row: 15, + column: 6, + }, + ), + custom: (), + node: Expr { + value: Located { + location: Location { + row: 14, + column: 0, + }, + end_location: Some( + Location { + row: 15, + column: 6, + }, + ), + custom: (), + node: Subscript { + value: Located { + location: Location { + row: 14, + column: 0, + }, + end_location: Some( + Location { + row: 14, + column: 7, + }, + ), + custom: (), + node: Call { + func: Located { + location: Location { + row: 14, + column: 0, + }, + end_location: Some( + Location { + row: 14, + column: 5, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + args: [], + keywords: [], + }, + }, + slice: Located { + location: Location { + row: 14, + column: 8, + }, + end_location: Some( + Location { + row: 15, + column: 5, + }, + ), + custom: (), + node: Slice { + lower: Some( + Located { + location: Location { + row: 14, + column: 8, + }, + end_location: Some( + Location { + row: 14, + column: 9, + }, + ), + custom: (), + node: Name { + id: "a", + ctx: Load, + }, + }, + ), + upper: Some( + Located { + location: Location { + row: 15, + column: 4, + }, + end_location: Some( + Location { + row: 15, + column: 5, + }, + ), + custom: (), + node: Name { + id: "b", + ctx: Load, + }, + }, + ), + step: None, + }, + }, + ctx: Load, + }, + }, + }, + }, + Located { + location: Location { + row: 16, + column: 0, + }, + end_location: Some( + Location { + row: 16, + column: 19, + }, + ), + custom: (), + node: If { + test: Located { + location: Location { + row: 16, + column: 3, + }, + end_location: Some( + Location { + row: 16, + column: 13, + }, + ), + custom: (), + node: NamedExpr { + target: Located { + location: Location { + row: 16, + column: 3, + }, + end_location: Some( + Location { + row: 16, + column: 8, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Store, + }, + }, + value: Located { + location: Location { + row: 16, + column: 12, + }, + end_location: Some( + Location { + row: 16, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + body: [ + Located { + location: Location { + row: 16, + column: 15, + }, + end_location: Some( + Location { + row: 16, + column: 19, + }, + ), + custom: (), + node: Pass, + }, + ], + orelse: [], + }, + }, + Located { + location: Location { + row: 17, + column: 0, + }, + end_location: Some( + Location { + row: 21, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 17, + column: 6, + }, + end_location: Some( + Location { + row: 17, + column: 11, + }, + ), + custom: (), + node: Name { + id: "match", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 18, + column: 9, + }, + end_location: Some( + Location { + row: 18, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 18, + column: 9, + }, + end_location: Some( + Location { + row: 18, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 18, + column: 12, + }, + end_location: Some( + Location { + row: 18, + column: 16, + }, + ), + custom: (), + node: Pass, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 19, + column: 9, + }, + end_location: Some( + Location { + row: 19, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 19, + column: 9, + }, + end_location: Some( + Location { + row: 19, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 20, + column: 8, + }, + end_location: Some( + Location { + row: 20, + column: 12, + }, + ), + custom: (), + node: Pass, + }, + ], + }, + ], + }, + }, +] diff --git a/parser/src/snapshots/rustpython_parser__parser__tests__match_complex.snap b/parser/src/snapshots/rustpython_parser__parser__tests__match_complex.snap new file mode 100644 index 0000000..8317172 --- /dev/null +++ b/parser/src/snapshots/rustpython_parser__parser__tests__match_complex.snap @@ -0,0 +1,8254 @@ +--- +source: compiler/parser/src/parser.rs +expression: parse_ast +--- +[ + Located { + location: Location { + row: 4, + column: 0, + }, + end_location: Some( + Location { + row: 8, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 4, + column: 6, + }, + end_location: Some( + Location { + row: 4, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 5, + column: 9, + }, + end_location: Some( + Location { + row: 5, + column: 12, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 5, + column: 9, + }, + end_location: Some( + Location { + row: 5, + column: 12, + }, + ), + custom: (), + node: UnaryOp { + op: USub, + operand: Located { + location: Location { + row: 5, + column: 9, + }, + end_location: Some( + Location { + row: 5, + column: 12, + }, + ), + custom: (), + node: Constant { + value: Complex { + real: 0.0, + imag: 0.0, + }, + kind: None, + }, + }, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 6, + column: 8, + }, + end_location: Some( + Location { + row: 6, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 6, + column: 8, + }, + end_location: Some( + Location { + row: 6, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 6, + column: 12, + }, + end_location: Some( + Location { + row: 6, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 8, + column: 0, + }, + end_location: Some( + Location { + row: 12, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 8, + column: 6, + }, + end_location: Some( + Location { + row: 8, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 9, + column: 9, + }, + end_location: Some( + Location { + row: 9, + column: 17, + }, + ), + custom: (), + node: MatchClass { + cls: Located { + location: Location { + row: 9, + column: 9, + }, + end_location: Some( + Location { + row: 9, + column: 14, + }, + ), + custom: (), + node: Name { + id: "bytes", + ctx: Load, + }, + }, + patterns: [ + Located { + location: Location { + row: 9, + column: 15, + }, + end_location: Some( + Location { + row: 9, + column: 16, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "z", + ), + }, + }, + ], + kwd_attrs: [], + kwd_patterns: [], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 10, + column: 8, + }, + end_location: Some( + Location { + row: 10, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 10, + column: 8, + }, + end_location: Some( + Location { + row: 10, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 10, + column: 12, + }, + end_location: Some( + Location { + row: 10, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 12, + column: 0, + }, + end_location: Some( + Location { + row: 18, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 12, + column: 6, + }, + end_location: Some( + Location { + row: 12, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 13, + column: 9, + }, + end_location: Some( + Location { + row: 13, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 13, + column: 9, + }, + end_location: Some( + Location { + row: 13, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + guard: Some( + Located { + location: Location { + row: 13, + column: 14, + }, + end_location: Some( + Location { + row: 13, + column: 15, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + ), + body: [ + Located { + location: Location { + row: 14, + column: 8, + }, + end_location: Some( + Location { + row: 14, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 14, + column: 8, + }, + end_location: Some( + Location { + row: 14, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 14, + column: 12, + }, + end_location: Some( + Location { + row: 14, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 15, + column: 9, + }, + end_location: Some( + Location { + row: 15, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 15, + column: 9, + }, + end_location: Some( + Location { + row: 15, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + guard: Some( + Located { + location: Location { + row: 15, + column: 14, + }, + end_location: Some( + Location { + row: 15, + column: 15, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + ), + body: [ + Located { + location: Location { + row: 16, + column: 8, + }, + end_location: Some( + Location { + row: 16, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 16, + column: 8, + }, + end_location: Some( + Location { + row: 16, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 16, + column: 12, + }, + end_location: Some( + Location { + row: 16, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 18, + column: 0, + }, + end_location: Some( + Location { + row: 22, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 18, + column: 6, + }, + end_location: Some( + Location { + row: 18, + column: 7, + }, + ), + custom: (), + node: Constant { + value: Int( + 3, + ), + kind: None, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 19, + column: 9, + }, + end_location: Some( + Location { + row: 19, + column: 22, + }, + ), + custom: (), + node: MatchOr { + patterns: [ + Located { + location: Location { + row: 19, + column: 9, + }, + end_location: Some( + Location { + row: 19, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 19, + column: 9, + }, + end_location: Some( + Location { + row: 19, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 19, + column: 13, + }, + end_location: Some( + Location { + row: 19, + column: 14, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 19, + column: 13, + }, + end_location: Some( + Location { + row: 19, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 19, + column: 17, + }, + end_location: Some( + Location { + row: 19, + column: 18, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 19, + column: 17, + }, + end_location: Some( + Location { + row: 19, + column: 18, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 19, + column: 21, + }, + end_location: Some( + Location { + row: 19, + column: 22, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 19, + column: 21, + }, + end_location: Some( + Location { + row: 19, + column: 22, + }, + ), + custom: (), + node: Constant { + value: Int( + 3, + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 20, + column: 8, + }, + end_location: Some( + Location { + row: 20, + column: 16, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 20, + column: 8, + }, + end_location: Some( + Location { + row: 20, + column: 9, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 20, + column: 12, + }, + end_location: Some( + Location { + row: 20, + column: 16, + }, + ), + custom: (), + node: Constant { + value: Bool( + true, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 22, + column: 0, + }, + end_location: Some( + Location { + row: 26, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 22, + column: 6, + }, + end_location: Some( + Location { + row: 22, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 23, + column: 9, + }, + end_location: Some( + Location { + row: 23, + column: 24, + }, + ), + custom: (), + node: MatchOr { + patterns: [ + Located { + location: Location { + row: 23, + column: 9, + }, + end_location: Some( + Location { + row: 23, + column: 15, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 23, + column: 10, + }, + end_location: Some( + Location { + row: 23, + column: 11, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 23, + column: 10, + }, + end_location: Some( + Location { + row: 23, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 23, + column: 13, + }, + end_location: Some( + Location { + row: 23, + column: 14, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 23, + column: 13, + }, + end_location: Some( + Location { + row: 23, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + Located { + location: Location { + row: 23, + column: 18, + }, + end_location: Some( + Location { + row: 23, + column: 24, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 23, + column: 19, + }, + end_location: Some( + Location { + row: 23, + column: 20, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 23, + column: 19, + }, + end_location: Some( + Location { + row: 23, + column: 20, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 23, + column: 22, + }, + end_location: Some( + Location { + row: 23, + column: 23, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 23, + column: 22, + }, + end_location: Some( + Location { + row: 23, + column: 23, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 24, + column: 8, + }, + end_location: Some( + Location { + row: 24, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 24, + column: 8, + }, + end_location: Some( + Location { + row: 24, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 24, + column: 12, + }, + end_location: Some( + Location { + row: 24, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 26, + column: 0, + }, + end_location: Some( + Location { + row: 32, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 26, + column: 6, + }, + end_location: Some( + Location { + row: 26, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 27, + column: 9, + }, + end_location: Some( + Location { + row: 27, + column: 13, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 27, + column: 10, + }, + end_location: Some( + Location { + row: 27, + column: 12, + }, + ), + custom: (), + node: MatchStar { + name: None, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 28, + column: 8, + }, + end_location: Some( + Location { + row: 28, + column: 20, + }, + ), + custom: (), + node: Return { + value: Some( + Located { + location: Location { + row: 28, + column: 15, + }, + end_location: Some( + Location { + row: 28, + column: 20, + }, + ), + custom: (), + node: Constant { + value: Str( + "seq", + ), + kind: None, + }, + }, + ), + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 29, + column: 9, + }, + end_location: Some( + Location { + row: 29, + column: 11, + }, + ), + custom: (), + node: MatchMapping { + keys: [], + patterns: [], + rest: None, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 30, + column: 8, + }, + end_location: Some( + Location { + row: 30, + column: 20, + }, + ), + custom: (), + node: Return { + value: Some( + Located { + location: Location { + row: 30, + column: 15, + }, + end_location: Some( + Location { + row: 30, + column: 20, + }, + ), + custom: (), + node: Constant { + value: Str( + "map", + ), + kind: None, + }, + }, + ), + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 32, + column: 0, + }, + end_location: Some( + Location { + row: 40, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 32, + column: 6, + }, + end_location: Some( + Location { + row: 32, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 33, + column: 9, + }, + end_location: Some( + Location { + row: 33, + column: 24, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 33, + column: 10, + }, + end_location: Some( + Location { + row: 33, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 33, + column: 13, + }, + end_location: Some( + Location { + row: 33, + column: 23, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 33, + column: 14, + }, + end_location: Some( + Location { + row: 33, + column: 15, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 33, + column: 14, + }, + end_location: Some( + Location { + row: 33, + column: 15, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 33, + column: 17, + }, + end_location: Some( + Location { + row: 33, + column: 18, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 33, + column: 17, + }, + end_location: Some( + Location { + row: 33, + column: 18, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 33, + column: 20, + }, + end_location: Some( + Location { + row: 33, + column: 22, + }, + ), + custom: (), + node: MatchMapping { + keys: [], + patterns: [], + rest: None, + }, + }, + ], + }, + }, + ], + rest: None, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 34, + column: 8, + }, + end_location: Some( + Location { + row: 34, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 34, + column: 8, + }, + end_location: Some( + Location { + row: 34, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 34, + column: 12, + }, + end_location: Some( + Location { + row: 34, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 35, + column: 9, + }, + end_location: Some( + Location { + row: 35, + column: 77, + }, + ), + custom: (), + node: MatchOr { + patterns: [ + Located { + location: Location { + row: 35, + column: 9, + }, + end_location: Some( + Location { + row: 35, + column: 31, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 35, + column: 10, + }, + end_location: Some( + Location { + row: 35, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 35, + column: 13, + }, + end_location: Some( + Location { + row: 35, + column: 30, + }, + ), + custom: (), + node: MatchOr { + patterns: [ + Located { + location: Location { + row: 35, + column: 13, + }, + end_location: Some( + Location { + row: 35, + column: 23, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 35, + column: 14, + }, + end_location: Some( + Location { + row: 35, + column: 15, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 35, + column: 14, + }, + end_location: Some( + Location { + row: 35, + column: 15, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 35, + column: 17, + }, + end_location: Some( + Location { + row: 35, + column: 18, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 35, + column: 17, + }, + end_location: Some( + Location { + row: 35, + column: 18, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 35, + column: 20, + }, + end_location: Some( + Location { + row: 35, + column: 22, + }, + ), + custom: (), + node: MatchMapping { + keys: [], + patterns: [], + rest: None, + }, + }, + ], + }, + }, + Located { + location: Location { + row: 35, + column: 26, + }, + end_location: Some( + Location { + row: 35, + column: 30, + }, + ), + custom: (), + node: MatchSingleton { + value: Bool( + true, + ), + }, + }, + ], + }, + }, + ], + rest: None, + }, + }, + Located { + location: Location { + row: 35, + column: 34, + }, + end_location: Some( + Location { + row: 35, + column: 43, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 35, + column: 35, + }, + end_location: Some( + Location { + row: 35, + column: 36, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 35, + column: 38, + }, + end_location: Some( + Location { + row: 35, + column: 42, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 35, + column: 39, + }, + end_location: Some( + Location { + row: 35, + column: 41, + }, + ), + custom: (), + node: MatchSequence { + patterns: [], + }, + }, + ], + }, + }, + ], + rest: None, + }, + }, + Located { + location: Location { + row: 35, + column: 46, + }, + end_location: Some( + Location { + row: 35, + column: 61, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 35, + column: 47, + }, + end_location: Some( + Location { + row: 35, + column: 48, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 35, + column: 50, + }, + end_location: Some( + Location { + row: 35, + column: 60, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 35, + column: 51, + }, + end_location: Some( + Location { + row: 35, + column: 52, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 35, + column: 51, + }, + end_location: Some( + Location { + row: 35, + column: 52, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 35, + column: 54, + }, + end_location: Some( + Location { + row: 35, + column: 55, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 35, + column: 54, + }, + end_location: Some( + Location { + row: 35, + column: 55, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 35, + column: 57, + }, + end_location: Some( + Location { + row: 35, + column: 59, + }, + ), + custom: (), + node: MatchMapping { + keys: [], + patterns: [], + rest: None, + }, + }, + ], + }, + }, + ], + rest: None, + }, + }, + Located { + location: Location { + row: 35, + column: 64, + }, + end_location: Some( + Location { + row: 35, + column: 66, + }, + ), + custom: (), + node: MatchSequence { + patterns: [], + }, + }, + Located { + location: Location { + row: 35, + column: 69, + }, + end_location: Some( + Location { + row: 35, + column: 72, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 35, + column: 69, + }, + end_location: Some( + Location { + row: 35, + column: 72, + }, + ), + custom: (), + node: Constant { + value: Str( + "X", + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 35, + column: 75, + }, + end_location: Some( + Location { + row: 35, + column: 77, + }, + ), + custom: (), + node: MatchMapping { + keys: [], + patterns: [], + rest: None, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 36, + column: 8, + }, + end_location: Some( + Location { + row: 36, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 36, + column: 8, + }, + end_location: Some( + Location { + row: 36, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 36, + column: 12, + }, + end_location: Some( + Location { + row: 36, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 37, + column: 9, + }, + end_location: Some( + Location { + row: 37, + column: 11, + }, + ), + custom: (), + node: MatchSequence { + patterns: [], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 38, + column: 8, + }, + end_location: Some( + Location { + row: 38, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 38, + column: 8, + }, + end_location: Some( + Location { + row: 38, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 38, + column: 12, + }, + end_location: Some( + Location { + row: 38, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 40, + column: 0, + }, + end_location: Some( + Location { + row: 44, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 40, + column: 6, + }, + end_location: Some( + Location { + row: 40, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 41, + column: 9, + }, + end_location: Some( + Location { + row: 41, + column: 21, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 41, + column: 9, + }, + end_location: Some( + Location { + row: 41, + column: 21, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 41, + column: 9, + }, + end_location: Some( + Location { + row: 41, + column: 21, + }, + ), + custom: (), + node: Constant { + value: Float( + 0.25, + ), + kind: None, + }, + }, + op: Add, + right: Located { + location: Location { + row: 41, + column: 9, + }, + end_location: Some( + Location { + row: 41, + column: 21, + }, + ), + custom: (), + node: Constant { + value: Complex { + real: 0.0, + imag: 1.75, + }, + kind: None, + }, + }, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 42, + column: 8, + }, + end_location: Some( + Location { + row: 42, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 42, + column: 8, + }, + end_location: Some( + Location { + row: 42, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 42, + column: 12, + }, + end_location: Some( + Location { + row: 42, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 44, + column: 0, + }, + end_location: Some( + Location { + row: 48, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 44, + column: 6, + }, + end_location: Some( + Location { + row: 44, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 45, + column: 9, + }, + end_location: Some( + Location { + row: 45, + column: 12, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 45, + column: 9, + }, + end_location: Some( + Location { + row: 45, + column: 12, + }, + ), + custom: (), + node: UnaryOp { + op: USub, + operand: Located { + location: Location { + row: 45, + column: 9, + }, + end_location: Some( + Location { + row: 45, + column: 12, + }, + ), + custom: (), + node: Constant { + value: Complex { + real: 0.0, + imag: 0.0, + }, + kind: None, + }, + }, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 46, + column: 8, + }, + end_location: Some( + Location { + row: 46, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 46, + column: 8, + }, + end_location: Some( + Location { + row: 46, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 46, + column: 12, + }, + end_location: Some( + Location { + row: 46, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 48, + column: 0, + }, + end_location: Some( + Location { + row: 52, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 48, + column: 6, + }, + end_location: Some( + Location { + row: 48, + column: 7, + }, + ), + custom: (), + node: Constant { + value: Int( + 4, + ), + kind: None, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 49, + column: 9, + }, + end_location: Some( + Location { + row: 49, + column: 22, + }, + ), + custom: (), + node: MatchOr { + patterns: [ + Located { + location: Location { + row: 49, + column: 9, + }, + end_location: Some( + Location { + row: 49, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 49, + column: 9, + }, + end_location: Some( + Location { + row: 49, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 49, + column: 13, + }, + end_location: Some( + Location { + row: 49, + column: 14, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 49, + column: 13, + }, + end_location: Some( + Location { + row: 49, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 49, + column: 17, + }, + end_location: Some( + Location { + row: 49, + column: 18, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 49, + column: 17, + }, + end_location: Some( + Location { + row: 49, + column: 18, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 49, + column: 21, + }, + end_location: Some( + Location { + row: 49, + column: 22, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 49, + column: 21, + }, + end_location: Some( + Location { + row: 49, + column: 22, + }, + ), + custom: (), + node: Constant { + value: Int( + 3, + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 50, + column: 8, + }, + end_location: Some( + Location { + row: 50, + column: 16, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 50, + column: 8, + }, + end_location: Some( + Location { + row: 50, + column: 9, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 50, + column: 12, + }, + end_location: Some( + Location { + row: 50, + column: 16, + }, + ), + custom: (), + node: Constant { + value: Bool( + true, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 52, + column: 0, + }, + end_location: Some( + Location { + row: 56, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 52, + column: 6, + }, + end_location: Some( + Location { + row: 52, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 53, + column: 9, + }, + end_location: Some( + Location { + row: 53, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 53, + column: 9, + }, + end_location: Some( + Location { + row: 53, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + guard: Some( + Located { + location: Location { + row: 53, + column: 14, + }, + end_location: Some( + Location { + row: 53, + column: 15, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + ), + body: [ + Located { + location: Location { + row: 54, + column: 8, + }, + end_location: Some( + Location { + row: 54, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 54, + column: 8, + }, + end_location: Some( + Location { + row: 54, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 54, + column: 12, + }, + end_location: Some( + Location { + row: 54, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 56, + column: 0, + }, + end_location: Some( + Location { + row: 64, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 56, + column: 6, + }, + end_location: Some( + Location { + row: 56, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 57, + column: 9, + }, + end_location: Some( + Location { + row: 57, + column: 15, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 57, + column: 10, + }, + end_location: Some( + Location { + row: 57, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 57, + column: 13, + }, + end_location: Some( + Location { + row: 57, + column: 14, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 57, + column: 13, + }, + end_location: Some( + Location { + row: 57, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + ], + rest: None, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 58, + column: 8, + }, + end_location: Some( + Location { + row: 58, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 58, + column: 8, + }, + end_location: Some( + Location { + row: 58, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 58, + column: 12, + }, + end_location: Some( + Location { + row: 58, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 59, + column: 9, + }, + end_location: Some( + Location { + row: 59, + column: 15, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 59, + column: 10, + }, + end_location: Some( + Location { + row: 59, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 59, + column: 13, + }, + end_location: Some( + Location { + row: 59, + column: 14, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 59, + column: 13, + }, + end_location: Some( + Location { + row: 59, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + ], + rest: None, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 60, + column: 8, + }, + end_location: Some( + Location { + row: 60, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 60, + column: 8, + }, + end_location: Some( + Location { + row: 60, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 60, + column: 12, + }, + end_location: Some( + Location { + row: 60, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 61, + column: 9, + }, + end_location: Some( + Location { + row: 61, + column: 14, + }, + ), + custom: (), + node: MatchMapping { + keys: [], + patterns: [], + rest: Some( + "z", + ), + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 62, + column: 8, + }, + end_location: Some( + Location { + row: 62, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 62, + column: 8, + }, + end_location: Some( + Location { + row: 62, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 62, + column: 12, + }, + end_location: Some( + Location { + row: 62, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 64, + column: 0, + }, + end_location: Some( + Location { + row: 68, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 64, + column: 6, + }, + end_location: Some( + Location { + row: 64, + column: 11, + }, + ), + custom: (), + node: Call { + func: Located { + location: Location { + row: 64, + column: 6, + }, + end_location: Some( + Location { + row: 64, + column: 9, + }, + ), + custom: (), + node: Name { + id: "Seq", + ctx: Load, + }, + }, + args: [], + keywords: [], + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 65, + column: 9, + }, + end_location: Some( + Location { + row: 65, + column: 13, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 65, + column: 10, + }, + end_location: Some( + Location { + row: 65, + column: 12, + }, + ), + custom: (), + node: MatchStar { + name: None, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 66, + column: 8, + }, + end_location: Some( + Location { + row: 66, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 66, + column: 8, + }, + end_location: Some( + Location { + row: 66, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 66, + column: 12, + }, + end_location: Some( + Location { + row: 66, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 68, + column: 0, + }, + end_location: Some( + Location { + row: 74, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 68, + column: 6, + }, + end_location: Some( + Location { + row: 68, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 69, + column: 9, + }, + end_location: Some( + Location { + row: 69, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 69, + column: 9, + }, + end_location: Some( + Location { + row: 69, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 70, + column: 8, + }, + end_location: Some( + Location { + row: 70, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 70, + column: 8, + }, + end_location: Some( + Location { + row: 70, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 70, + column: 12, + }, + end_location: Some( + Location { + row: 70, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 71, + column: 9, + }, + end_location: Some( + Location { + row: 71, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 71, + column: 9, + }, + end_location: Some( + Location { + row: 71, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 72, + column: 8, + }, + end_location: Some( + Location { + row: 72, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 72, + column: 8, + }, + end_location: Some( + Location { + row: 72, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 72, + column: 12, + }, + end_location: Some( + Location { + row: 72, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 74, + column: 0, + }, + end_location: Some( + Location { + row: 78, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 74, + column: 6, + }, + end_location: Some( + Location { + row: 74, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 75, + column: 9, + }, + end_location: Some( + Location { + row: 75, + column: 21, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 75, + column: 10, + }, + end_location: Some( + Location { + row: 75, + column: 15, + }, + ), + custom: (), + node: Constant { + value: Str( + "foo", + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 75, + column: 17, + }, + end_location: Some( + Location { + row: 75, + column: 20, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "bar", + ), + }, + }, + ], + rest: None, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 76, + column: 8, + }, + end_location: Some( + Location { + row: 76, + column: 15, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 76, + column: 8, + }, + end_location: Some( + Location { + row: 76, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 76, + column: 12, + }, + end_location: Some( + Location { + row: 76, + column: 15, + }, + ), + custom: (), + node: Name { + id: "bar", + ctx: Load, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 78, + column: 0, + }, + end_location: Some( + Location { + row: 82, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 78, + column: 6, + }, + end_location: Some( + Location { + row: 78, + column: 15, + }, + ), + custom: (), + node: Tuple { + elts: [ + Located { + location: Location { + row: 78, + column: 7, + }, + end_location: Some( + Location { + row: 78, + column: 8, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + Located { + location: Location { + row: 78, + column: 10, + }, + end_location: Some( + Location { + row: 78, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + Located { + location: Location { + row: 78, + column: 13, + }, + end_location: Some( + Location { + row: 78, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + ], + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 79, + column: 9, + }, + end_location: Some( + Location { + row: 79, + column: 22, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 79, + column: 10, + }, + end_location: Some( + Location { + row: 79, + column: 11, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 79, + column: 10, + }, + end_location: Some( + Location { + row: 79, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 79, + column: 13, + }, + end_location: Some( + Location { + row: 79, + column: 14, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 79, + column: 13, + }, + end_location: Some( + Location { + row: 79, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 79, + column: 16, + }, + end_location: Some( + Location { + row: 79, + column: 18, + }, + ), + custom: (), + node: MatchStar { + name: Some( + "x", + ), + }, + }, + Located { + location: Location { + row: 79, + column: 20, + }, + end_location: Some( + Location { + row: 79, + column: 21, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 79, + column: 20, + }, + end_location: Some( + Location { + row: 79, + column: 21, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 80, + column: 8, + }, + end_location: Some( + Location { + row: 80, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 80, + column: 8, + }, + end_location: Some( + Location { + row: 80, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 80, + column: 12, + }, + end_location: Some( + Location { + row: 80, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 82, + column: 0, + }, + end_location: Some( + Location { + row: 90, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 82, + column: 6, + }, + end_location: Some( + Location { + row: 82, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 83, + column: 9, + }, + end_location: Some( + Location { + row: 83, + column: 12, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 83, + column: 10, + }, + end_location: Some( + Location { + row: 83, + column: 11, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 83, + column: 10, + }, + end_location: Some( + Location { + row: 83, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 84, + column: 8, + }, + end_location: Some( + Location { + row: 84, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 84, + column: 8, + }, + end_location: Some( + Location { + row: 84, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 84, + column: 12, + }, + end_location: Some( + Location { + row: 84, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 85, + column: 9, + }, + end_location: Some( + Location { + row: 85, + column: 15, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 85, + column: 10, + }, + end_location: Some( + Location { + row: 85, + column: 11, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 85, + column: 10, + }, + end_location: Some( + Location { + row: 85, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 85, + column: 13, + }, + end_location: Some( + Location { + row: 85, + column: 14, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 85, + column: 13, + }, + end_location: Some( + Location { + row: 85, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + guard: Some( + Located { + location: Location { + row: 85, + column: 20, + }, + end_location: Some( + Location { + row: 85, + column: 30, + }, + ), + custom: (), + node: NamedExpr { + target: Located { + location: Location { + row: 85, + column: 20, + }, + end_location: Some( + Location { + row: 85, + column: 21, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Store, + }, + }, + value: Located { + location: Location { + row: 85, + column: 25, + }, + end_location: Some( + Location { + row: 85, + column: 30, + }, + ), + custom: (), + node: Subscript { + value: Located { + location: Location { + row: 85, + column: 25, + }, + end_location: Some( + Location { + row: 85, + column: 26, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + slice: Located { + location: Location { + row: 85, + column: 27, + }, + end_location: Some( + Location { + row: 85, + column: 29, + }, + ), + custom: (), + node: Slice { + lower: None, + upper: Some( + Located { + location: Location { + row: 85, + column: 28, + }, + end_location: Some( + Location { + row: 85, + column: 29, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + ), + step: None, + }, + }, + ctx: Load, + }, + }, + }, + }, + ), + body: [ + Located { + location: Location { + row: 86, + column: 8, + }, + end_location: Some( + Location { + row: 86, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 86, + column: 8, + }, + end_location: Some( + Location { + row: 86, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 86, + column: 12, + }, + end_location: Some( + Location { + row: 86, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 87, + column: 9, + }, + end_location: Some( + Location { + row: 87, + column: 15, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 87, + column: 10, + }, + end_location: Some( + Location { + row: 87, + column: 11, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 87, + column: 10, + }, + end_location: Some( + Location { + row: 87, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 87, + column: 13, + }, + end_location: Some( + Location { + row: 87, + column: 14, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 87, + column: 13, + }, + end_location: Some( + Location { + row: 87, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 88, + column: 8, + }, + end_location: Some( + Location { + row: 88, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 88, + column: 8, + }, + end_location: Some( + Location { + row: 88, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 88, + column: 12, + }, + end_location: Some( + Location { + row: 88, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 90, + column: 0, + }, + end_location: Some( + Location { + row: 94, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 90, + column: 6, + }, + end_location: Some( + Location { + row: 90, + column: 7, + }, + ), + custom: (), + node: Name { + id: "w", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 91, + column: 9, + }, + end_location: Some( + Location { + row: 91, + column: 19, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 91, + column: 10, + }, + end_location: Some( + Location { + row: 91, + column: 11, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "x", + ), + }, + }, + Located { + location: Location { + row: 91, + column: 13, + }, + end_location: Some( + Location { + row: 91, + column: 14, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "y", + ), + }, + }, + Located { + location: Location { + row: 91, + column: 16, + }, + end_location: Some( + Location { + row: 91, + column: 18, + }, + ), + custom: (), + node: MatchStar { + name: None, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 92, + column: 8, + }, + end_location: Some( + Location { + row: 92, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 92, + column: 8, + }, + end_location: Some( + Location { + row: 92, + column: 9, + }, + ), + custom: (), + node: Name { + id: "z", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 92, + column: 12, + }, + end_location: Some( + Location { + row: 92, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 94, + column: 0, + }, + end_location: Some( + Location { + row: 98, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 94, + column: 6, + }, + end_location: Some( + Location { + row: 94, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 95, + column: 9, + }, + end_location: Some( + Location { + row: 95, + column: 22, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 95, + column: 9, + }, + end_location: Some( + Location { + row: 95, + column: 22, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 95, + column: 9, + }, + end_location: Some( + Location { + row: 95, + column: 22, + }, + ), + custom: (), + node: UnaryOp { + op: USub, + operand: Located { + location: Location { + row: 95, + column: 9, + }, + end_location: Some( + Location { + row: 95, + column: 22, + }, + ), + custom: (), + node: Constant { + value: Float( + 0.25, + ), + kind: None, + }, + }, + }, + }, + op: Sub, + right: Located { + location: Location { + row: 95, + column: 9, + }, + end_location: Some( + Location { + row: 95, + column: 22, + }, + ), + custom: (), + node: Constant { + value: Complex { + real: 0.0, + imag: 1.75, + }, + kind: None, + }, + }, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 96, + column: 8, + }, + end_location: Some( + Location { + row: 96, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 96, + column: 8, + }, + end_location: Some( + Location { + row: 96, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 96, + column: 12, + }, + end_location: Some( + Location { + row: 96, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 98, + column: 0, + }, + end_location: Some( + Location { + row: 102, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 98, + column: 6, + }, + end_location: Some( + Location { + row: 98, + column: 10, + }, + ), + custom: (), + node: Tuple { + elts: [ + Located { + location: Location { + row: 98, + column: 7, + }, + end_location: Some( + Location { + row: 98, + column: 8, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + ], + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 99, + column: 9, + }, + end_location: Some( + Location { + row: 99, + column: 12, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 99, + column: 10, + }, + end_location: Some( + Location { + row: 99, + column: 11, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "y", + ), + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 100, + column: 8, + }, + end_location: Some( + Location { + row: 100, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 100, + column: 8, + }, + end_location: Some( + Location { + row: 100, + column: 9, + }, + ), + custom: (), + node: Name { + id: "z", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 100, + column: 12, + }, + end_location: Some( + Location { + row: 100, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 102, + column: 0, + }, + end_location: Some( + Location { + row: 106, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 102, + column: 6, + }, + end_location: Some( + Location { + row: 102, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 103, + column: 9, + }, + end_location: Some( + Location { + row: 103, + column: 16, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 103, + column: 9, + }, + end_location: Some( + Location { + row: 103, + column: 16, + }, + ), + custom: (), + node: Attribute { + value: Located { + location: Location { + row: 103, + column: 9, + }, + end_location: Some( + Location { + row: 103, + column: 14, + }, + ), + custom: (), + node: Attribute { + value: Located { + location: Location { + row: 103, + column: 9, + }, + end_location: Some( + Location { + row: 103, + column: 12, + }, + ), + custom: (), + node: Attribute { + value: Located { + location: Location { + row: 103, + column: 9, + }, + end_location: Some( + Location { + row: 103, + column: 10, + }, + ), + custom: (), + node: Name { + id: "A", + ctx: Load, + }, + }, + attr: "B", + ctx: Load, + }, + }, + attr: "C", + ctx: Load, + }, + }, + attr: "D", + ctx: Load, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 104, + column: 8, + }, + end_location: Some( + Location { + row: 104, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 104, + column: 8, + }, + end_location: Some( + Location { + row: 104, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 104, + column: 12, + }, + end_location: Some( + Location { + row: 104, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 106, + column: 0, + }, + end_location: Some( + Location { + row: 110, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 106, + column: 6, + }, + end_location: Some( + Location { + row: 106, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 107, + column: 9, + }, + end_location: Some( + Location { + row: 107, + column: 13, + }, + ), + custom: (), + node: MatchSingleton { + value: None, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 108, + column: 8, + }, + end_location: Some( + Location { + row: 108, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 108, + column: 8, + }, + end_location: Some( + Location { + row: 108, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 108, + column: 12, + }, + end_location: Some( + Location { + row: 108, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 110, + column: 0, + }, + end_location: Some( + Location { + row: 114, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 110, + column: 6, + }, + end_location: Some( + Location { + row: 110, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 111, + column: 9, + }, + end_location: Some( + Location { + row: 111, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 111, + column: 9, + }, + end_location: Some( + Location { + row: 111, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 112, + column: 8, + }, + end_location: Some( + Location { + row: 112, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 112, + column: 8, + }, + end_location: Some( + Location { + row: 112, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 112, + column: 12, + }, + end_location: Some( + Location { + row: 112, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 114, + column: 0, + }, + end_location: Some( + Location { + row: 118, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 114, + column: 6, + }, + end_location: Some( + Location { + row: 114, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 115, + column: 9, + }, + end_location: Some( + Location { + row: 115, + column: 14, + }, + ), + custom: (), + node: MatchSingleton { + value: Bool( + false, + ), + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 116, + column: 8, + }, + end_location: Some( + Location { + row: 116, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 116, + column: 8, + }, + end_location: Some( + Location { + row: 116, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 116, + column: 12, + }, + end_location: Some( + Location { + row: 116, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 118, + column: 0, + }, + end_location: Some( + Location { + row: 126, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 118, + column: 6, + }, + end_location: Some( + Location { + row: 118, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 119, + column: 9, + }, + end_location: Some( + Location { + row: 119, + column: 11, + }, + ), + custom: (), + node: MatchSequence { + patterns: [], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 120, + column: 8, + }, + end_location: Some( + Location { + row: 120, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 120, + column: 8, + }, + end_location: Some( + Location { + row: 120, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 120, + column: 12, + }, + end_location: Some( + Location { + row: 120, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 121, + column: 9, + }, + end_location: Some( + Location { + row: 121, + column: 13, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 121, + column: 10, + }, + end_location: Some( + Location { + row: 121, + column: 12, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 121, + column: 10, + }, + end_location: Some( + Location { + row: 121, + column: 12, + }, + ), + custom: (), + node: Constant { + value: Str( + "", + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 122, + column: 8, + }, + end_location: Some( + Location { + row: 122, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 122, + column: 8, + }, + end_location: Some( + Location { + row: 122, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 122, + column: 12, + }, + end_location: Some( + Location { + row: 122, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 123, + column: 9, + }, + end_location: Some( + Location { + row: 123, + column: 11, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 123, + column: 9, + }, + end_location: Some( + Location { + row: 123, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Str( + "", + ), + kind: None, + }, + }, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 124, + column: 8, + }, + end_location: Some( + Location { + row: 124, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 124, + column: 8, + }, + end_location: Some( + Location { + row: 124, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 124, + column: 12, + }, + end_location: Some( + Location { + row: 124, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 126, + column: 0, + }, + end_location: Some( + Location { + row: 130, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 126, + column: 6, + }, + end_location: Some( + Location { + row: 126, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 127, + column: 9, + }, + end_location: Some( + Location { + row: 127, + column: 10, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "z", + ), + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 128, + column: 8, + }, + end_location: Some( + Location { + row: 128, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 128, + column: 8, + }, + end_location: Some( + Location { + row: 128, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 128, + column: 12, + }, + end_location: Some( + Location { + row: 128, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 130, + column: 0, + }, + end_location: Some( + Location { + row: 134, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 130, + column: 6, + }, + end_location: Some( + Location { + row: 130, + column: 7, + }, + ), + custom: (), + node: Name { + id: "w", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 131, + column: 9, + }, + end_location: Some( + Location { + row: 131, + column: 22, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 131, + column: 10, + }, + end_location: Some( + Location { + row: 131, + column: 11, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "x", + ), + }, + }, + Located { + location: Location { + row: 131, + column: 13, + }, + end_location: Some( + Location { + row: 131, + column: 14, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "y", + ), + }, + }, + Located { + location: Location { + row: 131, + column: 16, + }, + end_location: Some( + Location { + row: 131, + column: 21, + }, + ), + custom: (), + node: MatchStar { + name: Some( + "rest", + ), + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 132, + column: 8, + }, + end_location: Some( + Location { + row: 132, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 132, + column: 8, + }, + end_location: Some( + Location { + row: 132, + column: 9, + }, + ), + custom: (), + node: Name { + id: "z", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 132, + column: 12, + }, + end_location: Some( + Location { + row: 132, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 134, + column: 0, + }, + end_location: Some( + Location { + row: 138, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 134, + column: 6, + }, + end_location: Some( + Location { + row: 134, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 135, + column: 9, + }, + end_location: Some( + Location { + row: 135, + column: 39, + }, + ), + custom: (), + node: MatchOr { + patterns: [ + Located { + location: Location { + row: 135, + column: 9, + }, + end_location: Some( + Location { + row: 135, + column: 17, + }, + ), + custom: (), + node: MatchAs { + pattern: Some( + Located { + location: Location { + row: 135, + column: 10, + }, + end_location: Some( + Location { + row: 135, + column: 11, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 135, + column: 10, + }, + end_location: Some( + Location { + row: 135, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + ), + name: Some( + "z", + ), + }, + }, + Located { + location: Location { + row: 135, + column: 20, + }, + end_location: Some( + Location { + row: 135, + column: 28, + }, + ), + custom: (), + node: MatchAs { + pattern: Some( + Located { + location: Location { + row: 135, + column: 21, + }, + end_location: Some( + Location { + row: 135, + column: 22, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 135, + column: 21, + }, + end_location: Some( + Location { + row: 135, + column: 22, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + ), + name: Some( + "z", + ), + }, + }, + Located { + location: Location { + row: 135, + column: 31, + }, + end_location: Some( + Location { + row: 135, + column: 39, + }, + ), + custom: (), + node: MatchAs { + pattern: Some( + Located { + location: Location { + row: 135, + column: 32, + }, + end_location: Some( + Location { + row: 135, + column: 33, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 135, + column: 32, + }, + end_location: Some( + Location { + row: 135, + column: 33, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + ), + name: Some( + "z", + ), + }, + }, + ], + }, + }, + guard: Some( + Located { + location: Location { + row: 135, + column: 43, + }, + end_location: Some( + Location { + row: 135, + column: 53, + }, + ), + custom: (), + node: Compare { + left: Located { + location: Location { + row: 135, + column: 43, + }, + end_location: Some( + Location { + row: 135, + column: 44, + }, + ), + custom: (), + node: Name { + id: "z", + ctx: Load, + }, + }, + ops: [ + Eq, + ], + comparators: [ + Located { + location: Location { + row: 135, + column: 48, + }, + end_location: Some( + Location { + row: 135, + column: 53, + }, + ), + custom: (), + node: BinOp { + left: Located { + location: Location { + row: 135, + column: 48, + }, + end_location: Some( + Location { + row: 135, + column: 49, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + op: Mod, + right: Located { + location: Location { + row: 135, + column: 52, + }, + end_location: Some( + Location { + row: 135, + column: 53, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + ), + body: [ + Located { + location: Location { + row: 136, + column: 8, + }, + end_location: Some( + Location { + row: 136, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 136, + column: 8, + }, + end_location: Some( + Location { + row: 136, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 136, + column: 12, + }, + end_location: Some( + Location { + row: 136, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 138, + column: 0, + }, + end_location: Some( + Location { + row: 146, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 138, + column: 6, + }, + end_location: Some( + Location { + row: 138, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 139, + column: 9, + }, + end_location: Some( + Location { + row: 139, + column: 24, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 139, + column: 10, + }, + end_location: Some( + Location { + row: 139, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 139, + column: 13, + }, + end_location: Some( + Location { + row: 139, + column: 23, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 139, + column: 14, + }, + end_location: Some( + Location { + row: 139, + column: 15, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 139, + column: 14, + }, + end_location: Some( + Location { + row: 139, + column: 15, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 139, + column: 17, + }, + end_location: Some( + Location { + row: 139, + column: 18, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 139, + column: 17, + }, + end_location: Some( + Location { + row: 139, + column: 18, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 139, + column: 20, + }, + end_location: Some( + Location { + row: 139, + column: 22, + }, + ), + custom: (), + node: MatchMapping { + keys: [], + patterns: [], + rest: None, + }, + }, + ], + }, + }, + ], + rest: None, + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 140, + column: 8, + }, + end_location: Some( + Location { + row: 140, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 140, + column: 8, + }, + end_location: Some( + Location { + row: 140, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 140, + column: 12, + }, + end_location: Some( + Location { + row: 140, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 141, + column: 9, + }, + end_location: Some( + Location { + row: 141, + column: 78, + }, + ), + custom: (), + node: MatchOr { + patterns: [ + Located { + location: Location { + row: 141, + column: 9, + }, + end_location: Some( + Location { + row: 141, + column: 32, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 141, + column: 10, + }, + end_location: Some( + Location { + row: 141, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 141, + column: 13, + }, + end_location: Some( + Location { + row: 141, + column: 31, + }, + ), + custom: (), + node: MatchOr { + patterns: [ + Located { + location: Location { + row: 141, + column: 13, + }, + end_location: Some( + Location { + row: 141, + column: 23, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 141, + column: 14, + }, + end_location: Some( + Location { + row: 141, + column: 15, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 141, + column: 14, + }, + end_location: Some( + Location { + row: 141, + column: 15, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 141, + column: 17, + }, + end_location: Some( + Location { + row: 141, + column: 18, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 141, + column: 17, + }, + end_location: Some( + Location { + row: 141, + column: 18, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 141, + column: 20, + }, + end_location: Some( + Location { + row: 141, + column: 22, + }, + ), + custom: (), + node: MatchMapping { + keys: [], + patterns: [], + rest: None, + }, + }, + ], + }, + }, + Located { + location: Location { + row: 141, + column: 26, + }, + end_location: Some( + Location { + row: 141, + column: 31, + }, + ), + custom: (), + node: MatchSingleton { + value: Bool( + false, + ), + }, + }, + ], + }, + }, + ], + rest: None, + }, + }, + Located { + location: Location { + row: 141, + column: 35, + }, + end_location: Some( + Location { + row: 141, + column: 44, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 141, + column: 36, + }, + end_location: Some( + Location { + row: 141, + column: 37, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 141, + column: 39, + }, + end_location: Some( + Location { + row: 141, + column: 43, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 141, + column: 40, + }, + end_location: Some( + Location { + row: 141, + column: 42, + }, + ), + custom: (), + node: MatchSequence { + patterns: [], + }, + }, + ], + }, + }, + ], + rest: None, + }, + }, + Located { + location: Location { + row: 141, + column: 47, + }, + end_location: Some( + Location { + row: 141, + column: 62, + }, + ), + custom: (), + node: MatchMapping { + keys: [ + Located { + location: Location { + row: 141, + column: 48, + }, + end_location: Some( + Location { + row: 141, + column: 49, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + ], + patterns: [ + Located { + location: Location { + row: 141, + column: 51, + }, + end_location: Some( + Location { + row: 141, + column: 61, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 141, + column: 52, + }, + end_location: Some( + Location { + row: 141, + column: 53, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 141, + column: 52, + }, + end_location: Some( + Location { + row: 141, + column: 53, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 141, + column: 55, + }, + end_location: Some( + Location { + row: 141, + column: 56, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 141, + column: 55, + }, + end_location: Some( + Location { + row: 141, + column: 56, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 141, + column: 58, + }, + end_location: Some( + Location { + row: 141, + column: 60, + }, + ), + custom: (), + node: MatchMapping { + keys: [], + patterns: [], + rest: None, + }, + }, + ], + }, + }, + ], + rest: None, + }, + }, + Located { + location: Location { + row: 141, + column: 65, + }, + end_location: Some( + Location { + row: 141, + column: 67, + }, + ), + custom: (), + node: MatchSequence { + patterns: [], + }, + }, + Located { + location: Location { + row: 141, + column: 70, + }, + end_location: Some( + Location { + row: 141, + column: 73, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 141, + column: 70, + }, + end_location: Some( + Location { + row: 141, + column: 73, + }, + ), + custom: (), + node: Constant { + value: Str( + "X", + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 141, + column: 76, + }, + end_location: Some( + Location { + row: 141, + column: 78, + }, + ), + custom: (), + node: MatchMapping { + keys: [], + patterns: [], + rest: None, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 142, + column: 8, + }, + end_location: Some( + Location { + row: 142, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 142, + column: 8, + }, + end_location: Some( + Location { + row: 142, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 142, + column: 12, + }, + end_location: Some( + Location { + row: 142, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + MatchCase { + pattern: Located { + location: Location { + row: 143, + column: 9, + }, + end_location: Some( + Location { + row: 143, + column: 11, + }, + ), + custom: (), + node: MatchSequence { + patterns: [], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 144, + column: 8, + }, + end_location: Some( + Location { + row: 144, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 144, + column: 8, + }, + end_location: Some( + Location { + row: 144, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 144, + column: 12, + }, + end_location: Some( + Location { + row: 144, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 146, + column: 0, + }, + end_location: Some( + Location { + row: 150, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 146, + column: 6, + }, + end_location: Some( + Location { + row: 146, + column: 15, + }, + ), + custom: (), + node: Tuple { + elts: [ + Located { + location: Location { + row: 146, + column: 7, + }, + end_location: Some( + Location { + row: 146, + column: 8, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + Located { + location: Location { + row: 146, + column: 10, + }, + end_location: Some( + Location { + row: 146, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + Located { + location: Location { + row: 146, + column: 13, + }, + end_location: Some( + Location { + row: 146, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + ], + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 147, + column: 9, + }, + end_location: Some( + Location { + row: 147, + column: 14, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 147, + column: 9, + }, + end_location: Some( + Location { + row: 147, + column: 10, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 147, + column: 9, + }, + end_location: Some( + Location { + row: 147, + column: 10, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + }, + }, + Located { + location: Location { + row: 147, + column: 12, + }, + end_location: Some( + Location { + row: 147, + column: 14, + }, + ), + custom: (), + node: MatchStar { + name: Some( + "x", + ), + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 148, + column: 8, + }, + end_location: Some( + Location { + row: 148, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 148, + column: 8, + }, + end_location: Some( + Location { + row: 148, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 148, + column: 12, + }, + end_location: Some( + Location { + row: 148, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 150, + column: 0, + }, + end_location: Some( + Location { + row: 154, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 150, + column: 6, + }, + end_location: Some( + Location { + row: 150, + column: 15, + }, + ), + custom: (), + node: Tuple { + elts: [ + Located { + location: Location { + row: 150, + column: 7, + }, + end_location: Some( + Location { + row: 150, + column: 8, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + Located { + location: Location { + row: 150, + column: 10, + }, + end_location: Some( + Location { + row: 150, + column: 11, + }, + ), + custom: (), + node: Constant { + value: Int( + 1, + ), + kind: None, + }, + }, + Located { + location: Location { + row: 150, + column: 13, + }, + end_location: Some( + Location { + row: 150, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + ], + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 151, + column: 9, + }, + end_location: Some( + Location { + row: 151, + column: 15, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 151, + column: 9, + }, + end_location: Some( + Location { + row: 151, + column: 11, + }, + ), + custom: (), + node: MatchStar { + name: Some( + "x", + ), + }, + }, + Located { + location: Location { + row: 151, + column: 13, + }, + end_location: Some( + Location { + row: 151, + column: 14, + }, + ), + custom: (), + node: MatchValue { + value: Located { + location: Location { + row: 151, + column: 13, + }, + end_location: Some( + Location { + row: 151, + column: 14, + }, + ), + custom: (), + node: Constant { + value: Int( + 2, + ), + kind: None, + }, + }, + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 152, + column: 8, + }, + end_location: Some( + Location { + row: 152, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 152, + column: 8, + }, + end_location: Some( + Location { + row: 152, + column: 9, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 152, + column: 12, + }, + end_location: Some( + Location { + row: 152, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 154, + column: 0, + }, + end_location: Some( + Location { + row: 158, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 154, + column: 6, + }, + end_location: Some( + Location { + row: 154, + column: 7, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 155, + column: 9, + }, + end_location: Some( + Location { + row: 155, + column: 11, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 155, + column: 9, + }, + end_location: Some( + Location { + row: 155, + column: 10, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "y", + ), + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 156, + column: 8, + }, + end_location: Some( + Location { + row: 156, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 156, + column: 8, + }, + end_location: Some( + Location { + row: 156, + column: 9, + }, + ), + custom: (), + node: Name { + id: "z", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 156, + column: 12, + }, + end_location: Some( + Location { + row: 156, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 158, + column: 0, + }, + end_location: Some( + Location { + row: 162, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 158, + column: 0, + }, + end_location: Some( + Location { + row: 162, + column: 0, + }, + ), + custom: (), + node: Tuple { + elts: [ + Located { + location: Location { + row: 158, + column: 6, + }, + end_location: Some( + Location { + row: 158, + column: 7, + }, + ), + custom: (), + node: Name { + id: "w", + ctx: Load, + }, + }, + Located { + location: Location { + row: 158, + column: 9, + }, + end_location: Some( + Location { + row: 158, + column: 10, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + ], + ctx: Load, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 159, + column: 9, + }, + end_location: Some( + Location { + row: 159, + column: 13, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 159, + column: 9, + }, + end_location: Some( + Location { + row: 159, + column: 10, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "y", + ), + }, + }, + Located { + location: Location { + row: 159, + column: 12, + }, + end_location: Some( + Location { + row: 159, + column: 13, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "z", + ), + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 160, + column: 8, + }, + end_location: Some( + Location { + row: 160, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 160, + column: 8, + }, + end_location: Some( + Location { + row: 160, + column: 9, + }, + ), + custom: (), + node: Name { + id: "v", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 160, + column: 12, + }, + end_location: Some( + Location { + row: 160, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, + Located { + location: Location { + row: 162, + column: 0, + }, + end_location: Some( + Location { + row: 165, + column: 0, + }, + ), + custom: (), + node: Match { + subject: Located { + location: Location { + row: 162, + column: 6, + }, + end_location: Some( + Location { + row: 162, + column: 12, + }, + ), + custom: (), + node: NamedExpr { + target: Located { + location: Location { + row: 162, + column: 6, + }, + end_location: Some( + Location { + row: 162, + column: 7, + }, + ), + custom: (), + node: Name { + id: "w", + ctx: Store, + }, + }, + value: Located { + location: Location { + row: 162, + column: 11, + }, + end_location: Some( + Location { + row: 162, + column: 12, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + }, + }, + cases: [ + MatchCase { + pattern: Located { + location: Location { + row: 163, + column: 9, + }, + end_location: Some( + Location { + row: 163, + column: 16, + }, + ), + custom: (), + node: MatchSequence { + patterns: [ + Located { + location: Location { + row: 163, + column: 9, + }, + end_location: Some( + Location { + row: 163, + column: 15, + }, + ), + custom: (), + node: MatchAs { + pattern: Some( + Located { + location: Location { + row: 163, + column: 9, + }, + end_location: Some( + Location { + row: 163, + column: 10, + }, + ), + custom: (), + node: MatchAs { + pattern: None, + name: Some( + "y", + ), + }, + }, + ), + name: Some( + "v", + ), + }, + }, + ], + }, + }, + guard: None, + body: [ + Located { + location: Location { + row: 164, + column: 8, + }, + end_location: Some( + Location { + row: 164, + column: 13, + }, + ), + custom: (), + node: Assign { + targets: [ + Located { + location: Location { + row: 164, + column: 8, + }, + end_location: Some( + Location { + row: 164, + column: 9, + }, + ), + custom: (), + node: Name { + id: "z", + ctx: Store, + }, + }, + ], + value: Located { + location: Location { + row: 164, + column: 12, + }, + end_location: Some( + Location { + row: 164, + column: 13, + }, + ), + custom: (), + node: Constant { + value: Int( + 0, + ), + kind: None, + }, + }, + type_comment: None, + }, + }, + ], + }, + ], + }, + }, +] diff --git a/parser/src/soft_keywords.rs b/parser/src/soft_keywords.rs new file mode 100644 index 0000000..a425625 --- /dev/null +++ b/parser/src/soft_keywords.rs @@ -0,0 +1,112 @@ +use itertools::{Itertools, MultiPeek}; + +use crate::lexer::{LexResult, Tok}; +pub use crate::mode::Mode; + +/// An [`Iterator`] that transforms a token stream to accommodate soft keywords (namely, `match` +/// and `case`). +/// +/// [PEP 634](https://www.python.org/dev/peps/pep-0634/) introduced the `match` and `case` keywords +/// as soft keywords, meaning that they can be used as identifiers (e.g., variable names) in certain +/// contexts. +/// +/// This function modifies a token stream to accommodate this change. In particular, it replaces +/// `match` and `case` tokens with `identifier` tokens if they are used as identifiers. +/// +/// Handling soft keywords in this intermediary pass allows us to simplify both the lexer and +/// parser, as neither of them need to be aware of soft keywords. +pub struct SoftKeywordTransformer +where + I: Iterator, +{ + pub underlying: MultiPeek, + pub start_of_line: bool, +} + +impl SoftKeywordTransformer +where + I: Iterator, +{ + pub fn new(tokenizer: I, mode: Mode) -> Self { + Self { + underlying: tokenizer.multipeek(), + start_of_line: matches!(mode, Mode::Interactive | Mode::Module), + } + } +} + +impl Iterator for SoftKeywordTransformer +where + I: Iterator, +{ + type Item = LexResult; + + #[inline] + fn next(&mut self) -> Option { + let mut next = self.underlying.next(); + if let Some(Ok((start, tok, end))) = next.as_ref() { + // If the token is a `match` or `case` token, check if it's used as an identifier. + // We assume every `match` or `case` is an identifier unless both of the following + // conditions are met: + // 1. The token is at the start of a logical line. + // 2. The logical line contains a top-level colon (that is, a colon that is not nested + // inside a parenthesized expression, list, or dictionary). + // 3. The top-level colon is not the immediate sibling of a `match` or `case` token. + // (This is to avoid treating `match` and `case` as identifiers when annotated with + // type hints.) + if matches!(tok, Tok::Match | Tok::Case) { + if !self.start_of_line { + next = Some(Ok((*start, soft_to_name(tok), *end))); + } else { + let mut nesting = 0; + let mut first = true; + let mut seen_colon = false; + while let Some(Ok((_, tok, _))) = self.underlying.peek() { + match tok { + Tok::Newline => break, + Tok::Colon if nesting == 0 => { + if !first { + seen_colon = true; + } + } + Tok::Lpar | Tok::Lsqb | Tok::Lbrace => nesting += 1, + Tok::Rpar | Tok::Rsqb | Tok::Rbrace => nesting -= 1, + _ => {} + } + first = false; + } + if !seen_colon { + next = Some(Ok((*start, soft_to_name(tok), *end))); + } + } + } + } + + self.start_of_line = next.as_ref().map_or(false, |lex_result| { + lex_result.as_ref().map_or(false, |(_, tok, _)| { + matches!( + tok, + Tok::StartModule + | Tok::StartInteractive + | Tok::Newline + | Tok::Indent + | Tok::Dedent + ) + }) + }); + + next + } +} + +#[inline] +fn soft_to_name(tok: &Tok) -> Tok { + let name = match tok { + Tok::Match => "match", + Tok::Case => "case", + _ => unreachable!("other tokens never reach here"), + }; + Tok::Name { + name: name.to_owned(), + } +} diff --git a/parser/src/token.rs b/parser/src/token.rs index 3fa6ff1..42b0991 100644 --- a/parser/src/token.rs +++ b/parser/src/token.rs @@ -184,6 +184,8 @@ pub enum Tok { Return, Try, While, + Match, + Case, With, Yield, @@ -297,6 +299,8 @@ impl fmt::Display for Tok { Return => f.write_str("'return'"), Try => f.write_str("'try'"), While => f.write_str("'while'"), + Match => f.write_str("'match'"), + Case => f.write_str("'case'"), With => f.write_str("'with'"), Yield => f.write_str("'yield'"), ColonEqual => f.write_str("':='"),