lib-ruby-parser-ast 0.55.0

AST for lib-ruby-parser
Documentation
// This file is autogenerated by codegen/node_file.liquid

use crate::nodes::InnerNode;
use crate::nodes::InspectVec;
use crate::Loc;
use crate::Node;

/// Represents optional positional argument (i.e. `foo` in `m(foo = 1)`)
#[derive(Debug, Clone, PartialEq)]
#[repr(C)]
pub struct Optarg {
    /// Name of the argument
    pub name: String,

    /// Default value of the argument
    pub default: Box<Node>,

    /// Location of the argument name
    ///
    /// ```text
    /// def m(foo = 1); end
    ///       ~~~
    /// ```
    pub name_l: Loc,

    /// Location of the `=` operator
    ///
    /// ```text
    /// def m(foo = 1); end
    ///           ~
    /// ```
    pub operator_l: Loc,

    /// Location of the full expression
    ///
    /// ```text
    /// def m(foo = 1); end
    ///       ~~~~~~~
    /// ```
    pub expression_l: Loc,

}

impl InnerNode for Optarg {
    fn expression(&self) -> &Loc {
        &self.expression_l
    }

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

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

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