Header parsing
This library is meant to help with parsing markdown inspired files, where headers are marked by a sequence of "#".
The only function parse_header is meant to be used when parsing a file line by line.
If the line starts with a "#", the function will return Some result to indicate if it's a valid format, else it will return None.
The only invalid format is when a header starts with more than one "#" more than the previous header.
This makes using markdown like formats viable for config files.
Example config
Headers and subheaders are stored as array.
For example you could have a file like this:
A
B
C
D
E
F
G
The letters would belong to different headers:
Abelongs to no subheader ([])Bbelongs to "Header 1" (["Header 1"])Cbelongs to "Subheader 1" of "Header 1" (["Header 1", "Subheader 1"])Dbelongs to "Subheader 2" of "Header 1" (["Header 1", "Subheader 2"])Ebelongs to "Header 2" (["Header 2"])Fbelongs to "Subheader 1" of "Header 2" (["Header 2", "Subheader 1"])Gbelongs to "Subheader 2" of "Header 2" (["Header 2", "Subheader 2"])
Usage
You have to store the path of headers and subheader yourself. This way, you are allowed to handle the sections inbetween the headers as you want.
use parse_header;
use ;