Parse comments in whitespace

This commit is contained in:
Joscha 2022-11-18 20:55:44 +01:00
parent a559966c1d
commit 41723eb4ca
2 changed files with 41 additions and 8 deletions

View file

@ -2,15 +2,25 @@ use std::fmt;
use crate::span::{HasSpan, Span};
#[derive(Clone)]
pub enum Line {
Empty,
Comment(String),
}
#[derive(Clone)]
pub struct Space {
pub comment: Vec<(String, Span)>,
pub lines: Vec<Line>,
pub span: Span,
}
impl fmt::Debug for Space {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Space").finish()
if self.lines.iter().any(|l| matches!(l, Line::Comment(_))) {
write!(f, "space with comments")
} else {
write!(f, "space")
}
}
}