Add function expr parsing
* Introduce new `fn` keyword * Function example is added to examples/expr.not Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -92,10 +92,25 @@ IndexExpr -> Result<Expr>:
|
||||
;
|
||||
|
||||
AccessExpr -> Result<Expr>:
|
||||
AtomExpr { $1 }
|
||||
FunExpr { $1 }
|
||||
| CallIndexExpr '.' Ident { Ok(AccessExpr::new_expr($1?, $3?)) }
|
||||
;
|
||||
|
||||
FunExpr -> Result<Expr>:
|
||||
AtomExpr { $1 }
|
||||
| 'fn' '(' FunParams ')' '{' Body '}' { Ok(FunExpr::new_expr($3?, $6?)) }
|
||||
;
|
||||
|
||||
FunParams -> Result<Vec<String>>:
|
||||
FunParamsTail { $1 }
|
||||
| { Ok(Vec::new()) }
|
||||
;
|
||||
|
||||
FunParamsTail -> Result<Vec<String>>:
|
||||
FunParamsTail ',' Ident { flatten($1, $3) }
|
||||
| Ident { Ok(vec![$1?]) }
|
||||
;
|
||||
|
||||
AtomExpr -> Result<Expr>:
|
||||
Atom { $1.map(Expr::Atom) }
|
||||
| '(' Expr ')' { $2 }
|
||||
|
||||
Reference in New Issue
Block a user