lib_ruby_parser_ast/nodes/types/c_send.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 conditional method call using `&.` operator
9#[derive(Debug, Clone, PartialEq)]
10#[repr(C)]
11pub struct CSend {
12 /// Receiver of the method call, `Int("1")` for `1&.foo`
13 pub recv: Box<Node>,
14
15 /// Name of the method, `String("foo")` for `1&.foo`
16 pub method_name: String,
17
18 /// List of arguments
19 ///
20 /// ```text
21 /// foo&.bar(42)
22 /// # and also setters like
23 /// foo&.bar = 42
24 /// ```
25 pub args: Vec<Node>,
26
27 /// Location of the `&.` operator
28 ///
29 /// ```text
30 /// foo&.bar
31 /// ~~
32 /// ```
33 pub dot_l: Loc,
34
35 /// Location of the method name
36 ///
37 /// ```text
38 /// foo&.bar(42)
39 /// ~~~
40 /// ```
41 ///
42 /// `None` in a very special case when method call is implicit (i.e. `foo&.()`)
43 pub selector_l: Option<Loc>,
44
45 /// Location of the open parenthesis
46 ///
47 /// ```text
48 /// foo&.bar(42)
49 /// ~
50 /// ```
51 ///
52 /// `None` if there are no parentheses
53 pub begin_l: Option<Loc>,
54
55 /// Location of the closing parenthesis
56 ///
57 /// ```text
58 /// foo&.bar(42)
59 /// ~
60 /// ```
61 ///
62 /// `None` if there are no parentheses
63 pub end_l: Option<Loc>,
64
65 /// Location of the operator if `CSend` is a part of assignment like
66 ///
67 /// ```text
68 /// foo&.bar = 1
69 /// ~
70 /// ```
71 ///
72 /// `None` for a regular call.
73 pub operator_l: Option<Loc>,
74
75 /// Location of the full expression
76 ///
77 /// ```text
78 /// foo&.bar(42)
79 /// ~~~~~~~~~~~~
80 /// ```
81 pub expression_l: Loc,
82
83}
84
85impl InnerNode for CSend {
86 fn expression(&self) -> &Loc {
87 &self.expression_l
88 }
89
90 fn inspected_children(&self, indent: usize) -> Vec<String> {
91 let mut result = InspectVec::new(indent);
92 result.push_node(&self.recv);
93 result.push_str(&self.method_name);
94 result.push_nodes(&self.args);
95
96 result.strings()
97 }
98
99 fn str_type(&self) -> &'static str {
100 "csend"
101 }
102
103 fn print_with_locs(&self) {
104 println!("{}", self.inspect(0));
105 self.recv.inner_ref().print_with_locs();
106 for node in self.args.iter() { node.inner_ref().print_with_locs(); }
107 self.dot_l.print("dot");
108 if let Some(loc) = self.selector_l.as_ref() { loc.print("selector") }
109 if let Some(loc) = self.begin_l.as_ref() { loc.print("begin") }
110 if let Some(loc) = self.end_l.as_ref() { loc.print("end") }
111 if let Some(loc) = self.operator_l.as_ref() { loc.print("operator") }
112 self.expression_l.print("expression");
113
114 }
115}