11use crate :: * ;
22
3+ /// A trait to create a richer `AST` node for a programming language, mainly
4+ /// thought to be sent on the network.
35pub trait Alterator
46where
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 ] ,
0 commit comments