Crate databind

Source
Expand description

Expand the functionality of Minecraft Datapacks.

§CLI

If you’re just looking to use Databind as a tool and not to make your own Rust project with it, then you can use the CLI. Documentation for it is available here.

§Quick Start

Here’s some code to compile a given string and print the output for each file:

use databind::compiler::{Compiler, macros::Macro};
use std::collections::HashMap;

fn main() {
    // Databind source file
    let source_file = "
    func main\n\
        say Hello, World!\n\
    end\n\
    func second_func\n\
        say Second function\n\
    end"
    .to_string();

    // Keep track of global macros
    let mut macros: HashMap<String, Macro> = HashMap::new();

    // Compiled
    let compiled = Compiler::compile(&source_file, "", None, &mut macros)
        .expect("Compilation failed");

    // Print the contents of each file
    for (file, contents) in compiled.files.iter() {
        println!("Output File: {}.mcfunction", file);
        println!("Contents:\n{}", contents);
        println!("----------");
    }
}

The code above results in the following output:

Output File: main.mcfunction
Contents:
# Compiled with MysteryBlokHed/databind
say Hello, World!
----------
Output File: second_func.mcfunction
Contents:
# Compiled with MysteryBlokHed/databind
say Second function
----------

Modules§

ast
Contains enums for the AST of Databind
compiler
files
Contains functions used by the CLI to get information from files or to create files

Structs§

Settings
Settings for the compiler