Skip to content

Commit

Permalink
Fix #151 - expand id parsing (#152)
Browse files Browse the repository at this point in the history
Current parsing is a bit inflexible, improve parsing to include more.
  • Loading branch information
jsuereth authored May 9, 2024
1 parent 5eb7a59 commit 69c45d8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/weaver_semconv_gen/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ fn parse_markdown_gen_parameters(input: &str) -> IResult<&str, Vec<MarkdownGenPa

/// nom parser for semconv ids.
fn parse_id(input: &str) -> IResult<&str, &str> {
recognize(many0_count(alt((alpha1, tag("."), tag("_"), tag("-")))))(input)
recognize(pair(
alpha1, // First character must be alpha, then anything is accepted.
many0_count(alt((alphanumeric1, tag("."), tag("_"), tag("-")))),
))(input)
}

/// nom parser for <!-- semconv {id}({args}) -->
Expand Down Expand Up @@ -134,6 +137,9 @@ mod tests {
assert!(is_markdown_snippet_directive(
"<!-- semconv registry.user_agent -->"
));
assert!(is_markdown_snippet_directive(
"<!-- semconv registry.user_agent.p99 -->"
));
assert!(is_markdown_snippet_directive(
"<!-- semconv my.id(full) -->"
));
Expand Down

0 comments on commit 69c45d8

Please sign in to comment.