#config-parser #markdown-parser #config #header #hierarchy #parser #markdown

header-config

Runtime parser for hierarchical configurations using Markdown-style headers

6 releases

Uses new Rust 2024

new 0.1.5 Mar 28, 2025
0.1.4 Mar 4, 2025
0.1.2 Feb 25, 2025
0.1.1 Dec 21, 2024

#1272 in Parser implementations

Download history 257/week @ 2024-12-17 43/week @ 2024-12-24 30/week @ 2024-12-31 29/week @ 2025-01-07 3/week @ 2025-01-14 26/week @ 2025-02-11 5/week @ 2025-02-18 168/week @ 2025-02-25 230/week @ 2025-03-04 12/week @ 2025-03-11 2/week @ 2025-03-18

412 downloads per month

MIT/Apache

7KB
70 lines

Header Config Parser

Crates.io Docs.rs License

A Rust library for parsing hierarchical configuration files using Markdown-style headers, transforming nested sections into flat key-value pairs with namespaced keys.

Features

  • ๐Ÿ“‚ Header-based namespacing
  • โž• Automatic key hierarchy flattening
  • ๐Ÿงน Whitespace-tolerant parsing
  • ๐Ÿšฆ Empty value handling
  • ๐Ÿ” Simple string-based lookups

Installation

Add to your Cargo.toml:

[dependencies]
header-config = "0.1"

File Format Specification

Basic Syntax

# Server Config

port 8080
timeout 30

# Database

host localhost
user admin

## Replica

host replica.db

Key Features

  • Headers create namespaces using # symbols
  • Keys are whitespace-separated from values
  • Empty values allowed (key without value)
  • Nesting with subheaders (## Subsection)

Parsing Rules

  • Header levels determine namespace depth
  • It's not allowed to go more than one header level deeper at once
  • Keys inherit all parent header namespaces
  • Case-sensitive matching
  • Duplicates aren't allowed

Example

The format looks like this:

key1 value
key2

# HeaderA

key1 value
key2

# HeaderB

key1 value
key2

## SubheaderA

key1 value
key2

## SubheaderB

key1 value
key2

The created mapping will be something like this:

"key1" -> "value"
"key2" -> ""
"HeaderA:key1" -> "value"
"HeaderA:key2" -> ""
"HeaderB:key1" -> "value"
"HeaderB:key2" -> ""
"HeaderB:SubheaderA:key1" -> "value"
"HeaderB:SubheaderA:key2" -> ""
"HeaderB:SubheaderB:key1" -> "value"
"HeaderB:SubheaderB:key2" -> ""

Dependencies

~1โ€“1.6MB
~30K SLoC