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:
2020-09-18 16:39:06 -07:00
parent 337be88849
commit f0032afe12
7 changed files with 95 additions and 9 deletions

View File

@@ -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 }