Rename unconventional nodes (#74)

This commit is contained in:
Jeong, YunWon 2023-06-17 01:54:00 +09:00 committed by GitHub
parent 5270020423
commit 69d27d924c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 2407 additions and 2302 deletions

View file

@ -509,7 +509,7 @@ ConstantExpr: ast::Expr = {
ConstantAtom,
<location:@L> "-" <operand:ConstantAtom> <end_location:@R> => ast::Expr::UnaryOp(
ast::ExprUnaryOp {
op: ast::Unaryop::USub,
op: ast::UnaryOp::USub,
operand: Box::new(operand),
range: (location..end_location).into()
}
@ -875,11 +875,11 @@ TryStatement: ast::Stmt = {
},
};
ExceptStarClause: ast::Excepthandler = {
ExceptStarClause: ast::ExceptHandler = {
<location:@L> "except" "*" <typ:Test<"all">> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::Excepthandler::ExceptHandler(
ast::ExcepthandlerExceptHandler {
ast::ExceptHandler::ExceptHandler(
ast::ExceptHandlerExceptHandler {
type_: Some(Box::new(typ)),
name: None,
body,
@ -889,8 +889,8 @@ ExceptStarClause: ast::Excepthandler = {
},
<location:@L> "except" "*" <x:(<Test<"all">> "as" <Identifier>)> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::Excepthandler::ExceptHandler(
ast::ExcepthandlerExceptHandler {
ast::ExceptHandler::ExceptHandler(
ast::ExceptHandlerExceptHandler {
type_: Some(Box::new(x.0)),
name: Some(x.1),
body,
@ -901,11 +901,11 @@ ExceptStarClause: ast::Excepthandler = {
};
ExceptClause: ast::Excepthandler = {
ExceptClause: ast::ExceptHandler = {
<location:@L> "except" <typ:Test<"all">?> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::Excepthandler::ExceptHandler(
ast::ExcepthandlerExceptHandler {
ast::ExceptHandler::ExceptHandler(
ast::ExceptHandlerExceptHandler {
type_: typ.map(Box::new),
name: None,
body,
@ -915,8 +915,8 @@ ExceptClause: ast::Excepthandler = {
},
<location:@L> "except" <x:(<Test<"all">> "as" <Identifier>)> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::Excepthandler::ExceptHandler(
ast::ExcepthandlerExceptHandler {
ast::ExceptHandler::ExceptHandler(
ast::ExceptHandlerExceptHandler {
type_: Some(Box::new(x.0)),
name: Some(x.1),
body,
@ -938,7 +938,7 @@ WithStatement: ast::Stmt = {
},
};
WithItems: Vec<ast::Withitem> = {
WithItems: Vec<ast::WithItem> = {
"(" <WithItemsNoAs> ","? ")",
"(" <left:(<WithItemsNoAs> ",")?> <mid:WithItem<"as">> <right:("," <WithItem<"all">>)*> ","? ")" => {
left.into_iter().flatten().chain([mid]).chain(right).collect()
@ -950,17 +950,17 @@ WithItems: Vec<ast::Withitem> = {
};
#[inline]
WithItemsNoAs: Vec<ast::Withitem> = {
WithItemsNoAs: Vec<ast::WithItem> = {
<location:@L> <all:OneOrMore<Test<"all">>> <end_location:@R> => {
all.into_iter().map(|context_expr| ast::Withitem { context_expr, optional_vars: None, range: optional_range(location, end_location) }).collect()
all.into_iter().map(|context_expr| ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) }).collect()
},
}
WithItem<Goal>: ast::Withitem = {
<location:@L> <context_expr: Test<Goal>> <end_location:@R> if Goal != "as" => ast::Withitem { context_expr, optional_vars: None, range: optional_range(location, end_location) },
WithItem<Goal>: ast::WithItem = {
<location:@L> <context_expr: Test<Goal>> <end_location:@R> if Goal != "as" => ast::WithItem { context_expr, optional_vars: None, range: optional_range(location, end_location) },
<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: optional_range(location, end_location) }
ast::WithItem { context_expr, optional_vars, range: optional_range(location, end_location) }
},
};
@ -1212,7 +1212,7 @@ OrTest<Goal>: ast::Expr = {
<location:@L> <mut values:(<AndTest<"all">> "or")+> <last: AndTest<"all">> <end_location:@R> => {
values.push(last);
ast::Expr::BoolOp(
ast::ExprBoolOp { op: ast::Boolop::Or, values, range: (location..end_location).into() }
ast::ExprBoolOp { op: ast::BoolOp::Or, values, range: (location..end_location).into() }
)
},
AndTest<Goal>,
@ -1222,7 +1222,7 @@ AndTest<Goal>: ast::Expr = {
<location:@L> <mut values:(<NotTest<"all">> "and")+> <last:NotTest<"all">> <end_location:@R> => {
values.push(last);
ast::Expr::BoolOp(
ast::ExprBoolOp { op: ast::Boolop::And, values, range: (location..end_location).into() }
ast::ExprBoolOp { op: ast::BoolOp::And, values, range: (location..end_location).into() }
)
},
NotTest<Goal>,
@ -1230,7 +1230,7 @@ AndTest<Goal>: ast::Expr = {
NotTest<Goal>: ast::Expr = {
<location:@L> "not" <e:NotTest<"all">> <end_location:@R> => ast::Expr::UnaryOp(
ast::ExprUnaryOp { operand: Box::new(e), op: ast::Unaryop::Not, range: (location..end_location).into() }
ast::ExprUnaryOp { operand: Box::new(e), op: ast::UnaryOp::Not, range: (location..end_location).into() }
),
Comparison<Goal>,
};
@ -1245,17 +1245,17 @@ Comparison<Goal>: ast::Expr = {
Expression<Goal>,
};
CompOp: ast::Cmpop = {
"==" => ast::Cmpop::Eq,
"!=" => ast::Cmpop::NotEq,
"<" => ast::Cmpop::Lt,
"<=" => ast::Cmpop::LtE,
">" => ast::Cmpop::Gt,
">=" => ast::Cmpop::GtE,
"in" => ast::Cmpop::In,
"not" "in" => ast::Cmpop::NotIn,
"is" => ast::Cmpop::Is,
"is" "not" => ast::Cmpop::IsNot,
CompOp: ast::CmpOp = {
"==" => ast::CmpOp::Eq,
"!=" => ast::CmpOp::NotEq,
"<" => ast::CmpOp::Lt,
"<=" => ast::CmpOp::LtE,
">" => ast::CmpOp::Gt,
">=" => ast::CmpOp::GtE,
"in" => ast::CmpOp::In,
"not" "in" => ast::CmpOp::NotIn,
"is" => ast::CmpOp::Is,
"is" "not" => ast::CmpOp::IsNot,
};
Expression<Goal>: ast::Expr = {
@ -1325,10 +1325,10 @@ Factor<Goal>: ast::Expr = {
Power<Goal>,
};
UnaryOp: ast::Unaryop = {
"+" => ast::Unaryop::UAdd,
"-" => ast::Unaryop::USub,
"~" => ast::Unaryop::Invert,
UnaryOp: ast::UnaryOp = {
"+" => ast::UnaryOp::UAdd,
"-" => ast::UnaryOp::USub,
"~" => ast::UnaryOp::Invert,
};
Power<Goal>: ast::Expr = {

484
parser/src/python.rs generated

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,7 @@ expression: parse_ast
StmtWith {
range: 0..17,
items: [
Withitem {
WithItem {
range: 5..11,
context_expr: Constant(
ExprConstant {

View file

@ -44,7 +44,7 @@ expression: parse_ast
],
handlers: [
ExceptHandler(
ExcepthandlerExceptHandler {
ExceptHandlerExceptHandler {
range: 29..82,
type_: Some(
Name(
@ -138,7 +138,7 @@ expression: parse_ast
},
),
ExceptHandler(
ExcepthandlerExceptHandler {
ExceptHandlerExceptHandler {
range: 83..134,
type_: Some(
Name(

View file

@ -156,7 +156,7 @@ expression: parse_ast
],
handlers: [
ExceptHandler(
ExcepthandlerExceptHandler {
ExceptHandlerExceptHandler {
range: 99..180,
type_: Some(
Name(
@ -284,7 +284,7 @@ expression: parse_ast
},
),
ExceptHandler(
ExcepthandlerExceptHandler {
ExceptHandlerExceptHandler {
range: 181..260,
type_: Some(
Name(

View file

@ -1,13 +1,13 @@
---
source: parser/src/parser.rs
expression: "parse_program(source, \"<test>\").unwrap()"
expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
---
[
With(
StmtWith {
range: 0..12,
items: [
Withitem {
WithItem {
range: 5..6,
context_expr: Constant(
ExprConstant {
@ -35,7 +35,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 13..30,
items: [
Withitem {
WithItem {
range: 18..24,
context_expr: Constant(
ExprConstant {
@ -73,7 +73,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 31..46,
items: [
Withitem {
WithItem {
range: 36..37,
context_expr: Constant(
ExprConstant {
@ -86,7 +86,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
),
optional_vars: None,
},
Withitem {
WithItem {
range: 39..40,
context_expr: Constant(
ExprConstant {
@ -114,7 +114,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 47..72,
items: [
Withitem {
WithItem {
range: 52..58,
context_expr: Constant(
ExprConstant {
@ -137,7 +137,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
),
),
},
Withitem {
WithItem {
range: 60..66,
context_expr: Constant(
ExprConstant {
@ -175,7 +175,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 73..97,
items: [
Withitem {
WithItem {
range: 78..91,
context_expr: IfExp(
ExprIfExp {
@ -226,7 +226,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 98..127,
items: [
Withitem {
WithItem {
range: 103..121,
context_expr: IfExp(
ExprIfExp {
@ -287,7 +287,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 128..141,
items: [
Withitem {
WithItem {
range: 133..135,
context_expr: Tuple(
ExprTuple {
@ -313,7 +313,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 142..160,
items: [
Withitem {
WithItem {
range: 147..154,
context_expr: Tuple(
ExprTuple {
@ -349,7 +349,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 161..175,
items: [
Withitem {
WithItem {
range: 167..168,
context_expr: Constant(
ExprConstant {
@ -377,7 +377,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 176..195,
items: [
Withitem {
WithItem {
range: 181..189,
context_expr: Constant(
ExprConstant {
@ -415,7 +415,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 196..211,
items: [
Withitem {
WithItem {
range: 202..203,
context_expr: Constant(
ExprConstant {
@ -443,7 +443,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 212..232,
items: [
Withitem {
WithItem {
range: 217..226,
context_expr: Tuple(
ExprTuple {
@ -489,7 +489,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 233..250,
items: [
Withitem {
WithItem {
range: 239..243,
context_expr: Constant(
ExprConstant {
@ -502,7 +502,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
),
optional_vars: None,
},
Withitem {
WithItem {
range: 239..243,
context_expr: Constant(
ExprConstant {
@ -530,7 +530,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 251..273,
items: [
Withitem {
WithItem {
range: 256..267,
context_expr: Tuple(
ExprTuple {
@ -585,7 +585,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 274..290,
items: [
Withitem {
WithItem {
range: 279..284,
context_expr: Tuple(
ExprTuple {
@ -627,7 +627,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 291..312,
items: [
Withitem {
WithItem {
range: 296..306,
context_expr: Tuple(
ExprTuple {
@ -679,7 +679,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 313..331,
items: [
Withitem {
WithItem {
range: 318..325,
context_expr: Tuple(
ExprTuple {
@ -730,7 +730,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 332..355,
items: [
Withitem {
WithItem {
range: 337..349,
context_expr: Tuple(
ExprTuple {
@ -791,7 +791,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 356..375,
items: [
Withitem {
WithItem {
range: 361..369,
context_expr: NamedExpr(
ExprNamedExpr {
@ -833,7 +833,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 376..400,
items: [
Withitem {
WithItem {
range: 381..394,
context_expr: NamedExpr(
ExprNamedExpr {
@ -885,7 +885,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 401..428,
items: [
Withitem {
WithItem {
range: 406..422,
context_expr: Tuple(
ExprTuple {
@ -958,7 +958,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 429..461,
items: [
Withitem {
WithItem {
range: 434..455,
context_expr: Tuple(
ExprTuple {
@ -1041,7 +1041,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 462..481,
items: [
Withitem {
WithItem {
range: 468..474,
context_expr: Constant(
ExprConstant {
@ -1079,7 +1079,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 482..502,
items: [
Withitem {
WithItem {
range: 488..494,
context_expr: Constant(
ExprConstant {
@ -1117,7 +1117,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 503..530,
items: [
Withitem {
WithItem {
range: 509..515,
context_expr: Constant(
ExprConstant {
@ -1140,7 +1140,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
),
),
},
Withitem {
WithItem {
range: 517..523,
context_expr: Constant(
ExprConstant {
@ -1178,7 +1178,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
StmtWith {
range: 531..559,
items: [
Withitem {
WithItem {
range: 537..543,
context_expr: Constant(
ExprConstant {
@ -1201,7 +1201,7 @@ expression: "parse_program(source, \"<test>\").unwrap()"
),
),
},
Withitem {
WithItem {
range: 545..551,
context_expr: Constant(
ExprConstant {