WikitextEx.AST (WikitextEx v0.1.1)

View Source

Abstract Syntax Tree (AST) structure for WikitextEx parser.

This module defines the AST node structure and all the specific node types that represent different wikitext elements. Each AST node has:

  • type: An atom indicating the kind of element (:text, :template, :link, etc.)
  • value: Type-specific data stored in structured format
  • children: List of nested AST nodes for container elements

Example

%WikitextEx.AST{
  type: :template,
  value: %WikitextEx.AST.Template{name: "cite", args: [...]},
  children: []
}

Node Types

The parser produces these AST node types:

  • Text elements: :text
  • Structure: :header, :list_item, :table, :table_row, :table_cell
  • Formatting: :bold, :italic
  • Links: :link, :category, :file, :interlang_link
  • Templates: :template
  • HTML: :html_tag, :comment, :ref, :nowiki

Summary

Functions

Extract text content from AST children, useful for headers and other containers.

Types

Functions

text_content(children)

Extract text content from AST children, useful for headers and other containers.

Examples

iex> children = [
...>   %WikitextEx.AST{type: :text, value: %WikitextEx.AST.Text{content: "Hello"}, children: []},
...>   %WikitextEx.AST{type: :text, value: %WikitextEx.AST.Text{content: " World"}, children: []}
...> ]
iex> WikitextEx.AST.text_content(children)
"Hello World"

iex> node = %WikitextEx.AST{type: :text, value: %WikitextEx.AST.Text{content: "Single text"}, children: []}
iex> WikitextEx.AST.text_content(node)
"Single text"

iex> bold_node = %WikitextEx.AST{
...>   type: :bold,
...>   value: nil,
...>   children: [%WikitextEx.AST{type: :text, value: %WikitextEx.AST.Text{content: "Bold text"}, children: []}]
...> }
iex> WikitextEx.AST.text_content(bold_node)
"Bold text"