mumu 0.11.1

Lava Mumu is a language for those in the now and that know
Documentation
use crate::parser::types::{Value, RegexValue};
use super::helpers::err_with_pos;

pub fn eval_regex_literal(
    pattern: &str,
    flags: &str,
    line: usize,
    col: usize,
) -> Result<Value, String> {
    // Flags: only "i", "m", "s", "x" allowed
    let mut flag_str = String::new();
    let mut builder = regex::RegexBuilder::new(pattern);

    for ch in flags.chars() {
        match ch {
            'i' => { builder.case_insensitive(true); flag_str.push('i'); }
            'm' => { builder.multi_line(true); flag_str.push('m'); }
            's' => { builder.dot_matches_new_line(true); flag_str.push('s'); }
            'x' => { builder.ignore_whitespace(true); flag_str.push('x'); }
            f => {
                return Err(err_with_pos(
                    format!("Invalid regex flag '{}'. Only i, m, s, x are supported.", f),
                    line,
                    col,
                ));
            }
        }
    }

    let compiled = builder.build().map_err(|e| {
        err_with_pos(
            format!("Regex compile error: {}", e),
            line,
            col,
        )
    })?;

    Ok(Value::Regex(RegexValue {
        pattern: pattern.to_string(),
        flags: flag_str,
        compiled: std::sync::Arc::new(compiled),
    }))
}