diff --git a/src/alterator.rs b/src/alterator.rs index a7b307e22..172ed9b99 100644 --- a/src/alterator.rs +++ b/src/alterator.rs @@ -1,13 +1,21 @@ use crate::*; +/// A trait to create a richer `AST` node for a programming language, mainly +/// thought to be sent on the network. pub trait Alterator where Self: Checker, { + /// Creates a new `AST` node containing the code associated to the node, + /// its span, and its children. + /// + /// This function can be overloaded according to the needs of each + /// programming language. fn alterate(node: &Node, code: &[u8], span: bool, children: Vec<AstNode>) -> AstNode { Self::get_default(node, code, span, children) } + /// Gets the code as text and the span associated to a node. fn get_text_span(node: &Node, code: &[u8], span: bool, text: bool) -> (String, Span) { let text = if text { String::from_utf8(code[node.start_byte()..node.end_byte()].to_vec()).unwrap() @@ -26,11 +34,15 @@ where } } + /// Gets a default `AST` node containing the code associated to the node, + /// its span, and its children. fn get_default(node: &Node, code: &[u8], span: bool, children: Vec<AstNode>) -> AstNode { let (text, span) = Self::get_text_span(node, code, span, node.child_count() == 0); AstNode::new(node.kind(), text, span, children) } + /// Gets a new `AST` node if and only if the code is not a comment, + /// otherwise [`None`] is returned. fn get_ast_node( node: &Node, code: &[u8], diff --git a/src/lib.rs b/src/lib.rs index 2f09d8af6..2b96a4dd5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,7 +53,7 @@ mod macros; mod getter; mod alterator; -pub(crate) use alterator::*; +pub use alterator::*; mod node; pub use crate::node::*; diff --git a/src/macros.rs b/src/macros.rs index c14740191..6adf0138a 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -74,6 +74,17 @@ macro_rules! mk_lang { )* } impl LANG { + /// Return an iterator over the supported languages. + /// + /// # Examples + /// + /// ``` + /// use rust_code_analysis::LANG; + /// + /// for lang in LANG::into_enum_iter() { + /// println!("{:?}", lang); + /// } + /// ``` pub fn into_enum_iter() -> impl Iterator<Item=LANG> { use LANG::*; [$( $camel, )*].into_iter()