Skip to content

Commit 595aec1

Browse files
committed
chore: integrate bracket_map_access into the array
1 parent 4560edb commit 595aec1

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/query/ast/src/parser/expr.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,9 +1220,6 @@ pub fn expr_element(i: Input) -> IResult<WithSpan<ExprElement>> {
12201220
let variable_access = map(variable_ident, ExprElement::VariableAccess);
12211221

12221222
let unary_op = map(unary_op, |op| ExprElement::UnaryOp { op });
1223-
let bracket_map_access = map(map_access_bracket, |accessor| ExprElement::MapAccess {
1224-
accessor,
1225-
});
12261223
let dot_number_map_access = map(map_access_dot_number, |accessor| ExprElement::MapAccess {
12271224
accessor,
12281225
});
@@ -1300,7 +1297,16 @@ pub fn expr_element(i: Input) -> IResult<WithSpan<ExprElement>> {
13001297
"[" ~ #comma_separated_list0_ignore_trailing(subexpr(0))? ~ ","? ~ ^"]"
13011298
},
13021299
|(_, opt_args, _, _)| {
1303-
let exprs = opt_args.unwrap_or_default();
1300+
let mut exprs = opt_args.unwrap_or_default();
1301+
1302+
if exprs.len() == 1 {
1303+
let expr = exprs.pop().unwrap();
1304+
return ExprElement::MapAccess {
1305+
accessor: MapAccessor::Bracket {
1306+
key: Box::new(expr),
1307+
},
1308+
};
1309+
}
13041310
ExprElement::Array { exprs }
13051311
},
13061312
);
@@ -1583,7 +1589,7 @@ pub fn expr_element(i: Input) -> IResult<WithSpan<ExprElement>> {
15831589
},
15841590
LBracket => {
15851591
return with_span!(rule!(
1586-
#list_comprehensions | #bracket_map_access | #array
1592+
#list_comprehensions | #array
15871593
))
15881594
.parse(i);
15891595
},
@@ -2392,16 +2398,6 @@ pub fn interval_kind(i: Input) -> IResult<IntervalKind> {
23922398
.parse(i)
23932399
}
23942400

2395-
fn map_access_bracket(i: Input) -> IResult<MapAccessor> {
2396-
map(
2397-
rule! {
2398-
"[" ~ #subexpr(0) ~ "]"
2399-
},
2400-
|(_, key, _)| MapAccessor::Bracket { key: Box::new(key) },
2401-
)
2402-
.parse(i)
2403-
}
2404-
24052401
fn map_access_dot_number(i: Input) -> IResult<MapAccessor> {
24062402
map_res(rule! { LiteralFloat }, |key| {
24072403
if key.text().starts_with('.') {

0 commit comments

Comments
 (0)