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 module declaration using `module` keyword
#[derive(Debug, Clone, PartialEq)]
pub struct Module {
    /// Name of the module
    pub name: Node,
    /// Body of the module
    ///
    /// `None` if module has no body
    pub body: Option<Node>,
    /// Location of the `module` keyword
    ///
    /// ```text
    /// module M; end
    /// ~~~~~~
    /// ```
    pub keyword_l: Range,
    /// Location of the `end` keyword
    ///
    /// ```text
    /// module M; end
    ///           ~~~
    /// ```
    pub end_l: Range,
    /// Location of the full expression
    ///
    /// ```text
    /// module M; end
    /// ~~~~~~~~~~~~~
    /// ```
    pub expression_l: Range,
}


impl InnerNode for Module {
    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.name);
        result.push_maybe_node_or_nil(&self.body);
        result.strings()
    }

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

    fn print_with_locs(&self) {
        println!("{}", self.inspect(0));
        self.expression_l.print("expression");
        self.end_l.print("end");
        self.keyword_l.print("keyword");
        if let Some(node) = &self.body {
            node.inner_ref().print_with_locs();
        }
        self.name.inner_ref().print_with_locs();
    }
}