# AST Definition

This document describes the Abstract Syntax Tree structure used by Wasot. For the overall event-driven [architecture](./architecture.md), see the architecture document. For how this maps to XML, see the [data model](./wasot_and_xml.md). For the streaming event representation, see [events](./events.md).

This is the Pseudo Code of the AST-Definition:

```ast-pseudocode
Document = Metadata + Elements
Metadata = Map<String, String>
Elements = List<Element>
Element = Block | Text | ContextLine | VoidElement

Text = List<String> + List<List<Link>> + List<Footnote>
Block = MetaLine + Elements
ContextLine = MetaLine
VoidElement = MetaLine

MetaLine = TypeName + Level + Id? + InlineText? + Arguments + IsVoid
TypeName = String
Level = Integer                              # Number of dots (nesting depth)
Id = String                                  # Optional block ID (supports base36)
InlineText = QuotedString
IsVoid = Boolean                             # True for void elements (.hr:)

Arguments = List<PositionalArg> + List<KeywordArg>
PositionalArg = QuotedString
KeywordArg = QuotedString + QuotedString     # Key-value pair

QuotedString = String + Boolean + List<Link>
Link = Name? + Target? + TargetType + Arguments + StartIndex + Length

TargetType = Uri                             # External URL (https://, mailto:, etc.)
           | Id                              # Local ID reference within document
           | FootNote                        # Footnote reference (*1, *2, etc.)
           | IdInDocument(ExternalIdRef)     # Cross-document reference

ExternalIdRef = DocumentId + LocalId + DocumentPath?
Footnote = Marker + LinkContent              # Marker is u32, LinkContent is String
```

For more details on links, see [links](./links.md). For cross-document references, see [document_ids](./document_ids.md). For how [selectors](./selectors.md) match against this AST, see the selectors documentation.
