mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-07 13:15:21 +00:00
Fix match parsing
This commit is contained in:
parent
e00297d1c7
commit
f07b97cef3
4 changed files with 34 additions and 4 deletions
|
@ -274,6 +274,34 @@ impl crate::fold::Fold<TextRange> for LinearLocator<'_> {
|
|||
keywords,
|
||||
})
|
||||
}
|
||||
|
||||
fn fold_pattern_match_mapping(
|
||||
&mut self,
|
||||
node: crate::PatternMatchMapping<TextRange>,
|
||||
) -> Result<crate::PatternMatchMapping<Self::TargetU>, Self::Error> {
|
||||
let crate::PatternMatchMapping {
|
||||
keys,
|
||||
patterns,
|
||||
rest,
|
||||
range,
|
||||
} = node;
|
||||
let context = self.will_map_user(&range);
|
||||
|
||||
let mut located_keys = Vec::with_capacity(keys.len());
|
||||
let mut located_patterns = Vec::with_capacity(patterns.len());
|
||||
for (key, value) in keys.into_iter().zip(patterns.into_iter()) {
|
||||
located_keys.push(self.fold(key)?);
|
||||
located_patterns.push(self.fold(value)?);
|
||||
}
|
||||
let rest = self.fold(rest)?;
|
||||
let range = self.map_user(range, context)?;
|
||||
Ok(crate::PatternMatchMapping {
|
||||
keys: located_keys,
|
||||
patterns: located_patterns,
|
||||
rest,
|
||||
range,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct LinearLookaheadLocator<'a, 'b>(&'b mut LinearLocator<'a>);
|
||||
|
|
|
@ -370,13 +370,14 @@ MatchStatement: ast::Stmt = {
|
|||
.last()
|
||||
.unwrap()
|
||||
.end();
|
||||
let subject_range = (subjects.first().unwrap().start()..subjects.last().unwrap().end()).into();
|
||||
ast::Stmt::Match(
|
||||
ast::StmtMatch {
|
||||
subject: Box::new(ast::Expr::Tuple(
|
||||
ast::ExprTuple {
|
||||
elts: subjects,
|
||||
ctx: ast::ExprContext::Load,
|
||||
range: (location..end_location).into()
|
||||
range: subject_range,
|
||||
},
|
||||
)),
|
||||
cases,
|
||||
|
|
5
parser/src/python.rs
generated
5
parser/src/python.rs
generated
|
@ -1,5 +1,5 @@
|
|||
// auto-generated: "lalrpop 0.20.0"
|
||||
// sha3: de5ffc51d44962eb297cbbf668fae33652eed69586405ebef2229fc02d183bc8
|
||||
// sha3: c2ba3f0f3de013733a18ba664f36f7f587254cc430656e553ceada96d33c409b
|
||||
use crate::{
|
||||
ast::{self as ast, Ranged, bigint::BigInt},
|
||||
lexer::{LexicalError, LexicalErrorType},
|
||||
|
@ -30842,13 +30842,14 @@ fn __action82<
|
|||
.last()
|
||||
.unwrap()
|
||||
.end();
|
||||
let subject_range = (subjects.first().unwrap().start()..subjects.last().unwrap().end()).into();
|
||||
ast::Stmt::Match(
|
||||
ast::StmtMatch {
|
||||
subject: Box::new(ast::Expr::Tuple(
|
||||
ast::ExprTuple {
|
||||
elts: subjects,
|
||||
ctx: ast::ExprContext::Load,
|
||||
range: (location..end_location).into()
|
||||
range: subject_range,
|
||||
},
|
||||
)),
|
||||
cases,
|
||||
|
|
|
@ -3783,7 +3783,7 @@ expression: parse_ast
|
|||
range: 2720..2760,
|
||||
subject: Tuple(
|
||||
ExprTuple {
|
||||
range: 2720..2760,
|
||||
range: 2726..2730,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue