feat: borrow expr, parser fix, borrow tests, borrow example

This commit is contained in:
2026-06-07 18:09:40 +03:00
parent adca52b269
commit 0d7a30835f
4 changed files with 78 additions and 9 deletions
+2 -4
View File
@@ -601,12 +601,10 @@ proc parseUnary(p: var Parser): Expr =
case p.peek()
of tkBorrow:
discard p.advance() # borrow
let isMut = p.check(tkMut)
discard p.expect(tkAmp, "expected '&' after 'borrow'")
var isMut = p.check(tkMut)
if isMut:
discard p.advance() # mut
discard p.expect(tkAmp, "expected '&' after 'borrow'")
if isMut and p.check(tkMut):
discard p.advance() # redundant mut after &
let operand = p.parseUnary() # parse the moved value
return Expr(kind: ekBorrow, loc: loc, exprBorrowOperand: operand, exprBorrowMutable: isMut)
of tkBang, tkMinus, tkTilde, tkStar, tkAmp: