diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f270a..cd37117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Macro strings - Function parameters/arguments +- Example: barebones compiler ### Changed diff --git a/examples/compiler.rs b/examples/compiler.rs new file mode 100644 index 0000000..b7fe1d7 --- /dev/null +++ b/examples/compiler.rs @@ -0,0 +1,30 @@ +//! This example demonstrates how to compile a shulkerscript file into a datapack using the shulkerscript compiler. +//! Most basic version of a shulkerscript compiler, which takes a single input file and places the resulting datapack in the specified output directory. +//! +//! For a ready-to-use compiler, see the `shulkerscript-cli` crate. + +use shulkerscript::{ + base::{FsProvider, PrintHandler}, + compile, +}; + +#[cfg(not(feature = "shulkerbox"))] +compile_error!("Need feature 'shulkerbox' to compile this example"); + +fn main() { + let mut args = std::env::args(); + let _ = args.next().unwrap(); + let input = args.next().expect("Expect path to shulkerscript file"); + + let output = args.next().expect("Expect path to output directory"); + + let code = compile( + &PrintHandler::new(), + &FsProvider::default(), + shulkerbox::datapack::Datapack::LATEST_FORMAT, + &[("main".to_string(), &input)], + ) + .expect("failed to compile"); + + code.place(output).expect("failed to place datapack"); +}