From 5af42d0828eab6101b345a06a7c04eede809e834 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Fri, 12 Nov 2021 00:27:06 -0800 Subject: [PATCH] Flow control --- schala-lang/language/src/parsing/new.rs | 6 ++++++ schala-lang/language/src/parsing/test.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/schala-lang/language/src/parsing/new.rs b/schala-lang/language/src/parsing/new.rs index 5be93ae..483494f 100644 --- a/schala-lang/language/src/parsing/new.rs +++ b/schala-lang/language/src/parsing/new.rs @@ -35,8 +35,14 @@ peg::parser! { rule statement_kind() -> StatementKind = __ import:import() { StatementKind::Import(import) } / __ decl:declaration() { StatementKind::Declaration(decl) } / + __ flow:flow() { StatementKind::Flow(flow) } / __ expr:expression() { StatementKind::Expression(expr) } + rule flow() -> FlowControl = + "continue" { FlowControl::Continue } / + "break" { FlowControl::Break } / + "return" _ expr:expression()? { FlowControl::Return(expr) } + rule import() -> ImportSpecifier = "import" _ path_components:path_components() suffix:import_suffix()? { ImportSpecifier { diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 1d0b95f..836e45e 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -1292,7 +1292,7 @@ fn flow_control() { return 10; }"#; - assert_ast!( + assert_ast2!( source, vec![fn_decl( Signature { name: rc("test"), operator: false, type_anno: None, params: vec![] },