lib-ruby-parser 0.7.0

Ruby parser
Documentation
use crate::nodes::InnerNode;
use crate::nodes::InspectVec;
use crate::source::Range;
use crate::Node;
/// Represents `foo && bar` (or `foo and bar`) statement.
#[derive(Debug, Clone, PartialEq)]
pub struct And {
    /// Left hand statament of the `&&` operation.
    ///
    /// `Lvar("foo")` node for `foo && bar`
    pub lhs: Node,
    /// Right hand statement of the `&&` operation.
    ///
    /// `Lvar("bar")` node for `foo && bar`
    pub rhs: Node,
    /// Location of the `&&` (or `and`) operator
    ///
    /// ```text
    /// a && b
    ///   ~~
    /// ```
    pub operator_l: Range,
    /// Location of the full expression
    ///
    /// ```text
    /// a && b
    /// ~~~~~~
    /// ```
    pub expression_l: Range,
}


impl InnerNode for And {
    fn expression(&self) -> &Range {
        &self.expression_l
    }

    fn inspected_children(&self, indent: usize) -> Vec<String> {
        let mut result = InspectVec::new(indent);
        result.push_node(&self.lhs);
        result.push_node(&self.rhs);
        result.strings()
    }

    fn str_type(&self) -> &'static str {
        "and"
    }

    fn print_with_locs(&self) {
        println!("{}", self.inspect(0));
        self.expression_l.print("expression");
        self.operator_l.print("operator");
        self.rhs.inner_ref().print_with_locs();
        self.lhs.inner_ref().print_with_locs();
    }
}