From 37c8582c4eaec5ec11730db8b0b4a64ac626241f Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Fri, 11 Aug 2023 12:07:24 +0530 Subject: [PATCH] fix: improved regex pattern, removes backrefs --- src/cli/repl.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/cli/repl.rs b/src/cli/repl.rs index 544670d..ff14181 100644 --- a/src/cli/repl.rs +++ b/src/cli/repl.rs @@ -8,7 +8,7 @@ use std::{ use anyhow::Error; use clap::Command; -use fancy_regex::Regex; +use regex::Regex; use lune::lua::stdio::formatting::{pretty_format_luau_error, pretty_format_value}; use lune::Lune; use mlua::ExternalError; @@ -77,14 +77,8 @@ pub async fn show_interface(cmd: Command) -> Result { !env_var_bool(no_color).unwrap_or_else(|| false) } }); - - // Group 2 of this match pattern is the variable contents - - // We're using fancy_regex instead of regex for backreferences - // and lookaround. I'm not too good at regex, so if there's a - // way to do this without backreferences and lookarounds, - // please let me know. - const VARIABLE_DECLARATION_PAT: &str = r#"(?!local.*)(?!\s)(=\s*)(.*)"#; + + const VARIABLE_DECLARATION_PAT: &str = r#"(local)?\s*(.*)\s*(=)\s*(.*)\s*"#; // HACK: Prepend this "context" to the source code provided, // so that the variable is preserved even the following steps @@ -138,7 +132,7 @@ pub async fn show_interface(cmd: Command) -> Result { match eval_result { Ok(_) => { - if Regex::new(VARIABLE_DECLARATION_PAT)?.is_match(&source_code)? + if Regex::new(VARIABLE_DECLARATION_PAT)?.is_match(&source_code) && !&source_code.contains("\n") { let declaration = source_code.split("=").collect::>()[1]