Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ast/src/source_locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>);
Expand Down
3 changes: 2 additions & 1 deletion parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions parser/src/python.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading