Expand description
Ritobin text format parser and writer for League Toolkit.
This crate provides functionality to parse and write the ritobin text format, which is a human-readable representation of League of Legends bin files.
§Quick start
Parse ritobin text, build a Bin, and round-trip it back to text:
use ltk_ritobin::{Cst, Print as _};
let text = r#"
#PROP_text
type: string = "PROP"
version: u32 = 3
linked: list[string] = { }
entries: map[hash, embed] = { }
"#.trim();
let cst = Cst::parse(text);
assert!(cst.errors.is_empty());
let partial = cst.build_bin(text);
assert!(partial.diagnostics.is_empty());
// Write back to text
let output = partial.bin.print().unwrap();
assert_eq!(text, output);§Converting .bin to ritobin
.bin files identify fields and types by FNV-1a hashes. Supplying a HashProvider
lets the printer emit the original names instead of 0xdeadbeef literals:
use std::io::BufReader;
use std::fs::File;
use ltk_meta::Bin;
use ltk_ritobin::{Print, print::PrintConfig, HashMapProvider};
let mut reader = BufReader::new(File::open("data.bin")?);
let bin = Bin::from_reader(&mut reader)?;
let mut hashes = HashMapProvider::new();
hashes.load_from_directory("hashes/"); // loads hashes.bin{entries,fields,hashes,types}.txt
let text = bin.print_with_config(PrintConfig::default().with_hashes(hashes))?;
std::fs::write("data.rito", text)?;§Error reporting
For resilient parsing, errors exist as nodes into the concrete syntax tree (cst), which propagate into the Nodes’ errors field (depending on parse::ErrorPropagation). This
allows for more versatile behaviour with things like pretty-printing technically invalid trees,
since parsing will always result in a cst.
The same handling of errors is done in the type-checker (when building a ltk_meta::Bin), to
always provide a best effort construction.
use ltk_ritobin::Cst;
let text = "test: u32 = 4!!2";
// by default uses ErrorPropagation::Move,
// so all errors will end up in the root
let cst = Cst::parse(text);
assert_eq!(cst.errors.len(), 1); // the unexpected "!!" in the valueCst::build_bin follows the same philosophy: it returns a ast::PartialBin, pairing a
best-effort Bin with any diagnostics, so type errors don’t prevent you from getting a
Bin back. This matters for editor use cases: between keystrokes a buffer is almost always
temporarily invalid, and tooling still needs to render it, navigate it, and report problems
with precise spans. Use ast::PartialBin::into_result where you instead want a Result that
only succeeds on a clean build.
§Patch files
A file whose type root is "PTCH" describes a patch bin. Its patches root holds one
patch embed per record, and its optional deleted root lists the objects it deletes.
Cst::build builds either kind of file as a ltk_meta::BinFile, and Print is
implemented for ltk_meta::BinOverride and ltk_meta::BinFile:
use ltk_meta::BinFile;
use ltk_ritobin::Cst;
let text = r#"
#PTCH_text
type: string = "PTCH"
version: u32 = 3
linked: list[string] = {}
entries: map[hash,embed] = {}
patches: map[hash,embed] = {
0x4a47c414 = patch {
path: string = "Position.Anchors.Anchor"
value: vec2 = { 0, 1 }
}
}
"#;
let (file, diagnostics) = Cst::parse(text).build(text);
assert!(diagnostics.is_empty());
let BinFile::Override(patch) = file else { unreachable!() };
assert_eq!(patch.patches.len(), 1);Re-exports§
pub use span::Span;pub use cst::Cst;pub use cst::Node;pub use print::Print;pub use hashes::*;pub use types::*;
Modules§
- ast
- cst
- Concrete Syntax Tree (CST)
- escaping
- hashes
- Hash provider traits and implementations for ritobin writing.
- parse
- Ritobin parser, tokenizer & other relevant types.
- Pretty printers for CSTs and Bins
- span
- Source spans and span-resolving debug output.
- types
- Type name mappings for ritobin format.
Macros§
- format_
to - rito
- Returns the
RitoTypenamed byltk_meta::PropertyKindvariants, at compile time.