mirror of
https://github.com/danbulant/nushell
synced 2026-06-11 18:51:07 +00:00
Previously, there was a single parsing rule for "bare words" that applied to both internal and external commands. This meant that, because `cargo +nightly` needed to work, we needed to add `+` as a valid character in bare words. The number of characters continued to grow, and the situation was becoming untenable. The current strategy would eventually eat up all syntax and make it impossible to add syntax like `@foo` to internal commands. This patch significantly restricts bare words and introduces a new token type (`ExternalWord`). An `ExternalWord` expands to an error in the internal syntax, but expands to a bare word in the external syntax. `ExternalWords` are highlighted in grey in the shell.
55 lines
1.4 KiB
Rust
55 lines
1.4 KiB
Rust
use crate::parser::CallNode;
|
|
use crate::traits::ToDebug;
|
|
use crate::{Span, Tagged};
|
|
use derive_new::new;
|
|
use getset::Getters;
|
|
use std::fmt;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, new)]
|
|
pub struct Pipeline {
|
|
pub(crate) parts: Vec<PipelineElement>,
|
|
pub(crate) post_ws: Option<Span>,
|
|
}
|
|
|
|
impl ToDebug for Pipeline {
|
|
fn fmt_debug(&self, f: &mut fmt::Formatter, source: &str) -> fmt::Result {
|
|
for part in &self.parts {
|
|
write!(f, "{}", part.debug(source))?;
|
|
}
|
|
|
|
if let Some(post_ws) = self.post_ws {
|
|
write!(f, "{}", post_ws.slice(source))?
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Getters, new)]
|
|
pub struct PipelineElement {
|
|
pub pipe: Option<Span>,
|
|
pub pre_ws: Option<Span>,
|
|
#[get = "pub(crate)"]
|
|
call: Tagged<CallNode>,
|
|
pub post_ws: Option<Span>,
|
|
}
|
|
|
|
impl ToDebug for PipelineElement {
|
|
fn fmt_debug(&self, f: &mut fmt::Formatter, source: &str) -> fmt::Result {
|
|
if let Some(pipe) = self.pipe {
|
|
write!(f, "{}", pipe.slice(source))?;
|
|
}
|
|
|
|
if let Some(pre_ws) = self.pre_ws {
|
|
write!(f, "{}", pre_ws.slice(source))?;
|
|
}
|
|
|
|
write!(f, "{}", self.call.debug(source))?;
|
|
|
|
if let Some(post_ws) = self.post_ws {
|
|
write!(f, "{}", post_ws.slice(source))?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|