Skip to content

Commit

Permalink
Rename parser goal 'All' to 'all' (#6867)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser authored Aug 25, 2023
1 parent 0b6dab5 commit 15b7525
Show file tree
Hide file tree
Showing 2 changed files with 14,493 additions and 19,611 deletions.
12 changes: 8 additions & 4 deletions crates/ruff_python_parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ IpyHelpEndEscapeCommandStatement: ast::Stmt = {
// We are permissive than the original implementation because we would allow whitespace
// between the expression and the suffix while the IPython implementation doesn't allow it.
// For example, `foo ?` would be valid in our case but invalid from IPython.
<location:@L> <e:Expression<"All">> <suffix:("?")+> <end_location:@R> =>? {
<location:@L> <e:Expression<"all">> <suffix:("?")+> <end_location:@R> =>? {
fn unparse_expr(expr: &ast::Expr, buffer: &mut String) -> Result<(), LexicalError> {
match expr {
ast::Expr::Name(ast::ExprName { id, .. }) => {
Expand Down Expand Up @@ -1054,7 +1054,7 @@ WithStatement: ast::Stmt = {

WithItems: Vec<ast::WithItem> = {
"(" <WithItemsNoAs> ","? ")",
"(" <left:(<WithItemsNoAs> ",")?> <mid:WithItem<"as">> <right:("," <WithItem<"all">>)*> ","? ")" => {
"(" <left:(<WithItemsNoAs> ",")?> <mid:WithItemAs> <right:("," <WithItem<"all">>)*> ","? ")" => {
left.into_iter().flatten().chain([mid]).chain(right).collect()
},
<WithItem<"no-withitems">> => vec![<>],
Expand All @@ -1071,12 +1071,16 @@ WithItemsNoAs: Vec<ast::WithItem> = {
}

WithItem<Goal>: ast::WithItem = {
<location:@L> <context_expr: Test<Goal>> <end_location:@R> if Goal != "as" => ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() },
<location:@L> <context_expr: Test<Goal>> <end_location:@R> => ast::WithItem { context_expr, optional_vars: None, range: (location..end_location).into() },
<WithItemAs>,
};

WithItemAs: ast::WithItem = {
<location:@L> <context_expr:Test<"all">> "as" <vars:Expression<"all">> <end_location:@R> => {
let optional_vars = Some(Box::new(set_context(vars, ast::ExprContext::Store)));
ast::WithItem { context_expr, optional_vars, range: (location..end_location).into() }
},
};
}

FuncDef: ast::Stmt = {
<location:@L> <decorator_list:Decorator*> <is_async:"async"?> "def" <name:Identifier> <type_params:TypeParams?> <args:Parameters> <r:("->" <Test<"all">>)?> ":" <body:Suite> => {
Expand Down
Loading

0 comments on commit 15b7525

Please sign in to comment.