move and turn into spans
This commit is contained in:
parent
bedaa49754
commit
9f401bda53
13 changed files with 1262 additions and 774 deletions
176
src/format_debug_output/display.rs
Normal file
176
src/format_debug_output/display.rs
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
use super::ast::*;
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
impl Display for Separator {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Separator::Eq => write!(f, "="),
|
||||
Separator::Colon => write!(f, ":"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for QuoteType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
QuoteType::Single => write!(f, "\'"),
|
||||
QuoteType::Double => write!(f, "\""),
|
||||
QuoteType::Backtick => write!(f, "`"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Delimiter {
|
||||
fn fmt_start(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Delimiter::Paren => write!(f, "("),
|
||||
Delimiter::Bracket => write!(f, "["),
|
||||
Delimiter::Brace => write!(f, "{{"),
|
||||
Delimiter::Angle => write!(f, "<"),
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_end(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Delimiter::Paren => write!(f, ")"),
|
||||
Delimiter::Bracket => write!(f, "]"),
|
||||
Delimiter::Brace => write!(f, "}}"),
|
||||
Delimiter::Angle => write!(f, ">"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for AnyString<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.prefix)?;
|
||||
for _ in 0..self.num_hashtags {
|
||||
write!(f, "#")?;
|
||||
}
|
||||
write!(f, "{}", self.ty)?;
|
||||
write!(f, "{}", self.contents)?;
|
||||
write!(f, "{}", self.ty)?;
|
||||
|
||||
for _ in 0..self.num_hashtags {
|
||||
write!(f, "#")?;
|
||||
}
|
||||
write!(f, "{}", self.suffix)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for Space<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for PathSep {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
PathSep::Slash => write!(f, "/"),
|
||||
PathSep::Backslash => write!(f, "\\"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for PathSegment<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.leading_separator)?;
|
||||
write!(f, "{}", self.segment)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for FileLocation<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, ":{}", self.line)?;
|
||||
if let Some(offset) = &self.offset {
|
||||
write!(f, ":{offset}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for FileName<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.leading_separator)?;
|
||||
write!(f, "{}", self.segment)?;
|
||||
if let Some(ext) = &self.ext_excluding_dot {
|
||||
write!(f, ".{ext}")?;
|
||||
}
|
||||
if let Some(loc) = &self.location {
|
||||
write!(f, "{loc}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for Path<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if let Some(drive) = &self.drive_excluding_colon {
|
||||
write!(f, "{drive}:")?;
|
||||
}
|
||||
for segment in &self.segments {
|
||||
write!(f, "{segment}")?;
|
||||
}
|
||||
write!(f, "{}", self.filename)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for Number<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for Atom<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Atom::Text(text) => write!(f, "{text}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for Token<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Token::Number(number) => write!(f, "{number}"),
|
||||
Token::True => write!(f, "true"),
|
||||
Token::False => write!(f, "false"),
|
||||
Token::None => write!(f, "None"),
|
||||
Token::Atom(atom) => write!(f, "{atom}"),
|
||||
Token::Path(path) => write!(f, "{path}"),
|
||||
Token::Separated {
|
||||
before,
|
||||
space_before,
|
||||
separator,
|
||||
after,
|
||||
} => write!(f, "{before}{space_before}{separator}{after}"),
|
||||
Token::Delimited(delimited) => write!(f, "{delimited}"),
|
||||
Token::String(s) => write!(f, "{s}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for Delimited<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.prefix)?;
|
||||
self.delimiter.fmt_start(f)?;
|
||||
write!(f, "{}", self.contents)?;
|
||||
self.delimiter.fmt_end(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for Segment<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.leading_space)?;
|
||||
write!(f, "{}", self.token)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Display for Segments<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
for segment in &self.segments {
|
||||
write!(f, "{segment}")?;
|
||||
}
|
||||
write!(f, "{}", self.trailing_space)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue