From ddba3423dfa15bab3ad2ab0617c5948f7a5f1df6 Mon Sep 17 00:00:00 2001 From: yannickreiss Date: Tue, 12 Aug 2025 19:04:09 +0200 Subject: [PATCH] Transofrmation --- example.mlc | 2 +- language.toml | 1 + src/preprocessor.rs | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/example.mlc b/example.mlc index 1e15215..e0c3385 100644 --- a/example.mlc +++ b/example.mlc @@ -1,5 +1,5 @@ -#with language.toml variable:=-3; c := (a+b- 3) * 23 + variable; d := c - a;Natural : Number (n) := {n >= 0};faculty : Natural (n) -> Natural := if n = 0 then 1 else faculty (n-1) * n end; String Natural (n) := {Character * n};hello_word -> String := "Hello World!"; first_letter -> Character := 'a'; wrong -> Logic := false;date -> String := "#date_now"; +user -> String := "#user" diff --git a/language.toml b/language.toml index 137ffca..43c5085 100644 --- a/language.toml +++ b/language.toml @@ -10,6 +10,7 @@ comments = ["^--.*", ""] [meta.interpolation] with = ["^#with ([\\w./]+)", "cat $1"] date = ["#date_now", "date"] +user = ["#user", "user"] # Describes tokens to be replaced by identifiers and then later swapped back in after the tokenizer. # All special tokens are treated as constants diff --git a/src/preprocessor.rs b/src/preprocessor.rs index 168a7f9..e6644fc 100644 --- a/src/preprocessor.rs +++ b/src/preprocessor.rs @@ -125,9 +125,20 @@ impl MetaRules { println!("[INFO] Applying rule {}", rule.0); let base_pattern: Regex = Regex::new((rule.1 .0).as_str()).unwrap(); let processed_code_replacement = processed_code.clone(); - let parameter = &base_pattern + let parameter = if &base_pattern .captures(processed_code_replacement.as_str()) - .unwrap()[0]; + .unwrap() + .len() + > 0 + { + &base_pattern + .captures(processed_code_replacement.as_str()) + .unwrap()[0] + } else { + &base_pattern + .captures(processed_code_replacement.as_str()) + .unwrap() + }; let command: &str = &base_pattern.replace(parameter, rule.1 .1.as_str()); println!("{:?}", &command); let subprocess = std::process::Command::new("/bin/bash")