Add "return" statement
Functions may now be exited by returning a value or no value. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -22,6 +22,7 @@ Body -> Result<Vec<Stmt>>:
|
||||
Stmt -> Result<Stmt>:
|
||||
Expr { Ok(Stmt::Expr($1?)) }
|
||||
| Assign { Ok(Stmt::Assign($1?)) }
|
||||
| Return { Ok(Stmt::Return($1?)) }
|
||||
;
|
||||
|
||||
Assign -> Result<AssignStmt>:
|
||||
@@ -41,6 +42,11 @@ LhsExpr -> Result<LhsExpr>:
|
||||
}
|
||||
;
|
||||
|
||||
Return -> Result<ReturnStmt>:
|
||||
'return' Expr { Ok(ReturnStmt { expr: Some($2?), }) }
|
||||
| 'return' { Ok(ReturnStmt { expr: None, }) }
|
||||
;
|
||||
|
||||
Expr -> Result<Expr>: BinExpr { $1 };
|
||||
|
||||
BinExpr -> Result<Expr>:
|
||||
|
||||
Reference in New Issue
Block a user