fixing the precedence regarding slice ranges

Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
Jakub Doka 2024-12-22 20:43:49 +01:00
parent 5909837015
commit 9c4b84ce33
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143

View file

@ -490,15 +490,6 @@ impl<'a, 'b> Parser<'a, 'b> {
},
body: self.ptr_expr()?,
},
T::Range => E::Range {
pos: token.start,
start: None,
end: if matches!(self.token.kind, TokenKind::RBrack) {
None
} else {
Some(self.ptr_expr()?)
},
},
T::Ctor => self.ctor(pos, None),
T::Tupl => self.tupl(pos, None, ListKind::Tuple),
T::Arr => self.tupl(pos, None, ListKind::Array),
@ -570,14 +561,7 @@ impl<'a, 'b> Parser<'a, 'b> {
let token = self.token;
if matches!(
token.kind,
T::LParen
| T::Ctor
| T::Dot
| T::Tupl
| T::Arr
| T::LBrack
| T::Colon
| T::Range
T::LParen | T::Ctor | T::Dot | T::Tupl | T::Arr | T::LBrack | T::Colon
) {
self.next();
}
@ -593,20 +577,43 @@ impl<'a, 'b> Parser<'a, 'b> {
T::Arr => self.tupl(token.start, Some(expr), ListKind::Array),
T::LBrack => E::Index {
base: self.arena.alloc(expr),
index: {
let index = self.expr()?;
self.expect_advance(T::RBrack)?;
self.arena.alloc(index)
},
},
T::Range => E::Range {
pos: token.start,
start: Some(self.arena.alloc(expr)),
end: if matches!(self.token.kind, TokenKind::RBrack) {
None
index: self.arena.alloc({
if self.advance_if(T::Range) {
let pos = self.token.start;
if self.advance_if(T::RBrack) {
Expr::Range { pos, start: None, end: None }
} else {
Some(self.ptr_expr()?)
},
let res = Expr::Range {
pos,
start: None,
end: Some(self.ptr_expr()?),
};
self.expect_advance(T::RBrack)?;
res
}
} else {
let start = self.expr()?;
let pos = self.token.start;
if self.advance_if(T::Range) {
let start = self.arena.alloc(start);
if self.advance_if(T::RBrack) {
Expr::Range { pos, start: Some(start), end: None }
} else {
let res = Expr::Range {
pos,
start: Some(start),
end: Some(self.ptr_expr()?),
};
self.expect_advance(T::RBrack)?;
res
}
} else {
self.expect_advance(T::RBrack)?;
start
}
}
}),
},
T::Colon => E::BinOp {
left: {