databind/lib.rs
1/*
2 * Databind - Expand the functionality of Minecraft Datapacks.
3 * Copyright (C) 2021 Adam Thompson-Sharpe
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18//! Expand the functionality of Minecraft Datapacks.
19//!
20//! ## CLI
21//!
22//! If you're just looking to use Databind as a tool and not to make your own
23//! Rust project with it, then you can use the CLI. Documentation for it is
24//! available [here](https://databind.rtfd.io/en/stable).
25//!
26//! ## Quick Start
27//!
28//! Here's some code to compile a given string and print the output
29//! for each file:
30//!
31//! ```rust
32//! use databind::compiler::{Compiler, macros::Macro};
33//! use std::collections::HashMap;
34//!
35//! fn main() {
36//! // Databind source file
37//! let source_file = "
38//! func main\n\
39//! say Hello, World!\n\
40//! end\n\
41//! func second_func\n\
42//! say Second function\n\
43//! end"
44//! .to_string();
45//!
46//! // Keep track of global macros
47//! let mut macros: HashMap<String, Macro> = HashMap::new();
48//!
49//! // Compiled
50//! let compiled = Compiler::compile(&source_file, "", None, &mut macros)
51//! .expect("Compilation failed");
52//!
53//! // Print the contents of each file
54//! for (file, contents) in compiled.files.iter() {
55//! println!("Output File: {}.mcfunction", file);
56//! println!("Contents:\n{}", contents);
57//! println!("----------");
58//! }
59//! }
60//! ```
61//!
62//! The code above results in the following output:
63//!
64//! ```text
65//! Output File: main.mcfunction
66//! Contents:
67//! # Compiled with MysteryBlokHed/databind
68//! say Hello, World!
69//! ----------
70//! Output File: second_func.mcfunction
71//! Contents:
72//! # Compiled with MysteryBlokHed/databind
73//! say Second function
74//! ----------
75//! ```
76#![warn(clippy::all)]
77#[macro_use]
78extern crate pest_derive;
79
80pub mod ast;
81pub mod compiler;
82pub mod files;
83mod settings;
84pub use settings::Settings;
85
86// Trigger CI