From 814b7f9411565f3596a6d113021bc4e1e9883292 Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Fri, 26 Mar 2021 11:39:05 +0000 Subject: [PATCH] Add last_stmt_with_semicolon (#159) * Add last_stmt_with_semicolon * Update full-moon/src/ast/mod.rs Co-authored-by: boyned//Kampfkarren Co-authored-by: boyned//Kampfkarren --- CHANGELOG.md | 1 + full-moon/src/ast/mod.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c913fccc..ce07a709 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added a `lua52` feature flag for Lua 5.2 specific syntax - Added support for `goto` and labels when using the `lua52` feature flag - Added initialiser methods for all Luau-related structs available under the roblox feature flag. +- Added `block.last_stmt_with_semicolon()` which returns a tuple containing the last stmt in the block, and an optional token reference. ### Changed - Updated dependency cfg_if to v1.0 diff --git a/full-moon/src/ast/mod.rs b/full-moon/src/ast/mod.rs index f607a24e..4c4c053e 100644 --- a/full-moon/src/ast/mod.rs +++ b/full-moon/src/ast/mod.rs @@ -80,6 +80,11 @@ impl<'a> Block<'a> { Some(&self.last_stmt.as_ref()?.0) } + /// The last statement of the block if on exists, including any optional semicolon token reference present + pub fn last_stmt_with_semicolon(&self) -> Option<&(LastStmt<'a>, Option>)> { + self.last_stmt.as_ref() + } + /// Returns a new block with the given statements /// Takes a vector of statements, followed by an optional semicolon token reference pub fn with_stmts(self, stmts: Vec<(Stmt<'a>, Option>)>) -> Self {