31 releases
4.0.0-alpha.33 | May 20, 2022 |
---|---|
4.0.0-alpha.32 |
|
4.0.0-alpha.29 | Jan 31, 2022 |
4.0.0-alpha.22 | Apr 27, 2021 |
0.0.0 |
|
#101 in Template engine
580KB
13K
SLoC
Rant is a dynamically-typed, multi-paradigm templating language designed primarily for procedural generation. It is designed with scalability in mind: it can handle tasks ranging from simple randomized string generation to more complex workloads such as procedural dialogue, character generation, and worldbuilding.
Prerelease notice
This project is in alpha. This means that the API is unstable, functionality may be broken/missing, and everything is subject to change.
Please dont hesitate to try it out and give feedback; however, do not use in production environments until a stable version is released.
Features may appear/disappear at any time for any reason. Assume that every alpha release will have breaking changes.
Introducing Rant 4
Rant is the result of a long-standing desire for an all-in-one data templating tool made especially for creative applications like games and interactive art.
Rant 4 is the next leap forward in achieving this goal: the syntax, standard library, and interpreter have all been completely reimagined from the ground up.
Features
๐งฐ Painless API
Rant has a no-nonsense API designed for ease of use.
No getting lost in configuration hell. Integrating Rant into your project only takes a few lines of code.
๐ป Cross-platform
Write once, run anywhere! The runtime works the same across Windows, Mac, Linux, and WebAssembly.
โ Templating that does more
Rant is all about "printing": each lexical scope has an output to print (append values) to, which then prints itself to the parent output, and so on.
This enables you to intuitively build strings, collections, and more in a familiar templating setting.
๐จ Now intentionally Turing-complete!
In addition to being a templating language, Rant adopts declarative and imperative programming concepts with design influences from many other popular languages.
โจ Generate anything โ not just text
Unlike older Rant versions that could only generate strings, Rant 4 can output arbitrary data structures using any of the built-in data types. Enjoy first-class support for common primitives like strings, numbers, collections, closures, and more.
๐ฒ Built with โฅ for RNG
Rant is made with random generation in mind as a major use-case.
Make use of a wide array of built-in utilities for generating random numbers, strings, booleans, lists, list subsets, and much more for all your randomization needs. The internal RNG can be manually seeded to produce repeatable outputs.
๐ฑ Branching and beyond
Augment regular control flow behavior with a multitude of configuration options for iterative, randomized, and weighted branch selection.
๐งฌ Delightful combinatorics
Perform nested mappings, filters, zips, combinations, and more with minimal effort.
Rant's powerful piping syntax lets you perform complex operations with shorter, more readable code.
๐ Automatic text formatting
Passively format text output with automatic capitalization, whitespace normalization, and number formatting โ including built-in support for numerous writing systems.
๐ฆ Data sources
Attach custom data sources to your Rant execution context to give your scripts controlled access to external resources.
๐งฉ Simple module system
Sharing code between Rant programs is trivial. Just write your module script and @require
it elsewhere.
Need custom module resolution logic? No problem. You can write your own resolver and just plug it in.
๐ Rant Standard Library
A comprehensive standard library provides the tools needed to quickly iterate on your ideas.
๐งช Use integrated or standalone
Whether you want to integrate Rant directly into a product or use it as a standalone tool to assist with writing, Rant has a place in any part of your workflow.
Getting started
Rant is written in Rust, so you'll need to install the toolchain in order to build it.
CLI
Rant's CLI can run Rant code from files or the command line. Install it from Cargo with:
$ cargo install rant --version 4.0.0-alpha.33 --features cli
Then run it:
# Launch the REPL
$ rant
# Get a full list of options
$ rant -h
# Run an inline script and display output
$ rant -e '[rep:3] [sep:\s] {b{ee|i|o|u}bbity}'
# Run hello_world.rant and send output to result.txt
$ rant hello_world.rant > result.txt
Library
To use Rant in a Rust project, add the rant
crate to Cargo.toml
:
[dependencies]
rant = "*"
You can run a Rant program with just a few lines of code:
use rant::Rant;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
// Create a default Rant context
let mut rant = Rant::new();
// Compile a simple program
let program = rant.compile_quiet(r#"
[$greet:name] {
{Hello|Hi|Hey} <name>!
}
[greet:world]
"#)?;
// Run the program and print the output
let output = rant.run(&program)?;
println!("{}", output);
Ok(())
}
Examples
This repository includes a collection of example Rant scripts for you to learn from. Check them out!
Documentation
The latest reference documentation can be found at docs.rant-lang.org.
Since Rant 4 is early in development, some documentation may be outdated/incomplete, but it is actively updated to ensure that it reflects current features with reasonable accuracy.
Changelog
The changelog is updated constantly throughout the development process, providing a complete summary of upcoming changes at a glance even before the next release.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Dependencies
~3โ11MB
~79K SLoC