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

Include argument parentheses in range #5

Merged
merged 1 commit into from
Jun 7, 2023
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
7 changes: 6 additions & 1 deletion parser/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ mod tests {
use super::*;
use crate::{ast, parser::ParseErrorType, Parse};

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

#[cfg(feature = "all-nodes-with-ranges")]
function_and_lambda! {
test_function_no_args_with_ranges: "def f(): pass",
test_function_pos_args_with_ranges: "def f(a, b, c): pass",
}

#[cfg(not(feature = "all-nodes-with-ranges"))]
function_and_lambda! {
test_function_no_args: "def f(): pass",
Expand Down
9 changes: 7 additions & 2 deletions parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -981,15 +981,20 @@ FuncDef: ast::Stmt = {

Parameters: ast::Arguments = {
<location:@L> "(" <a: (ParameterList<TypedParameter, StarTypedParameter>)?> ")" <end_location:@R> =>? {
let args = a.map(validate_arguments).transpose()?.unwrap_or_else(|| ast::Arguments {
let range = optional_range(location, end_location);

let args = a.map(|mut arguments| {
arguments.range = range;
validate_arguments(arguments)
}).transpose()?.unwrap_or_else(|| ast::Arguments {
posonlyargs: vec![],
args: vec![],
vararg: None,
kwonlyargs: vec![],
kw_defaults: vec![],
kwarg: None,
defaults: vec![],
range: optional_range(location, end_location)
range
});

Ok(args)
Expand Down
11 changes: 8 additions & 3 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.

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