toml_edit 0.1.4

Yet another format-preserving TOML parser.
Documentation
use crate::decor::InternalString;
use crate::parser::strings::{basic_string, literal_string};
use combine::range::{recognize_with_value, take_while1};
use combine::stream::RangeStream;
use combine::*;

#[inline]
fn is_unquoted_char(c: char) -> bool {
    match c {
        'A'..='Z' | 'a'..='z' | '0'..='9' | '-' | '_' => true,
        _ => false,
    }
}

// unquoted-key = 1*( ALPHA / DIGIT / %x2D / %x5F ) ; A-Z / a-z / 0-9 / - / _
parse!(unquoted_key() -> &'a str, {
    take_while1(is_unquoted_char)
});

// key = unquoted-key / basic-string / literal-string
parse!(key() -> (&'a str, InternalString), {
    recognize_with_value(choice((
        basic_string(),
        literal_string().map(|s: &'a str| s.into()),
        unquoted_key().map(|s: &'a str| s.into()),
    )))
});