diff --git a/.gitignore b/.gitignore
index 35b3418..be68079 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
target
.idea
-src/bin/PRIKOL.rs
+src/bin/sandbox.rs
+sandbox
\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index 2f65f0b..9d8cd76 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -86,15 +86,6 @@ dependencies = [
"windows-targets",
]
-[[package]]
-name = "block-buffer"
-version = "0.10.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
-dependencies = [
- "generic-array",
-]
-
[[package]]
name = "bytes"
version = "1.10.1"
@@ -107,35 +98,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
-[[package]]
-name = "cpufeatures"
-version = "0.2.17"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
-dependencies = [
- "libc",
-]
-
-[[package]]
-name = "crypto-common"
-version = "0.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
-dependencies = [
- "generic-array",
- "typenum",
-]
-
-[[package]]
-name = "digest"
-version = "0.10.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
-dependencies = [
- "block-buffer",
- "crypto-common",
-]
-
[[package]]
name = "fnv"
version = "1.0.7"
@@ -184,16 +146,6 @@ dependencies = [
"pin-utils",
]
-[[package]]
-name = "generic-array"
-version = "0.14.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
-dependencies = [
- "typenum",
- "version_check",
-]
-
[[package]]
name = "gimli"
version = "0.31.1"
@@ -287,17 +239,6 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
-[[package]]
-name = "json5"
-version = "0.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1"
-dependencies = [
- "pest",
- "pest_derive",
- "serde",
-]
-
[[package]]
name = "libc"
version = "0.2.171"
@@ -373,51 +314,6 @@ version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
-[[package]]
-name = "pest"
-version = "2.8.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "198db74531d58c70a361c42201efde7e2591e976d518caf7662a47dc5720e7b6"
-dependencies = [
- "memchr",
- "thiserror",
- "ucd-trie",
-]
-
-[[package]]
-name = "pest_derive"
-version = "2.8.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d725d9cfd79e87dccc9341a2ef39d1b6f6353d68c4b33c177febbe1a402c97c5"
-dependencies = [
- "pest",
- "pest_generator",
-]
-
-[[package]]
-name = "pest_generator"
-version = "2.8.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "db7d01726be8ab66ab32f9df467ae8b1148906685bbe75c82d1e65d7f5b3f841"
-dependencies = [
- "pest",
- "pest_meta",
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
-name = "pest_meta"
-version = "2.8.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7f9f832470494906d1fca5329f8ab5791cc60beb230c74815dff541cbd2b5ca0"
-dependencies = [
- "once_cell",
- "pest",
- "sha2",
-]
-
[[package]]
name = "pin-project-lite"
version = "0.2.16"
@@ -520,17 +416,6 @@ dependencies = [
"serde",
]
-[[package]]
-name = "sha2"
-version = "0.10.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
-dependencies = [
- "cfg-if",
- "cpufeatures",
- "digest",
-]
-
[[package]]
name = "smallvec"
version = "1.15.0"
@@ -564,26 +449,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
-[[package]]
-name = "thiserror"
-version = "2.0.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
-dependencies = [
- "thiserror-impl",
-]
-
-[[package]]
-name = "thiserror-impl"
-version = "2.0.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
[[package]]
name = "tokio"
version = "1.44.2"
@@ -658,30 +523,12 @@ dependencies = [
"once_cell",
]
-[[package]]
-name = "typenum"
-version = "1.18.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
-
-[[package]]
-name = "ucd-trie"
-version = "0.1.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
-
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
-[[package]]
-name = "version_check"
-version = "0.9.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
-
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@@ -766,8 +613,6 @@ name = "yyyi_ru"
version = "0.1.0"
dependencies = [
"axum",
- "json5",
"mtgott",
- "serde_json",
"tokio",
]
diff --git a/Cargo.toml b/Cargo.toml
index bec4282..0b98f0e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,10 +1,9 @@
[package]
name = "yyyi_ru"
version = "0.1.0"
+edition = "2024"
[dependencies]
axum = "0.8.3"
tokio = { version = "1.44.1", features = ["rt-multi-thread"] }
-json5 = "0.4.1"
-serde_json = "1.0.140"
mtgott = { path = "./mtgott" }
diff --git a/assets/HypertextPages/index.html b/assets/HypertextPages/index.html
index dc6ff36..00f3e6d 100644
--- a/assets/HypertextPages/index.html
+++ b/assets/HypertextPages/index.html
@@ -1,6 +1,5 @@
-{% import "lang_macro.html" as lang_macro %}
diff --git a/assets/HypertextPages/lang-macro.html b/assets/HypertextPages/lang-macro.html
deleted file mode 100644
index e69de29..0000000
diff --git a/mtgott/src/bin/PRIKOL.rs b/mtgott/src/bin/PRIKOL.rs
deleted file mode 100644
index c4b2854..0000000
--- a/mtgott/src/bin/PRIKOL.rs
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-fn main() {
- let func : & dyn for<'a> Fn(& 'a u32) -> &'a u32;
- func = &|u: &u32| -> &u32 {u};
- let y = 6u32;
- println!("{}", func(&y));
-}
\ No newline at end of file
diff --git a/mtgott/src/dirsearch.rs b/mtgott/src/dirsearch.rs
index c2e676b..8470a50 100644
--- a/mtgott/src/dirsearch.rs
+++ b/mtgott/src/dirsearch.rs
@@ -12,7 +12,7 @@ use std::rc::Rc;
pub fn search_dir_rec_helper(
res: &mut Vec>,
fs_path: PathBuf, virtual_path: String,
- allowed_extensions: &[&str], is_valid_name: fn(&str) -> bool, recc: u32
+ allowed_extensions: &[&str], is_valid_name: &dyn Fn(&str) -> bool, recc: u32
)-> Result<(), Box> {
if recc == 0 { return Err("Recursion limit exceeded".into()); }
let fs_path = canonicalize(fs_path)?;
@@ -45,65 +45,87 @@ pub fn search_dir_rec_helper(
}
pub fn search_dir(
- p: &str, allowed_extensions: &[&str], is_valid_name: fn(&str) -> bool)
+ p: &str, allowed_extensions: &[&str], is_valid_name: &dyn Fn(&str) -> bool)
-> Result>, Box> {
let mut res: Vec> = (0..allowed_extensions.len()).map(|_| Vec::new()).collect();
search_dir_rec_helper(&mut res, PathBuf::from(p), String::new(), allowed_extensions, is_valid_name, 100)?;
Ok(res)
}
-struct MtgottDirContent {
- mtgott: Vec,
- imtgott: Vec,
- plain: Vec
+pub struct MtgottDirFiles {
+ pub mtgott: Vec,
+ pub imtgott: Vec,
+ pub plain: Vec
}
-pub fn search_mtgott_dir(p: &str, plain_ext: &str) -> Result> {
+pub fn search_mtgott_dir(p: &str, plain_ext: &str) -> Result> {
let mut all = search_dir(p, &[
&(String::from(".mtgott") + plain_ext),
&(String::from(".imtgott") + plain_ext),
plain_ext
- ], is_special_name)?;
- Ok(MtgottDirContent{
+ ], &(|s| !is_special_name(s)))?;
+ Ok(MtgottDirFiles {
mtgott: std::mem::take(&mut all[0]),
imtgott: std::mem::take(&mut all[1]),
plain: std::mem::take(&mut all[2]),
})
}
-pub fn get_all_templates(p: &str, plain_ext: &str) -> Result> {
- let source = search_mtgott_dir(p, plain_ext)?;
+pub struct FileWithPath {
+ pub v_path: String,
+ pub text: String,
+}
+
+pub struct MtgottDirContent {
+ pub mtgott: Vec,
+ pub imtgott: Vec,
+ pub plain: Vec,
+}
+
+fn read_file_vector(p: &str, plain_ext: &str, secondary_ext: &str, files: Vec) -> Result, Box> {
+ files.iter().map(|v_path| -> Result> {
+ Ok(FileWithPath{
+ v_path: v_path.clone(),
+ text: String::from_utf8(fs::read(
+ &format!("{p}/{v_path}{secondary_ext}{plain_ext}")
+ )?)?})
+ }).collect::, Box>>()
+}
+
+pub fn read_mtgott_dir_content(p: &str, plain_ext: &str) -> Result> {
+ let MtgottDirFiles{mtgott, imtgott, plain} = search_mtgott_dir(p, plain_ext)?;
+ Ok(MtgottDirContent {
+ mtgott: read_file_vector(p, plain_ext, ".mtgott", mtgott)?,
+ imtgott: read_file_vector(p, plain_ext, ".imtgott", imtgott)?,
+ plain: read_file_vector(p, plain_ext, "", plain)?,
+ })
+}
+
+pub fn get_all_templates_from_dir_text(dir: MtgottDirContent, plain_ext: &str) -> Result> {
let mut res = MTGOTT{root: SharedValue::Dict(HashMap::new()), source_expressions: Vec::new(), source_elements: Vec::new()};
- for cut_path in source.mtgott {
- let path = format!("{cut_path}.mtgott{plain_ext}");
- let text_bytes = fs::read(PathBuf::from(p).join(&path))?;
- let text = std::str::from_utf8(&text_bytes)?;
- let plemege = parse_one_file_packed(text, &cut_path, &mut res.source_expressions)?;
+ for FileWithPath{v_path, text} in dir.mtgott {
+ let path = format!("{v_path}.mtgott{}", plain_ext);
+ let plemege = parse_one_file_packed(&text, &v_path, &mut res.source_expressions)?;
let compiled = plemege_to_value(plemege, &path, &mut res.source_elements, &mut res.source_expressions, 150)?;
- add_path_to_root(&mut res.root, &cut_path, '/', compiled)?
+ add_path_with_slashes_to_root(&mut res.root, &v_path, compiled)?
}
- for cut_path in source.imtgott {
- let path = format!("{cut_path}.imtgott{plain_ext}");
- let text_bytes = fs::read(PathBuf::from(p).join(&path))?;
- let text = std::str::from_utf8(&text_bytes)?;
- let plemege = parse_one_file_simplified(text, &cut_path, &mut res.source_expressions)?;
+ for FileWithPath{v_path, text} in dir.imtgott {
+ let path = format!("{v_path}.imtgott{}", plain_ext);
+ let plemege = parse_one_file_simplified(&text, &v_path, &mut res.source_expressions)?;
let compiled = plemege_to_value(plemege, &path, &mut res.source_elements, &mut res.source_expressions, 150)?;
- add_path_to_root(&mut res.root, &cut_path, '/', compiled)?
+ add_path_with_slashes_to_root(&mut res.root, &v_path, compiled)?
}
- for cut_path in source.plain {
- let path = format!("{cut_path}{plain_ext}");
- let text_bytes = fs::read(PathBuf::from(p).join(&path))?;
- let text = String::from_utf8(text_bytes)?;
- add_path_to_root(&mut res.root, &cut_path, '/', SharedValue::Str(text))?
+ for FileWithPath{v_path, text} in dir.plain {
+ add_path_with_slashes_to_root(&mut res.root, &v_path, SharedValue::Str(text))?
}
Ok(res)
}
-pub fn get_all_templates_plus_builtins(
- p: &str, plain_ext: &str,
+pub fn get_all_templates_plus_builtins_from_dir_text(
+ dir: MtgottDirContent, plain_ext: &str,
sanitize: fn(&str) -> String,
) -> Result>{
- let mut res = get_all_templates(p, plain_ext)?;
+ let mut res = get_all_templates_from_dir_text(dir, plain_ext)?;
add_path_with_slashes_to_root(&mut res.root, "sanitize", SharedValue::Fn(Box::new(
/* One obvious problem with this sanitizer is that it makes copy even when it
* takes full ownership of some string and does not have to replace any characters*/
@@ -124,6 +146,10 @@ pub fn get_all_templates_plus_builtins(
Ok(res)
}
-pub fn get_root_html(p: &str) -> Result>{
- get_all_templates_plus_builtins(p, ".html", escape_for_html)
+pub fn get_root_html_from_dir_text_html(dir: MtgottDirContent) -> Result>{
+ get_all_templates_plus_builtins_from_dir_text(dir, ".html", escape_for_html)
+}
+
+pub fn get_root_html(p: &str) -> Result> {
+ get_root_html_from_dir_text_html(read_mtgott_dir_content(p, ".html")?)
}
diff --git a/mtgott/src/parser.rs b/mtgott/src/parser.rs
index ff710fb..8b814b8 100644
--- a/mtgott/src/parser.rs
+++ b/mtgott/src/parser.rs
@@ -251,13 +251,13 @@ impl<'a> Parser<'a> {
return Err(self.new_unexpected_char_error(expected_pack_name))
}
let child_name: &str = &self.text[p1..self.p];
- if !is_special_name(child_name) {
+ if is_special_name(child_name) {
return Err(FileParsingError::new(illegal_pack_name, p1, self.p))
}
if let Some(_) = res.get(child_name) {
return Err(FileParsingError::new(pack_member_name_already_occupied, p1, self.p))
}
- self.skip_normal_word();
+ self.skip_whitespace();
if self.is_ahead("$}"){
self.p += 2;
@@ -471,7 +471,7 @@ impl<'a> Parser<'a> {
return finishing_touches(ReasonOfElementEnd{p1: self.p, cmd: BlockEndingTag::EOF}, res);
} else if self.is_ahead("{{") {
fin_static(self, tp1, &mut res);
- self.skip_whitespace();
+ self.p += 2;
if !self.is_ahead("}}") {
let expr: Expression = self.parse_expression(
arg_names, &mut (0..arg_names.len()).collect(), recc)?;
@@ -488,7 +488,7 @@ impl<'a> Parser<'a> {
tp1 = self.p;
} else if self.is_ahead("{[") {
fin_static(self, tp1, &mut res);
- self.skip_whitespace();
+ self.p += 2;
let expr: Expression = self.parse_expression(
arg_names, &mut (0..arg_names.len()).collect(), recc)?;
res.push(SubElement::InsertExpr(expr));
@@ -750,7 +750,9 @@ impl<'a> Parser<'a> {
) -> Result