lib_ruby_parser_ast/nodes/types/
if_ternary.rs

1// This file is autogenerated by codegen/node_file.liquid
2
3use crate::nodes::InnerNode;
4use crate::nodes::InspectVec;
5use crate::Loc;
6use crate::Node;
7
8/// Represents ternary `if` statement (i.e. `cond ? if_true : if_false`)
9#[derive(Debug, Clone, PartialEq)]
10#[repr(C)]
11pub struct IfTernary {
12    /// Condition of the `if` statement
13    pub cond: Box<Node>,
14
15    /// True-branch
16    pub if_true: Box<Node>,
17
18    /// True-branch
19    pub if_false: Box<Node>,
20
21    /// Location of the `?` operator
22    ///
23    /// ```text
24    /// cond ? if_true : if_false
25    ///      ~
26    /// ```
27    pub question_l: Loc,
28
29    /// Location of the `:` operator
30    ///
31    /// ```text
32    /// cond ? if_true : if_false
33    ///                ~
34    /// ```
35    pub colon_l: Loc,
36
37    /// Location of the full expression
38    ///
39    /// ```text
40    /// cond ? if_true : if_false
41    /// ~~~~~~~~~~~~~~~~~~~~~~~~~
42    /// ```
43    pub expression_l: Loc,
44
45}
46
47impl InnerNode for IfTernary {
48    fn expression(&self) -> &Loc {
49        &self.expression_l
50    }
51
52    fn inspected_children(&self, indent: usize) -> Vec<String> {
53        let mut result = InspectVec::new(indent);
54        result.push_node(&self.cond);
55        result.push_node(&self.if_true);
56        result.push_node(&self.if_false);
57        
58        result.strings()
59    }
60
61    fn str_type(&self) -> &'static str {
62        "if"
63    }
64
65    fn print_with_locs(&self) {
66        println!("{}", self.inspect(0));
67        self.cond.inner_ref().print_with_locs();
68        self.if_true.inner_ref().print_with_locs();
69        self.if_false.inner_ref().print_with_locs();
70        self.question_l.print("question");
71        self.colon_l.print("colon");
72        self.expression_l.print("expression");
73        
74    }
75}