Skip to main content

kaydle_primitives/
lib.rs

1/*!
2This crate contains parsers and other low-level helper types for handling
3[KDL](https://kdl.dev/) documents. It is a complete but highly skeletal KDL
4implementation, suitable for use by KDL crate authors to provide higher level
5access to KDL data. Unless you're working on a KDL implementation, you should
6probably not be using this crate.
7*/
8
9#![deny(missing_docs)]
10
11use nom::{branch::alt, error::ParseError, IResult, Parser};
12use nom_supreme::{
13    tag::{complete::tag, TagError},
14    ParserExt,
15};
16
17pub mod annotation;
18pub mod node;
19pub mod number;
20pub mod property;
21pub mod string;
22mod util;
23pub mod value;
24pub mod whitespace;
25
26/// Parse the string `null`
27pub fn parse_null<'i, E>(input: &'i str) -> IResult<&'i str, (), E>
28where
29    E: TagError<&'i str, &'static str>,
30{
31    tag("null").value(()).parse(input)
32}
33
34/// Parse a `true` or `false`
35pub fn parse_bool<'i, E>(input: &'i str) -> IResult<&'i str, bool, E>
36where
37    E: ParseError<&'i str>,
38    E: TagError<&'i str, &'static str>,
39{
40    alt((tag("true").value(true), tag("false").value(false))).parse(input)
41}