add argument for transpiling pack_format
This commit is contained in:
		
							parent
							
								
									398fce2bd6
								
							
						
					
					
						commit
						a0a27cda96
					
				
							
								
								
									
										18
									
								
								src/lib.rs
								
								
								
								
							
							
						
						
									
										18
									
								
								src/lib.rs
								
								
								
								
							| 
						 | 
					@ -31,8 +31,6 @@ use shulkerbox::{datapack::Datapack, virtual_fs::VFolder};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::lexical::token_stream::TokenStream;
 | 
					use crate::lexical::token_stream::TokenStream;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DEFAULT_PACK_FORMAT: u8 = 48;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/// Converts the given source code to tokens.
 | 
					/// Converts the given source code to tokens.
 | 
				
			||||||
///
 | 
					///
 | 
				
			||||||
/// # Errors
 | 
					/// # Errors
 | 
				
			||||||
| 
						 | 
					@ -70,14 +68,18 @@ where
 | 
				
			||||||
/// - If an error occurs while parsing the source code.
 | 
					/// - If an error occurs while parsing the source code.
 | 
				
			||||||
/// - If an error occurs while transpiling the source code.
 | 
					/// - If an error occurs while transpiling the source code.
 | 
				
			||||||
#[cfg(feature = "shulkerbox")]
 | 
					#[cfg(feature = "shulkerbox")]
 | 
				
			||||||
pub fn transpile<F, P>(file_provider: &F, script_paths: &[(String, P)]) -> Result<Datapack>
 | 
					pub fn transpile<F, P>(
 | 
				
			||||||
 | 
					    file_provider: &F,
 | 
				
			||||||
 | 
					    pack_format: u8,
 | 
				
			||||||
 | 
					    script_paths: &[(String, P)],
 | 
				
			||||||
 | 
					) -> Result<Datapack>
 | 
				
			||||||
where
 | 
					where
 | 
				
			||||||
    F: FileProvider,
 | 
					    F: FileProvider,
 | 
				
			||||||
    P: AsRef<Path>,
 | 
					    P: AsRef<Path>,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let printer = Printer::new();
 | 
					    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.
 | 
					/// Compiles the given source code.
 | 
				
			||||||
| 
						 | 
					@ -90,14 +92,18 @@ where
 | 
				
			||||||
/// - If an error occurs while parsing the source code.
 | 
					/// - If an error occurs while parsing the source code.
 | 
				
			||||||
/// - If an error occurs while transpiling the source code.
 | 
					/// - If an error occurs while transpiling the source code.
 | 
				
			||||||
#[cfg(feature = "shulkerbox")]
 | 
					#[cfg(feature = "shulkerbox")]
 | 
				
			||||||
pub fn compile<F, P>(file_provider: &F, script_paths: &[(String, P)]) -> Result<VFolder>
 | 
					pub fn compile<F, P>(
 | 
				
			||||||
 | 
					    file_provider: &F,
 | 
				
			||||||
 | 
					    pack_format: u8,
 | 
				
			||||||
 | 
					    script_paths: &[(String, P)],
 | 
				
			||||||
 | 
					) -> Result<VFolder>
 | 
				
			||||||
where
 | 
					where
 | 
				
			||||||
    F: FileProvider,
 | 
					    F: FileProvider,
 | 
				
			||||||
    P: AsRef<Path>,
 | 
					    P: AsRef<Path>,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let printer = Printer::new();
 | 
					    let printer = Printer::new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public_helpers::compile(&printer, file_provider, script_paths)
 | 
					    public_helpers::compile(&printer, file_provider, pack_format, script_paths)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Printer {
 | 
					struct Printer {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -61,6 +61,7 @@ pub fn parse(
 | 
				
			||||||
pub fn transpile<F, P>(
 | 
					pub fn transpile<F, P>(
 | 
				
			||||||
    printer: &Printer,
 | 
					    printer: &Printer,
 | 
				
			||||||
    file_provider: &F,
 | 
					    file_provider: &F,
 | 
				
			||||||
 | 
					    pack_format: u8,
 | 
				
			||||||
    script_paths: &[(String, P)],
 | 
					    script_paths: &[(String, P)],
 | 
				
			||||||
) -> Result<Datapack>
 | 
					) -> Result<Datapack>
 | 
				
			||||||
where
 | 
					where
 | 
				
			||||||
| 
						 | 
					@ -86,7 +87,7 @@ where
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    tracing::info!("Transpiling the source code.");
 | 
					    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)?;
 | 
					    transpiler.transpile(&programs, printer)?;
 | 
				
			||||||
    let datapack = transpiler.into_datapack();
 | 
					    let datapack = transpiler.into_datapack();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -104,13 +105,14 @@ where
 | 
				
			||||||
pub fn compile<F, P>(
 | 
					pub fn compile<F, P>(
 | 
				
			||||||
    printer: &Printer,
 | 
					    printer: &Printer,
 | 
				
			||||||
    file_provider: &F,
 | 
					    file_provider: &F,
 | 
				
			||||||
 | 
					    pack_format: u8,
 | 
				
			||||||
    script_paths: &[(String, P)],
 | 
					    script_paths: &[(String, P)],
 | 
				
			||||||
) -> Result<VFolder>
 | 
					) -> Result<VFolder>
 | 
				
			||||||
where
 | 
					where
 | 
				
			||||||
    F: FileProvider,
 | 
					    F: FileProvider,
 | 
				
			||||||
    P: AsRef<Path>,
 | 
					    P: AsRef<Path>,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    let datapack = transpile(printer, file_provider, script_paths)?;
 | 
					    let datapack = transpile(printer, file_provider, pack_format, script_paths)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    tracing::info!("Compiling the source code.");
 | 
					    tracing::info!("Compiling the source code.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,7 @@ fn transpile_test1() {
 | 
				
			||||||
    let mut dir = VFolder::new();
 | 
					    let mut dir = VFolder::new();
 | 
				
			||||||
    dir.add_file("test1.shu", VFile::Text(source.to_string()));
 | 
					    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");
 | 
					        .expect("Failed to transpile");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let expected = {
 | 
					    let expected = {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue