lib_ruby_parser_ast/nodes/types/sym.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::Bytes;
7
8/// Represents a plain symbol literal (i.e. `:foo`)
9///
10/// Note that `:` in `{ foo: bar }` belongs to a `pair` node.
11#[derive(Debug, Clone, PartialEq)]
12#[repr(C)]
13pub struct Sym {
14 /// Value of the symbol literal
15 ///
16 /// Note that it's a `StringValue`, not a `String`.
17 /// The reason is that you can get UTF-8 incompatible strings
18 /// from a valid UTF-8 source using escape sequences like `"\xFF"`
19 ///
20 /// These "\", "x", "F", "F" chars are valid separately, but together
21 /// they construct a char with code = 255 that is invalid for UTF-8.
22 ///
23 /// You can use `to_string_lossy` or `to_string` methods to get a raw symbol value.
24 pub name: Bytes,
25
26 /// Location of the symbol begin
27 ///
28 /// ```text
29 /// :foo
30 /// ~
31 /// ```
32 ///
33 /// `None` if symbol is a label (`{ foo: 1 }`) or a part of the symbols array (`%i[foo bar baz]`)
34 pub begin_l: Option<Loc>,
35
36 /// Location of the symbol end
37 ///
38 /// ```text
39 /// { 'foo': 1 }
40 /// ~
41 /// ```
42 ///
43 /// `None` if symbol is **not** a string label (`:foo`) or a part of the symbols array (`%i[foo bar baz]`)
44 pub end_l: Option<Loc>,
45
46 /// Location of the full expression
47 ///
48 /// ```text
49 /// :foo
50 /// ~~~~
51 ///
52 /// { foo: 1 }
53 /// ~~~~
54 ///
55 /// %i[foo]
56 /// ~~~
57 /// ```
58 pub expression_l: Loc,
59
60}
61
62impl InnerNode for Sym {
63 fn expression(&self) -> &Loc {
64 &self.expression_l
65 }
66
67 fn inspected_children(&self, indent: usize) -> Vec<String> {
68 let mut result = InspectVec::new(indent);
69 result.push_string_value(&self.name);
70
71 result.strings()
72 }
73
74 fn str_type(&self) -> &'static str {
75 "sym"
76 }
77
78 fn print_with_locs(&self) {
79 println!("{}", self.inspect(0));
80 if let Some(loc) = self.begin_l.as_ref() { loc.print("begin") }
81 if let Some(loc) = self.end_l.as_ref() { loc.print("end") }
82 self.expression_l.print("expression");
83
84 }
85}