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.
43 lines
1000 B
Rust
43 lines
1000 B
Rust
use crate::parser::TokenNode;
|
|
use crate::traits::ToDebug;
|
|
use getset::Getters;
|
|
use std::fmt;
|
|
|
|
#[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 ToDebug for CallNode {
|
|
fn fmt_debug(&self, f: &mut fmt::Formatter, 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(())
|
|
}
|
|
}
|