#nom #parser #half-life #quake #file-format #gamedev

nomap

Quake 1 & 2以及Half-Life 1使用的.map文件格式的解析器,使用nom解析框架实现

4个版本

0.2.1 2021年6月29日
0.2.0 2020年8月19日
0.1.1 2020年4月7日
0.1.0 2020年4月6日

#1816 in 解析器实现

MIT/Apache

40KB
1K SLoC

Docs License

nomap

Quake 1 & 2以及Half-Life 1使用的.map文件格式的解析器,使用nom解析框架实现。它可以轻松地与其他nom解析器集成。

nomap不区分空白字符,并忽略注释。它还可选地为其所有类型提供Display实现(通过"display"特性),因此您可以序列化解析的地图回字符串。

示例

// parse the example map with the standard format
let map = nomap::parse::<nomap::formats::Standard>(include_str!("../examples/example.map")).unwrap();

// report our findings
for ent in map.entities.iter() {
    println!(
        "Found entity of class `{}` with {} brush{}",
        // every entity should have this, so we optimistically index here
        ent.fields["classname"],
        ent.brushes.len(),
        // some fanciness
        if ent.brushes.len() == 1 { "" } else { "es" }
    )
}

依赖项

~1MB
~19K SLoC