Skip to content

Commit 9b13126

Browse files
authored
Document some library functions (#1051)
* macros: Document missing functions * alterator: Document trait
1 parent 4303256 commit 9b13126

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/alterator.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
use crate::*;
22

3+
/// A trait to create a richer `AST` node for a programming language, mainly
4+
/// thought to be sent on the network.
35
pub trait Alterator
46
where
57
Self: Checker,
68
{
9+
/// Creates a new `AST` node containing the code associated to the node,
10+
/// its span, and its children.
11+
///
12+
/// This function can be overloaded according to the needs of each
13+
/// programming language.
714
fn alterate(node: &Node, code: &[u8], span: bool, children: Vec<AstNode>) -> AstNode {
815
Self::get_default(node, code, span, children)
916
}
1017

18+
/// Gets the code as text and the span associated to a node.
1119
fn get_text_span(node: &Node, code: &[u8], span: bool, text: bool) -> (String, Span) {
1220
let text = if text {
1321
String::from_utf8(code[node.start_byte()..node.end_byte()].to_vec()).unwrap()
@@ -26,11 +34,15 @@ where
2634
}
2735
}
2836

37+
/// Gets a default `AST` node containing the code associated to the node,
38+
/// its span, and its children.
2939
fn get_default(node: &Node, code: &[u8], span: bool, children: Vec<AstNode>) -> AstNode {
3040
let (text, span) = Self::get_text_span(node, code, span, node.child_count() == 0);
3141
AstNode::new(node.kind(), text, span, children)
3242
}
3343

44+
/// Gets a new `AST` node if and only if the code is not a comment,
45+
/// otherwise [`None`] is returned.
3446
fn get_ast_node(
3547
node: &Node,
3648
code: &[u8],

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ mod getter;
5252
mod macros;
5353

5454
mod alterator;
55-
pub(crate) use alterator::*;
55+
pub use alterator::*;
5656

5757
mod node;
5858
pub use crate::node::*;

src/macros.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ macro_rules! mk_lang {
7474
)*
7575
}
7676
impl LANG {
77+
/// Return an iterator over the supported languages.
78+
///
79+
/// # Examples
80+
///
81+
/// ```
82+
/// use rust_code_analysis::LANG;
83+
///
84+
/// for lang in LANG::into_enum_iter() {
85+
/// println!("{:?}", lang);
86+
/// }
87+
/// ```
7788
pub fn into_enum_iter() -> impl Iterator<Item=LANG> {
7889
use LANG::*;
7990
[$( $camel, )*].into_iter()

0 commit comments

Comments
 (0)