diff --git a/Grammar b/Grammar index f880104..8cffe32 100644 --- a/Grammar +++ b/Grammar @@ -7,6 +7,12 @@ := let = | + | + + := fn ( ) end + + := e + | , := if then end | if then else end diff --git a/src/parser.rs b/src/parser.rs index c1e0b59..4e002a8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -15,6 +15,7 @@ pub enum AST { Statements(Vec), IfStatement(Box, Box, Option>), WhileStatement(Box, Box), + Function(Vec, Box), DoNothing } @@ -105,10 +106,18 @@ fn statements(tokens: &mut Tokens) -> ParseResult { fn statement(tokens: &mut Tokens) -> ParseResult { match tokens.peek().map(|i| i.clone()) { Some(&Keyword(Kw::Let)) => let_expression(tokens), + Some(&Keyword(Kw::Fn)) => function_block(tokens), _ => expression(tokens) } } +fn function_block(tokens: &mut Tokens) -> ParseResult { + expect!(Keyword(Kw::Fn), tokens); + expect!(Keyword(Kw::End), tokens); + + Ok(AST::Function(Vec::new(), Box::new(AST::DoNothing))) +} + fn let_expression(tokens: &mut Tokens) -> ParseResult { expect!(Keyword(Kw::Let), tokens); if let Some(&Identifier(ref name)) = tokens.next() {