mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-31 12:21:19 -03:00
committed by
Johannes Altmanninger
parent
532f30e031
commit
7aec6c55f9
23
src/ast.rs
23
src/ast.rs
@@ -437,8 +437,8 @@ fn cast(node: &dyn Node) -> Option<&Self> {
|
||||
}
|
||||
|
||||
/// Implement the leaf trait.
|
||||
macro_rules! implement_leaf {
|
||||
( $name:ident ) => {
|
||||
macro_rules! Leaf {
|
||||
($name:ident) => {
|
||||
impl Leaf for $name {
|
||||
fn range(&self) -> Option<SourceRange> {
|
||||
self.range
|
||||
@@ -459,17 +459,20 @@ fn accept_mut<V: NodeVisitorMut>(&mut self, visitor: &mut V) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
( $(#[$_m:meta])* $_v:vis struct $name:ident $_:tt $(;)? ) => {
|
||||
Leaf!($name);
|
||||
};
|
||||
}
|
||||
|
||||
/// Define a node that implements the keyword trait.
|
||||
macro_rules! define_keyword_node {
|
||||
( $name:ident, $($allowed:ident),* $(,)? ) => {
|
||||
#[derive(Default, Debug)]
|
||||
#[derive(Default, Debug, Leaf!)]
|
||||
pub struct $name {
|
||||
range: Option<SourceRange>,
|
||||
keyword: ParseKeyword,
|
||||
}
|
||||
implement_leaf!($name);
|
||||
impl Node for $name {
|
||||
fn kind(&self) -> Kind<'_> {
|
||||
Kind::Keyword(self)
|
||||
@@ -498,7 +501,7 @@ fn as_leaf(&self) -> &dyn Leaf {
|
||||
/// Define a node that implements the token trait.
|
||||
macro_rules! define_token_node {
|
||||
( $name:ident, $($allowed:ident),* $(,)? ) => {
|
||||
#[derive(Default, Debug)]
|
||||
#[derive(Default, Debug, Leaf!)]
|
||||
pub struct $name {
|
||||
range: Option<SourceRange>,
|
||||
parse_token_type: ParseTokenType,
|
||||
@@ -511,7 +514,6 @@ fn kind_mut(&mut self) -> KindMut<'_> {
|
||||
KindMut::Token(self)
|
||||
}
|
||||
}
|
||||
implement_leaf!($name);
|
||||
impl Token for $name {
|
||||
fn token_type(&self) -> ParseTokenType {
|
||||
self.parse_token_type
|
||||
@@ -1080,11 +1082,10 @@ pub struct FreestandingArgumentList {
|
||||
define_list_node!(CaseItemList, CaseItem);
|
||||
|
||||
/// A variable_assignment contains a source range like FOO=bar.
|
||||
#[derive(Default, Debug, Node!)]
|
||||
#[derive(Default, Debug, Node!, Leaf!)]
|
||||
pub struct VariableAssignment {
|
||||
range: Option<SourceRange>,
|
||||
}
|
||||
implement_leaf!(VariableAssignment);
|
||||
impl CheckParse for VariableAssignment {
|
||||
fn can_be_parsed(pop: &mut Populator<'_>) -> bool {
|
||||
// Do we have a variable assignment at all?
|
||||
@@ -1106,19 +1107,17 @@ fn can_be_parsed(pop: &mut Populator<'_>) -> bool {
|
||||
}
|
||||
|
||||
/// Zero or more newlines.
|
||||
#[derive(Default, Debug, Node!)]
|
||||
#[derive(Default, Debug, Node!, Leaf!)]
|
||||
pub struct MaybeNewlines {
|
||||
range: Option<SourceRange>,
|
||||
}
|
||||
implement_leaf!(MaybeNewlines);
|
||||
|
||||
/// An argument is just a node whose source range determines its contents.
|
||||
/// This is a separate type because it is sometimes useful to find all arguments.
|
||||
#[derive(Default, Debug, Node!)]
|
||||
#[derive(Default, Debug, Node!, Leaf!)]
|
||||
pub struct Argument {
|
||||
range: Option<SourceRange>,
|
||||
}
|
||||
implement_leaf!(Argument);
|
||||
impl CheckParse for Argument {
|
||||
fn can_be_parsed(pop: &mut Populator<'_>) -> bool {
|
||||
pop.peek_type(0) == ParseTokenType::string
|
||||
|
||||
Reference in New Issue
Block a user