vmf_parser_nom 0.1.1

A parser for the Valve map format.
Documentation
  • Coverage
  • 72.73%
    16 out of 22 items documented2 out of 3 items with examples
  • Size
  • Source code size: 31.68 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.6 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 16s Average build duration of successful builds.
  • all releases: 16s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • RedRam567/vmf_parser_nom
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • RedRam567

vmf_parser_nom

A parser for the Valve map format written in Rust. Also a provided convience macro for iterating over subblocks using the traversal crate.

Vmf Format

Read more about the vmf format on Valve Developer Community

// This is a comment.
ClassName_1
{
	"Property_1" "Value_1"
	"Property_2" "Value_2"
	ClassName_2
	{
		"Property_1" "Value_1"
	}
	ClassName_3
	{
	}
}

Example

use vmf_parser_nom::ast::{Block};
use vmf_parser_nom::parse;
use vmf_parser_nom::{VerboseError, SimpleError, ErrorKind};

let input = "ClassName_1
{
\t\"Property_1\" \"Value_1\"
\t\"Property_2\" \"Value_2\"
\tClassName_2
\t{
\t\t\"Property_1\" \"Value_1\"
\t}
\tClassName_3
\t{
\t}
}";

// parse the input to a vmf, borrowing from input
let vmf = parse::<&str, ()>(input).unwrap();
let string = vmf.to_string();
println!("vmf {vmf}")
assert_eq!(input, string);

// parse to owned strings instead
let vmf_owned = parse::<String, ()>(input).unwrap();

// All valid error types
let invalid_input = "block{\"property_with_no_value\"}";
let err_verbose = parse::<&str, VerboseError<_>>(invalid_input).unwrap_err();
let err_simple = parse::<&str, SimpleError<_>>(invalid_input).unwrap_err();
let err_tuple = parse::<&str, (_, ErrorKind)>(invalid_input).unwrap_err();
let err_unit = parse::<&str, ()>(invalid_input).unwrap_err();

println!("verbose: {err_verbose:?}");
println!("simple: {err_simple:?}");
println!("tuple: {err_tuple:?}");
println!("unit: {err_unit:?}");

// implements Deref
let block: &Block<String> = &vmf_owned;
assert_eq!(vmf_owned.inner, *block);

// inner value is simply a block with no properties
assert_eq!(vmf_owned.inner.name, "root");
assert_eq!(vmf_owned.inner.props, vec![]);
assert!(!vmf_owned.inner.blocks.is_empty());