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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use ;
/// Returns the first child of a specific typed node type.
///
/// Searches through the children of the parent node and returns the first child
/// that can be successfully cast to the specified node type `N`.
///
/// # Type Parameters
///
/// - `N`: The typed [`CstNode`] type to search for
///
/// # Examples
///
/// ```rust,ignore
/// use tokit::cst::cast;
///
/// // Find the first identifier child
/// if let Some(identifier) = cast::child::<IdentifierNode>(&function_syntax) {
/// println!("Function name: {}", identifier.source_string());
/// }
///
/// // Find the first expression in a statement
/// let expr = cast::child::<Expression>(&statement_syntax)?;
/// ```
/// Returns an iterator over all children of a specific typed node type.
///
/// Iterates through all children of the parent node, yielding only those that
/// can be successfully cast to the specified node type `N`.
///
/// # Type Parameters
///
/// - `N`: The typed [`Node`] type to iterate over
///
/// # Examples
///
/// ```rust,ignore
/// use tokit::cst::cast;
///
/// // Get all parameters of a function
/// let parameters: Vec<Parameter> = cast::children(&function_syntax).collect();
///
/// // Count the number of statements in a block
/// let statement_count = cast::children::<Statement>(&block_syntax).count();
///
/// // Find the first parameter with a specific name
/// let param = cast::children::<Parameter>(&function_syntax)
/// .find(|p| p.name() == "self");
/// ```
/// Returns the first token child with the specified syntax kind.
///
/// Searches through all tokens (not nodes) that are direct children of the parent
/// and returns the first one matching the specified kind.
///
/// # Type Parameters
///
/// - `L`: The [`Language`] type defining syntax kinds
///
/// # Examples
///
/// ```rust,ignore
/// use tokit::cst::cast;
///
/// // Get the equals token from an assignment
/// let equals = cast::token(&assignment_node, &SyntaxKind::Equals)?;
///
/// // Get the opening parenthesis of a function call
/// let lparen = cast::token(&call_node, &SyntaxKind::LeftParen)?;
///
/// // Check if a node has a specific keyword
/// if let Some(async_kw) = cast::token(&function_node, &SyntaxKind::AsyncKeyword) {
/// println!("Function is async");
/// }
/// ```