Nasty.Utils.Validator (Nasty v0.3.0)
View SourceAST validation utilities for ensuring structural consistency.
Validates that AST nodes conform to expected schemas and that the tree structure is internally consistent.
Examples
iex> Nasty.Utils.Validator.validate(document)
{:ok, document}
iex> Nasty.Utils.Validator.validate(malformed_node)
{:error, "Invalid node structure: ..."}
Summary
Functions
Checks if an AST node is valid.
Validates an AST node and all its descendants.
Validates an AST node, raising on error.
Validates language consistency throughout the tree.
Validates that spans are consistent throughout the tree.
Functions
Checks if an AST node is valid.
Examples
iex> Nasty.Utils.Validator.valid?(document)
true
iex> Nasty.Utils.Validator.valid?(malformed_node)
false
Validates an AST node and all its descendants.
Returns {:ok, node} if valid, or {:error, reason} if invalid.
Examples
iex> Nasty.Utils.Validator.validate(document)
{:ok, document}
iex> Nasty.Utils.Validator.validate(invalid_node)
{:error, "Document language must be an atom"}
Validates an AST node, raising on error.
Examples
iex> Nasty.Utils.Validator.validate!(document)
document
iex> Nasty.Utils.Validator.validate!(invalid_node)
** (RuntimeError) Invalid AST: Document language must be an atom
Validates language consistency throughout the tree.
Ensures all nodes have the same language marker.
Examples
iex> Nasty.Utils.Validator.validate_language(document)
:ok
Validates that spans are consistent throughout the tree.
Checks that:
- Parent spans contain all child spans
- Spans don't overlap incorrectly
- Byte offsets match positions
Examples
iex> Nasty.Utils.Validator.validate_spans(document)
:ok