Nasty.Rendering.PrettyPrint (Nasty v0.3.0)
View SourcePretty printing for AST nodes to aid debugging and visualization.
Provides human-readable string representations of AST structures with proper indentation and highlighting of key information.
Examples
iex> Nasty.Rendering.PrettyPrint.print(document)
"""
Document (:en)
Paragraph
Sentence (declarative, simple)
Clause (independent)
Subject: NounPhrase
Det: "the"
Head: "cat" [noun]
Predicate: VerbPhrase
Head: "sat" [verb]
"""
iex> Nasty.Rendering.PrettyPrint.tree(document)
"""
Document
├── Paragraph
│ └── Sentence
│ └── Clause
│ ├── NounPhrase
│ │ ├── Token: the
│ │ └── Token: cat
│ └── VerbPhrase
│ └── Token: sat
"""
Summary
Functions
Pretty prints an AST node with indentation.
Prints summary statistics about an AST.
Pretty prints an AST node as a tree with box-drawing characters.
Types
@type options() :: [ indent: pos_integer(), max_depth: pos_integer() | nil, show_spans: boolean(), show_metadata: boolean(), color: boolean() ]
Pretty print options.
:indent- Number of spaces per indent level (default: 2):max_depth- Maximum depth to print (default: nil = unlimited):show_spans- Whether to show position spans (default: false):show_metadata- Whether to show node metadata (default: false):color- Whether to use ANSI colors (default: false)
Functions
Pretty prints an AST node with indentation.
Examples
iex> Nasty.Rendering.PrettyPrint.print(document)
"Document (:en)\n Paragraph\n ..."
iex> Nasty.Rendering.PrettyPrint.print(document, indent: 4, max_depth: 2)
"Document (:en)\n Paragraph\n ..."
Prints summary statistics about an AST.
Examples
iex> Nasty.Rendering.PrettyPrint.stats(document)
"""
AST Statistics:
Paragraphs: 3
Sentences: 12
Clauses: 15
Tokens: 127
Noun Phrases: 18
Verb Phrases: 15
"""
Pretty prints an AST node as a tree with box-drawing characters.
Examples
iex> Nasty.Rendering.PrettyPrint.tree(document)
"""
Document
├── Paragraph
│ └── Sentence
│ └── Clause
"""