angle brackets

This commit is contained in:
Jana Dönszelmann 2026-04-02 10:40:13 +02:00
parent 049132b6ee
commit 43e40b61e3
No known key found for this signature in database
3 changed files with 30 additions and 6 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "logparse"
version = "0.1.1"
version = "0.1.2"
edition = "2024"
description = "parse arbitrary messages containing rust-like debug output to syntax highlight them"
authors = ["Jana Dönszelmann <cratesio@donsz.nl>"]

View file

@ -264,7 +264,8 @@ impl<'a> Token<'a> {
Path::parse().map(Self::Path),
AnyString::parse().map(Self::String),
delimited,
Atom::parse(alt((Separator::parse().value(""), ")", "]", "}"))).map(Self::Atom),
Atom::parse(alt((Separator::parse().value(""), ")", "]", "}", ">")))
.map(Self::Atom),
)),
)
}
@ -313,13 +314,14 @@ impl<'a> Delimited<'a> {
"delimited",
(
opt((
Atom::parse(alt(("(", "[", "{", Separator::parse().value("")))),
Atom::parse(alt(("(", "[", "{", "<", Separator::parse().value("")))),
Space::parse(),
)),
alt((
literal('(').map(|_| literal(')').value(Delimiter::Paren)),
literal('[').map(|_| literal(']').value(Delimiter::Bracket)),
literal('{').map(|_| literal('}').value(Delimiter::Brace)),
literal('<').map(|_| literal('>').value(Delimiter::Angle)),
))
.flat_map(|end| Segments::parse(end)),
)

View file

@ -225,7 +225,17 @@ mod private {
match prefix {
Some((Atom::Text(text), space)) => {
cx.push(text, SpanKind::Constructor);
cx.push(
text,
match delimiter {
Delimiter::Bracket => SpanKind::Constructor,
Delimiter::Paren if space.0.is_empty() => SpanKind::Constructor,
Delimiter::Paren => SpanKind::Text,
Delimiter::Brace => SpanKind::Text,
Delimiter::Angle if space.0.is_empty() => SpanKind::Constructor,
Delimiter::Angle => SpanKind::Text,
},
);
space.into_spans(cx);
}
None => {}
@ -741,7 +751,13 @@ mod tests {
),
),
(
"<u32",
"<",
Delimiter(
0,
),
),
(
"u32",
Text,
),
(
@ -761,9 +777,15 @@ mod tests {
),
),
(
"Trait>",
"Trait",
Text,
),
(
">",
Delimiter(
0,
),
),
(
" ",
Space(