Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit cfe0efc

Browse files
authored
Include argument parentheses in range (#5)
1 parent 7a3eedb commit cfe0efc

5 files changed

+118
-6
lines changed

parser/src/function.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ mod tests {
157157
use super::*;
158158
use crate::{ast, parser::ParseErrorType, Parse};
159159

160-
#[cfg(not(feature = "all-nodes-with-ranges"))]
161160
macro_rules! function_and_lambda {
162161
($($name:ident: $code:expr,)*) => {
163162
$(
@@ -170,6 +169,12 @@ mod tests {
170169
}
171170
}
172171

172+
#[cfg(feature = "all-nodes-with-ranges")]
173+
function_and_lambda! {
174+
test_function_no_args_with_ranges: "def f(): pass",
175+
test_function_pos_args_with_ranges: "def f(a, b, c): pass",
176+
}
177+
173178
#[cfg(not(feature = "all-nodes-with-ranges"))]
174179
function_and_lambda! {
175180
test_function_no_args: "def f(): pass",

parser/src/python.lalrpop

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,15 +981,20 @@ FuncDef: ast::Stmt = {
981981

982982
Parameters: ast::Arguments = {
983983
<location:@L> "(" <a: (ParameterList<TypedParameter, StarTypedParameter>)?> ")" <end_location:@R> =>? {
984-
let args = a.map(validate_arguments).transpose()?.unwrap_or_else(|| ast::Arguments {
984+
let range = optional_range(location, end_location);
985+
986+
let args = a.map(|mut arguments| {
987+
arguments.range = range;
988+
validate_arguments(arguments)
989+
}).transpose()?.unwrap_or_else(|| ast::Arguments {
985990
posonlyargs: vec![],
986991
args: vec![],
987992
vararg: None,
988993
kwonlyargs: vec![],
989994
kw_defaults: vec![],
990995
kwarg: None,
991996
defaults: vec![],
992-
range: optional_range(location, end_location)
997+
range
993998
});
994999

9951000
Ok(args)

parser/src/python.rs

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__function__tests__function_no_args_with_ranges.snap

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__function__tests__function_pos_args_with_ranges.snap

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)