Skip to content

Commit

Permalink
improve parse_key_value
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Sep 5, 2023
1 parent d42004a commit 5c9a408
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn parse_tag_text(input: &str) -> nom::IResult<&str, Option<EventData>> {
fn parse_tag_meta(input: &str) -> nom::IResult<&str, Option<EventData>> {
preceded(
tag("meta"),
map(parse_key_value, |kv| {
map(preceded(space1, parse_key_value), |kv| {
kv.map(|(k, v)| EventData::Meta(k.to_string(), v.to_string()))
}),
)(input)
Expand Down Expand Up @@ -523,14 +523,16 @@ fn parse_tail(input: &str) -> nom::IResult<&str, &str> {
}

fn parse_key_value(input: &str) -> nom::IResult<&str, Option<(&str, &str)>> {
let input = input.trim_end();
let key_value = alt((
map(
separated_pair(parse_name, char('='), parse_default_value),
separated_pair(parse_name, char('='), terminated(parse_default_value, eof)),
|(key, value)| Some((key, value)),
),
map(parse_name, |key| Some((key, ""))),
map(terminated(parse_name, eof), |key| Some((key, ""))),
));
preceded(space1, alt((key_value, success(None))))(input)

alt((key_value, success(None)))(input)
}

fn parse_name_list(input: &str) -> nom::IResult<&str, Vec<&str>> {
Expand Down

0 comments on commit 5c9a408

Please sign in to comment.