Node trait is used to represent nodes such as tokens or function definitions in the full-moon AST. This trait is sealed and cannot be implemented for types outside of full-moon.
Trait Definition
Methods
start_position
None if the position cannot be determined.
end_position
None if the position cannot be determined.
similar
tokens
range
(start_position, end_position). Returns None if either position cannot be determined.
surrounding_trivia
(leading_trivia, trailing_trivia).
Tokens Iterator
TheTokens type is an iterator returned by Node::tokens():
Tokens iterator is double-ended, allowing iteration from both the start and end of the token sequence.
Implementations
TheNode trait is implemented for many types in full-moon:
Ast- The complete ASTTokenReference- Individual tokensBox<T>whereT: Node&TwhereT: Node&mut TwhereT: NodeOption<T>whereT: NodeVec<T>whereT: Node(A, B)whereA: Node, B: Node- All AST node types (e.g.,
FunctionDeclaration,LocalAssignment, etc.)
Example: Getting Node Position
Example: Comparing Nodes
Example: Accessing Surrounding Trivia
Example: Iterating Over Tokens
Use Cases
TheNode trait is useful for:
- Position tracking: Finding where code elements appear in source
- Semantic comparison: Comparing AST structures without position data
- Token access: Getting all tokens that make up a node
- Trivia analysis: Accessing comments and whitespace around nodes
- Range calculation: Determining the span of code elements
- Generic AST traversal: Writing code that works with any node type
See Also
Visitor- Trait for visiting nodes immutablyVisitorMut- Trait for visiting nodes mutablyPosition- Represents a position in source codeTokenReference- Represents a token with trivia