better parsing

This commit is contained in:
Jana Dönszelmann 2026-04-03 16:47:18 +02:00
parent bed1d5b38b
commit 53fc09c02f
No known key found for this signature in database
10 changed files with 416 additions and 45 deletions

View file

@ -25,8 +25,9 @@ pub enum SpanKind {
/// i.e. `Some` in `Some(3)`
Constructor,
/// String prefix, suffix, hashtags, etc
StringSurroundings,
/// String prefix, suffix, hashtags, etc.
/// Also number suffix
Surroundings,
/// Any other text (the default)
Text,
@ -114,9 +115,9 @@ mod private {
num_hashtags,
suffix,
} = self;
cx.push(prefix, SpanKind::StringSurroundings);
cx.push(prefix, SpanKind::Surroundings);
for _ in 0..num_hashtags {
cx.push("#", SpanKind::StringSurroundings)
cx.push("#", SpanKind::Surroundings)
}
ty.into_spans(cx);
@ -124,9 +125,9 @@ mod private {
ty.into_spans(cx);
for _ in 0..num_hashtags {
cx.push("#", SpanKind::StringSurroundings)
cx.push("#", SpanKind::Surroundings)
}
cx.push(suffix, SpanKind::StringSurroundings);
cx.push(suffix, SpanKind::Surroundings);
}
}
@ -138,7 +139,12 @@ mod private {
impl<'a> IntoSpansImpl<'a> for Number<'a> {
fn into_spans(self, cx: &mut Context<'a>) {
cx.push(self.0, SpanKind::Number)
cx.push(self.number, SpanKind::Number);
if let Some(suffix) = self.suffix_without_underscore {
cx.push("_", SpanKind::Surroundings);
cx.push(suffix, SpanKind::Surroundings);
}
}
}
@ -228,10 +234,10 @@ mod private {
cx.push(
text,
match delimiter {
Delimiter::Bracket => SpanKind::Constructor,
Delimiter::Brace => SpanKind::Constructor,
Delimiter::Paren if space.0.is_empty() => SpanKind::Constructor,
Delimiter::Paren => SpanKind::Text,
Delimiter::Brace => SpanKind::Text,
Delimiter::Bracket => SpanKind::Text,
Delimiter::Angle if space.0.is_empty() => SpanKind::Constructor,
Delimiter::Angle => SpanKind::Text,
},
@ -336,7 +342,7 @@ mod tests {
),
(
"unsized_coercion",
Constructor,
Text,
),
(
"[",
@ -398,7 +404,7 @@ mod tests {
),
(
"",
StringSurroundings,
Surroundings,
),
(
"\"",
@ -414,7 +420,7 @@ mod tests {
),
(
"",
StringSurroundings,
Surroundings,
),
(
")",
@ -476,7 +482,7 @@ mod tests {
),
(
"core",
Constructor,
Text,
),
(
"[",
@ -572,7 +578,7 @@ mod tests {
),
(
"core",
Constructor,
Text,
),
(
"[",
@ -670,7 +676,7 @@ mod tests {
),
(
"unsized_coercion",
Constructor,
Text,
),
(
"[",
@ -884,7 +890,7 @@ mod tests {
),
(
"alloc",
Constructor,
Text,
),
(
"[",