Crate kv3

Source
Expand description

§kv3

A Rust crate for parsing Valve’s KeyValues3 (KV3) format.

This crate provides functionality to parse and serialize the KeyValues3 format used by Valve in their games and tools.

§Features

  • Parsing: Convert KV3-formatted strings into Rust data structures.
  • Support for Comments: Handles single-line (//), multi-line (/* ... */), and XML-style (<!-- ... -->) comments.
  • Support for Multiline Strings: Parses multiline strings enclosed in triple double-quotes (""").
  • Handles Various Data Types: Supports booleans, integers, floats, strings, arrays, hex arrays, objects, and null values.
  • Customizable Parsing: Built using the nom parser combinator library for flexibility.

§Example

use kv3::parse_kv3;

let input = r#"
{
    // comment
    number = 5
    floating = 5.0
    array = []
    obj = {}
    string = "asd"
    multiLineStringValue = """
First line of a multi-line string literal.
Second line of a multi-line string literal.
"""
}
"#;

match parse_kv3(input) {
    Ok((_, kvs)) => {
        println!("Parsed KV3: {:#?}", kvs);
    }
    Err(e) => {
        eprintln!("Error parsing KV3: {:?}", e);
    }
}

§KeyValues3 Format

For more information about the KeyValues3 format, please refer to the Valve Developer Community Wiki.

§License

This project is licensed under the MIT License.

Modules§

kv3_serde

Structs§

KV3Object

Enums§

KV3Value

Functions§

parse_kv3