From a0a27cda96e1922b019b216961c39f7ef7991d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20H=C3=B6lting?= <87192362+moritz-hoelting@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:48:40 +0200 Subject: [PATCH] add argument for transpiling pack_format --- src/lib.rs | 18 ++++++++++++------ src/public_helpers.rs | 6 ++++-- tests/transpiling/main.rs | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9ad6230..e82ca9e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,8 +31,6 @@ use shulkerbox::{datapack::Datapack, virtual_fs::VFolder}; use crate::lexical::token_stream::TokenStream; -const DEFAULT_PACK_FORMAT: u8 = 48; - /// Converts the given source code to tokens. /// /// # Errors @@ -70,14 +68,18 @@ where /// - If an error occurs while parsing the source code. /// - If an error occurs while transpiling the source code. #[cfg(feature = "shulkerbox")] -pub fn transpile(file_provider: &F, script_paths: &[(String, P)]) -> Result +pub fn transpile( + file_provider: &F, + pack_format: u8, + script_paths: &[(String, P)], +) -> Result where F: FileProvider, P: AsRef, { let printer = Printer::new(); - public_helpers::transpile(&printer, file_provider, script_paths) + public_helpers::transpile(&printer, file_provider, pack_format, script_paths) } /// Compiles the given source code. @@ -90,14 +92,18 @@ where /// - If an error occurs while parsing the source code. /// - If an error occurs while transpiling the source code. #[cfg(feature = "shulkerbox")] -pub fn compile(file_provider: &F, script_paths: &[(String, P)]) -> Result +pub fn compile( + file_provider: &F, + pack_format: u8, + script_paths: &[(String, P)], +) -> Result where F: FileProvider, P: AsRef, { let printer = Printer::new(); - public_helpers::compile(&printer, file_provider, script_paths) + public_helpers::compile(&printer, file_provider, pack_format, script_paths) } struct Printer { diff --git a/src/public_helpers.rs b/src/public_helpers.rs index 594291f..d4e519a 100644 --- a/src/public_helpers.rs +++ b/src/public_helpers.rs @@ -61,6 +61,7 @@ pub fn parse( pub fn transpile( printer: &Printer, file_provider: &F, + pack_format: u8, script_paths: &[(String, P)], ) -> Result where @@ -86,7 +87,7 @@ where tracing::info!("Transpiling the source code."); - let mut transpiler = Transpiler::new(crate::DEFAULT_PACK_FORMAT); + let mut transpiler = Transpiler::new(pack_format); transpiler.transpile(&programs, printer)?; let datapack = transpiler.into_datapack(); @@ -104,13 +105,14 @@ where pub fn compile( printer: &Printer, file_provider: &F, + pack_format: u8, script_paths: &[(String, P)], ) -> Result where F: FileProvider, P: AsRef, { - let datapack = transpile(printer, file_provider, script_paths)?; + let datapack = transpile(printer, file_provider, pack_format, script_paths)?; tracing::info!("Compiling the source code."); diff --git a/tests/transpiling/main.rs b/tests/transpiling/main.rs index d55383d..bc4af07 100644 --- a/tests/transpiling/main.rs +++ b/tests/transpiling/main.rs @@ -9,7 +9,7 @@ fn transpile_test1() { let mut dir = VFolder::new(); dir.add_file("test1.shu", VFile::Text(source.to_string())); - let transpiled = shulkerscript::transpile(&dir, &[("test1".to_string(), "./test1.shu")]) + let transpiled = shulkerscript::transpile(&dir, 48, &[("test1".to_string(), "./test1.shu")]) .expect("Failed to transpile"); let expected = {