The shape of the tree a macro reads and returns - one type per construct on Syntax, each with the methods it's read through. A macro gets a tree when its input is typed as one of these - an Ast.Expression or Ast.Block for a body, the definition itself for a derive or attribute macro, the whole Ast.Program for a program macro - and #comptime.program() hands the same tree to any macro or #comptime(...) code. See Writing macros for how they're used.
Nodes are grouped by unions - Ast.Statement, Ast.Expression, Ast.Definition, ... - and told apart with match, as in case Ast.If as node then .... Every node also has the methods of Ast.Node: its span(), its children(), toSource(), and from Typecheck on, typeOf(). Comments, whitespace and grouping parentheses aren't in the tree - a macro that needs them takes Tokens instead.
#ast-nodeWhat every node has, whatever its kind: where it is, the nodes directly under it and every one below, itself written back out as source, and - from Typecheck on - its type.
#astBuilding trees: parse reads source as a node of the kind asked for, literal turns a value into the expression that writes it, and splitPlaceholders cuts a string macro's text at its #{ } placeholders.
#ast-pieceOne piece of a string macro's text, from Ast.splitPlaceholders: plain text, or a placeholder's expression.
SyntaxString Macro
#spanA stretch of source - where a node, token or macro use is. An error's with value can be one, to point the compile error there.
#ast-definitionEvery kind of definition, and what they all have: a name, attributes, whether it's local or global, and from Analyze on, its type.
SyntaxDefine, Inline Definition
One ofAst.Statement
MembersAst.Function, Ast.Method, Ast.Struct, Ast.Enum, Ast.Union, Ast.Interface, Ast.Const, Ast.TypeAlias, Ast.Macro, Ast.ContextDeclaration
#ast-statementEverything a block can hold - definitions, implement blocks and plain expressions included - and the attributes written above it.
SyntaxStatement
MembersAst.Let, Ast.Set, Ast.Inject, Ast.Reject, Ast.If, Ast.For, Ast.Match, Ast.Break, Ast.Continue, Ast.Yield, Ast.Return, Ast.Defer, Ast.Error, Ast.Definition, Ast.Implement, Ast.Expression
#ast-expressionEverything that gives a value. A type is an expression too - a parameter's : Type is an Ast.Expression, parsed the same way.
SyntaxValue Expression, Type Expression, Condition Expression
One ofAst.Statement
MembersAst.Word, Ast.Number, Ast.String, Ast.Boolean, Ast.Path, Ast.Symbol, Ast.Context, Ast.MacroInvocation, Ast.MacroWithBody, Ast.StringMacro, Ast.Binary, Ast.Prefix, Ast.Postfix, Ast.Chain, Ast.Call, Ast.Index, Ast.BraceCall, Ast.GenericInstantiation, Ast.Lambda, Ast.InlineIf, Ast.Match, Ast.Root, Ast.Tuple, Ast.List, Ast.Block
#ast-patternWhat a parameter or let binds its value to: a name, or the pieces of a struct, tuple or list.
SyntaxArgument Destructuring
MembersAst.NamePattern, Ast.StructPattern, Ast.TuplePattern, Ast.ListPattern
#ast-matchpatternWhat a match case tests its subject against.
SyntaxMatch Case
MembersAst.WildcardPattern, Ast.NamePattern, Ast.LiteralPattern, Ast.TypePattern, Ast.CasePattern, Ast.ErrorPattern
#ast-programThe whole program - what a program macro takes and #comptime.program() returns. find<Kind>(where) is how a macro picks what to work on.
#ast-attributeOne @name(...) above a definition, statement, parameter or match case.
SyntaxAttributes
#ast-visibilityThe local or global in front of a top-level definition, if any.
SyntaxDefine
#ast-functionA function, with its body. withBody gives the same function with another body - what an attribute macro wrapping a function returns.
SyntaxFunction Definition, Function Declaration
One ofAst.Definition
#ast-methodA method - a function with the type it's for.
SyntaxMethod Definition, Method Declaration
One ofAst.Definition
#ast-structA struct: the fields and consts written in it, and the structs it combines with &&.
SyntaxStruct Definition
One ofAst.Definition
#ast-fieldOne field of a struct or of a struct-shaped enum case.
SyntaxField Definition
#ast-enumAn enum: the cases written in it, and the enums it combines with ||.
SyntaxEnum Definition
One ofAst.Definition
#ast-enumcaseOne case of an enum - empty, carrying values, or carrying fields.
SyntaxEnum Definition
#ast-unionAn untagged union and its member types.
SyntaxUnion Definition
One ofAst.Definition
#ast-interfaceAn interface and the signatures it declares.
SyntaxInterface Definition
One ofAst.Definition
#ast-declarationA function or method signature with no body - what an interface lists.
SyntaxFunction Declaration, Method Declaration
#ast-constA named constant - at the top level, inside a block, or inside a struct.
SyntaxConst Definition
One ofAst.Definition
#ast-contextdeclarationA context name: Type - the type of a context value, and its default if it has one. Only at the top of a file.
SyntaxContext Definition
One ofAst.Definition
#ast-typealiasA type Name := ... - a new name for a type expression.
SyntaxType Definition
One ofAst.Definition
#ast-macroAn implement macro - its kind and phase are in its attributes.
SyntaxImplement a Macro
One ofAst.Definition
#ast-implementAn implement Interface for Target block and the functions and methods in it.
SyntaxImplement an Interface, Implement Statement
One ofAst.Statement
#ast-parameterOne parameter, or one generic parameter between < >.
SyntaxArguments Declaration
#ast-namepatternA plain name - binds the whole value.
SyntaxArgument Destructuring, Match Case
One ofAst.Pattern, Ast.MatchPattern
#ast-patternelementOne element of a struct, tuple or list pattern - x, or x as y.
SyntaxArgument Destructuring
#ast-structpattern{x, y as py} - binds fields by name, with at most one ...rest for the remaining fields.
SyntaxArgument Destructuring
One ofAst.Pattern
#ast-tuplepattern(a, b) - binds a tuple's elements by position, with at most one ...rest.
SyntaxArgument Destructuring
One ofAst.Pattern
#ast-listpattern[first, ...rest] - binds a list's elements by position, with at most one ...rest.
SyntaxArgument Destructuring
One ofAst.Pattern
#ast-wildcardpattern_ - matches anything, binds nothing.
SyntaxMatch Case
One ofAst.MatchPattern
#ast-literalpatternA value to compare the subject with, like case 404.
SyntaxMatch Case
One ofAst.MatchPattern
#ast-typepatterncase Todo as todo - matches by type, and binds the value as that type.
SyntaxMatch Case
One ofAst.MatchPattern
#ast-casepatternAn enum case or struct, with patterns for what it carries - case Text(t), case Circle{radius}.
SyntaxMatch Case
One ofAst.MatchPattern
#ast-errorpatterncase Error(e) with detail - matches an errored value.
SyntaxMatch Case
One ofAst.MatchPattern
#ast-blockStatements in { } - a body, a branch, or an expression of its own.
SyntaxBlock
One ofAst.Expression
#ast-setReassigning something that exists - set x := v, or a compound set x += v.
SyntaxSet
One ofAst.Statement
#ast-injectInjects a value under a name for the rest of the block.
SyntaxInject
One ofAst.Statement
#ast-rejectRemoves this block's own injected value for a name.
SyntaxReject
One ofAst.Statement
#ast-ifA condition and one or two branches - an else if's else branch is another Ast.If.
SyntaxIf
One ofAst.Statement
#ast-loopmodifierOne of a loop's while, until, if or skipping conditions.
SyntaxFor
#ast-matchA subject and the cases it's tried against, in order - a statement, or an expression where a value is wanted.
SyntaxMatch
One ofAst.Statement, Ast.Expression
#ast-matchcaseOne case: a pattern, an optional guard, and what runs.
SyntaxMatch Case
#ast-continueSkips to the next iteration of the loop named by its item.
SyntaxContinue
One ofAst.Statement
#ast-deferAn expression to run when the block ends.
SyntaxDefer
One ofAst.Statement
#ast-errorLeaves the function with an error, and optionally a value with it.
SyntaxError
One ofAst.Statement
#ast-wordA name - a bare one, or a backtick-quoted one like `adds two numbers`, without its backticks.
SyntaxWord Reference
One ofAst.Expression
#ast-numberA number, as written and as the value it's worth.
SyntaxNumber Literal
One ofAst.Expression
#ast-stringA string, as written and as the text it stands for.
SyntaxString Literal
One ofAst.Expression
#ast-pathA path in backticks - `/folder/name`, `../folder/name`. A backtick-quoted name that isn't one is an Ast.Word.
SyntaxPath Reference
One ofAst.Expression
#ast-symbolAn operator as a value, like (+).
SyntaxSymbol Literal
One ofAst.Expression
#ast-contextAn injected value read by name, like &env.
SyntaxContext Reference
One ofAst.Expression
#ast-macroinvocationA macro used with no body, like #line.
SyntaxMacro Invocation
One ofAst.Expression
#ast-macrowithbodyA macro with a {{{ }}} body, like #SQL. Before its macro runs; after, the tree holds what it returned.
SyntaxMacro With Body
One ofAst.Expression
#ast-stringmacroA macro applied to a string, like #format"...". Before its macro runs; after, the tree holds what it returned.
SyntaxString Macro
One ofAst.Expression
#ast-binaryTwo operands and the infix operator between them - member access a.b included.
SyntaxBinary Operation
One ofAst.Expression
#ast-prefixAn operator before its operand, like -x.
SyntaxPrefix Operation
One ofAst.Expression
#ast-postfixAn operator after its operand, like x!.
SyntaxPostfix Operation
One ofAst.Expression
#ast-chainChained comparisons like a < b < c, kept as one node.
SyntaxOperator Chain
One ofAst.Expression
#ast-callA call, with its type arguments and guard if written.
SyntaxCall
One ofAst.Expression
#ast-indexAn index, in brackets or as a subscript.
SyntaxIndex Access
One ofAst.Expression
#ast-guardThe ?, ! or !? between a callee and its ( or [.
SyntaxCall, Index Access
#ast-bracecallConstructing a struct, like Point{1, 2}.
SyntaxBrace Call
One ofAst.Expression
#ast-genericinstantiationType arguments with no call after them, like Array<Int>.
SyntaxGeneric Instantiation
One ofAst.Expression
#ast-argumentOne argument at a call site - by position, or by name.
SyntaxCall Arguments
#ast-inlineifif condition then a else b written where a value is wanted.
SyntaxInline If
One ofAst.Expression
#ast-rootA root, of degree 2 unless a subscript says otherwise.
SyntaxRoot
One ofAst.Expression
#ast-elisionA bare ... standing for the elements left out of a list.
SyntaxList Literal