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 `BEGIN { ... }` statement
#[derive(Debug, Clone, PartialEq)]
pub struct Preexe {
    /// Body of the block
    pub body: Option<Node>,
    /// Location of the `BEGIN` keyword
    ///
    /// ```text
    /// BEGIN { 42 }
    /// ~~~~~
    /// ```
    pub keyword_l: Range,
    /// Location of the open parenthesis
    ///
    /// ```text
    /// BEGIN { 42 }
    ///       ~
    /// ```
    pub begin_l: Range,
    /// Location of the closing parenthesis
    ///
    /// ```text
    /// BEGIN { 42 }
    ///            ~
    /// ```
    pub end_l: Range,
    /// Location of the full expression
    ///
    /// ```text
    /// BEGIN { 42 }
    /// ~~~~~~~~~~~~
    /// ```
    pub expression_l: Range,
}


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

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

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

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