1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Binary format section primitives.
use super::ids::StringId;
/// Range into an array: [ptr..ptr+len).
///
/// Dual-use depending on context:
/// - For `TypeDef` wrappers (Optional, Array*): `ptr` is inner `TypeId`, `len` is 0.
/// - For `TypeDef` composites (Struct, Enum): `ptr` is index into TypeMember array, `len` is count.
#[derive(Clone, Copy, Debug, Default)]
#[repr(C)]
pub struct Slice {
pub ptr: u16,
pub len: u16,
}
impl Slice {
#[inline]
pub fn range(self) -> std::ops::Range<usize> {
let start = self.ptr as usize;
start..start + self.len as usize
}
}
/// Maps tree-sitter NodeTypeId to its string name.
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct NodeSymbol {
/// Tree-sitter node type ID
pub id: u16,
/// StringId for the node kind name
pub name: StringId,
}
impl NodeSymbol {
/// Create a new node symbol.
pub fn new(id: u16, name: StringId) -> Self {
Self { id, name }
}
}
/// Maps tree-sitter NodeFieldId to its string name.
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct FieldSymbol {
/// Tree-sitter field ID
pub id: u16,
/// StringId for the field name
pub name: StringId,
}
impl FieldSymbol {
/// Create a new field symbol.
pub fn new(id: u16, name: StringId) -> Self {
Self { id, name }
}
}
/// A node type ID that counts as trivia (whitespace, comments).
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct TriviaEntry {
pub node_type: u16,
}
impl TriviaEntry {
/// Create a new trivia entry.
pub fn new(node_type: u16) -> Self {
Self { node_type }
}
}