Skip to main content

throne/
lib.rs

1//! Throne is a scripting language for game prototyping and story logic.
2//!
3//! Documentation for learning the language itself can be found on [GitHub](https://github.com/t-mw/throne#reference).
4//!
5//! # Example
6//!
7//! ```
8//! use throne::{ContextBuilder, tokenize};
9//!
10//! // Write your script text inline or in an external file included with `include_str!(..)`
11//! let script = r#"
12//! Mary is sister of David
13//! Sarah is child of Mary
14//! Tom is child of David
15//!
16//! CHILD is child of PARENT . AUNT is sister of PARENT .
17//!     COUSIN is child of AUNT = COUSIN is cousin of CHILD
18//! "#;
19//!
20//! // Build the Throne context using your script text to define the initial state and rules
21//! let mut context = ContextBuilder::new()
22//!     .text(script)
23//!     .build()
24//!     .unwrap_or_else(|e| panic!("Failed to build Throne context: {}", e));
25//!
26//! // Execute an update step
27//! context.update().unwrap_or_else(|e| panic!("Throne context update failed: {}", e));
28//!
29//! // Fetch the updated state
30//! let state = context.core.state.get_all();
31//!
32//! // Convert a string to a Throne phrase
33//! let expected_state_phrase = tokenize("Sarah is cousin of Tom", &mut context.string_cache);
34//!
35//! assert_eq!(state, vec![expected_state_phrase]);
36//! ```
37
38#[macro_use]
39extern crate lazy_static;
40extern crate pest;
41#[macro_use]
42extern crate pest_derive;
43extern crate rand;
44extern crate regex;
45
46mod context;
47mod core;
48#[cfg(not(target_arch = "wasm32"))]
49mod ffi;
50mod matching;
51mod parser;
52mod rule;
53mod state;
54mod string_cache;
55#[cfg(test)]
56mod tests;
57pub mod token;
58mod update;
59#[cfg(target_arch = "wasm32")]
60mod wasm;
61
62pub use crate::context::{Context, ContextBuilder};
63pub use crate::core::Core;
64#[cfg(not(target_arch = "wasm32"))]
65#[doc(hidden)]
66pub use crate::ffi::*;
67pub use crate::rule::Rule;
68pub use crate::state::{PhraseId, State};
69pub use crate::string_cache::{Atom, StringCache};
70pub use crate::token::{tokenize, Phrase, PhraseGroup, PhraseString, Token};
71pub use crate::update::{update, SideInput};
72#[cfg(target_arch = "wasm32")]
73pub use crate::wasm::*;
74
75pub mod errors {
76    pub use crate::matching::ExcessivePermutationError;
77    pub use crate::parser::Error as ParserError;
78    pub use crate::update::{Error as UpdateError, RuleRepeatError};
79}