mirror of
https://github.com/nushell/nushell.git
synced 2025-05-19 06:04:35 +00:00
The original purpose of this PR was to modernize the external parser to use the new Shape system. This commit does include some of that change, but a more important aspect of this change is an improvement to the expansion trace. Previous commit 6a7c00ea adding trace infrastructure to the syntax coloring feature. This commit adds tracing to the expander. The bulk of that work, in addition to the tree builder logic, was an overhaul of the formatter traits to make them more general purpose, and more structured. Some highlights: - `ToDebug` was split into two traits (`ToDebug` and `DebugFormat`) because implementations needed to become objects, but a convenience method on `ToDebug` didn't qualify - `DebugFormat`'s `fmt_debug` method now takes a `DebugFormatter` rather than a standard formatter, and `DebugFormatter` has a new (but still limited) facility for structured formatting. - Implementations of `ExpandSyntax` need to produce output that implements `DebugFormat`. Unlike the highlighter changes, these changes are fairly focused in the trace output, so these changes aren't behind a flag.
43 lines
1.0 KiB
Rust
43 lines
1.0 KiB
Rust
use crate::parser::TokenNode;
|
|
use crate::traits::{DebugFormatter, FormatDebug, ToDebug};
|
|
use getset::Getters;
|
|
use std::fmt::{self, Write};
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
|
pub struct CallNode {
|
|
#[get = "pub(crate)"]
|
|
head: Box<TokenNode>,
|
|
#[get = "pub(crate)"]
|
|
children: Option<Vec<TokenNode>>,
|
|
}
|
|
|
|
impl CallNode {
|
|
pub fn new(head: Box<TokenNode>, children: Vec<TokenNode>) -> CallNode {
|
|
if children.len() == 0 {
|
|
CallNode {
|
|
head,
|
|
children: None,
|
|
}
|
|
} else {
|
|
CallNode {
|
|
head,
|
|
children: Some(children),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl FormatDebug for CallNode {
|
|
fn fmt_debug(&self, f: &mut DebugFormatter, source: &str) -> fmt::Result {
|
|
write!(f, "{}", self.head.debug(source))?;
|
|
|
|
if let Some(children) = &self.children {
|
|
for child in children {
|
|
write!(f, "{}", child.debug(source))?
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|