From 57ea1bae300f689cbc1917f82cc730f492f27498 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 8 Aug 2015 12:51:46 -0700 Subject: [PATCH] Preliminary addition of function blocks --- Grammar | 6 ++++++ src/parser.rs | 9 +++++++++ 2 files changed, 15 insertions(+) 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() {