Skip to main content

Module ast

Module ast 

Source
Expand description

Abstract Syntax Tree, layered on top of untyped SyntaxNodes

Modulesยง

edit
This module contains functions for editing syntax trees. As the trees are immutable, all function here return a fresh copy of the tree, instead of doing an in-place modification.
expr_ext ๐Ÿ”’
Various extension methods to ast Expr Nodes, which are hard to code-generate.
generated ๐Ÿ”’
This file is actually hand-written, but the submodules are indeed generated.
make
This module contains free-standing functions for creating AST fragments out of smaller pieces.
node_ext ๐Ÿ”’
Various extension methods to ast Nodes, which are hard to code-generate. Extensions for various expressions live in a sibling expr_extensions module.
operators ๐Ÿ”’
Defines a bunch of data-less enums for unary and binary operators.
prec
Precedence representation.
support ๐Ÿ”’
syntax_factory
Builds upon crate::ast::make constructors to create ast fragments with optional syntax mappings.
token_ext ๐Ÿ”’
There are many AstNodes, but only a few tokens, so we hand-write them here.
traits ๐Ÿ”’
Various traits that are implemented by ast nodes.

Structsยง

Abi
AnyComment
AnyHasArgList
AnyHasAttrs
AnyHasGenericArgs
AnyHasGenericParams
AnyHasLoopBody
AnyHasModuleItem
AnyHasName
AnyHasTypeBounds
AnyHasVisibility
ArgList
ArrayExpr
ArrayType
AsmClobberAbi
AsmConst
AsmDirSpec
AsmExpr
AsmLabel
AsmOperandExpr
AsmOperandNamed
AsmOption
AsmOptions
AsmRegOperand
AsmRegSpec
AsmSym
AssocItemList
AssocTypeArg
AstChildren
An iterator over SyntaxNode children of a particular AST type.
Attr
AttrsIter
AwaitExpr
BecomeExpr
BinExpr
BlockExpr
BoxPat
BreakExpr
Byte
ByteString
CString
CallExpr
CastExpr
CfgAtom
CfgAttrMeta
CfgComposite
CfgMeta
CfgPredExpr
CfgPredPat
Char
ClosureExpr
Comment
CommentKind
Const
ConstArg
ConstBlockPat
ConstParam
ContinueExpr
DerefPat
DocComment
DynTraitType
Enum
ExprStmt
ExternBlock
ExternCrate
ExternItemList
FieldExpr
FloatNumber
Fn
FnPtrType
ForBinder
ForExpr
ForType
FormatArgsArg
FormatArgsExpr
GenericArgList
GenericParamList
Ident
IdentPat
IfExpr
Impl
ImplRestriction
ImplTraitType
IncludeBytesExpr
IndexExpr
InferType
IntNumber
ItemList
KeyValueMeta
Label
LetElse
LetExpr
LetStmt
Lifetime
LifetimeArg
LifetimeParam
Literal
LiteralPat
LoopExpr
MacroCall
MacroDef
MacroExpr
MacroItems
MacroPat
MacroRules
MacroStmts
MacroType
MatchArm
MatchArmList
MatchExpr
MatchGuard
MethodCallExpr
Module
MutRestriction
Name
NameRef
NeverType
NotNull
OffsetOfExpr
OrPat
Param
ParamList
ParenExpr
ParenPat
ParenType
ParenthesizedArgList
Path
PathExpr
PathMeta
PathPat
PathSegment
PathType
PatternType
PrefixExpr
PtrType
QuoteOffsets
RangeExpr
RangePat
RecordExpr
RecordExprField
RecordExprFieldList
RecordField
RecordFieldList
RecordPat
RecordPatField
RecordPatFieldList
RefExpr
RefPat
RefType
Rename
RestPat
RetType
ReturnExpr
ReturnTypeSyntax
SelfParam
SlicePat
SlicePatComponents
SliceType
SourceFile
Static
StmtList
String
Struct
TokenTree
TokenTreeChildren
An iterator over the elements in an ast::TokenTree.
TokenTreeMeta
Trait
TryBlockModifier
TryExpr
TupleExpr
TupleField
TupleFieldList
TuplePat
TupleStructPat
TupleType
TypeAlias
TypeAnchor
TypeArg
TypeBound
TypeBoundList
TypeParam
UnderscoreExpr
Union
UnsafeMeta
Use
UseBoundGenericArgs
UseTree
UseTreeList
Variant
VariantList
Visibility
VisibilityInner
WhereClause
WherePred
WhileExpr
Whitespace
WildcardPat
YeetExpr
YieldExpr

Enumsยง

Adt
AnyAttr
AnyString
ArithOp
ArrayExprKind
AsmOperand
AsmPiece
AssocItem
AttrKind
BinaryOp
BlockModifier
CallableExpr
CfgAtomKey
CfgPredicate
CmpOp
CommentShape
ElseBranch
Expr
ExternItem
FieldKind
FieldList
GenericArg
GenericParam
Item
LiteralKind
LogicOp
Macro
Meta
NameLike
NameOrNameRef
Ordering
Pat
PathSegmentKind
Radix
RangeOp
SelfParamKind
Stmt
StructKind
Type
TypeBoundKind
TypeOrConstParam
UnaryOp
UseBoundGenericArg
VariantDef
VisibilityKind

Traitsยง

AstNode
The main trait to go from untyped SyntaxNode to a typed ast. The conversion itself has zero runtime cost: ast and syntax nodes have exactly the same representation: a pointer to the tree root and a pointer to the node itself.
AstToken
Like AstNode, but wraps tokens rather than interior nodes.
HasArgList
HasAttrs
HasGenericArgs
HasGenericParams
HasLoopBody
HasModuleItem
HasName
HasTypeBounds
HasVisibility
IsString
RangeItem
Trait to describe operations common to both RangeExpr and RangePat.

Functionsยง

attrs_including_inner
attrs_with_doc_including_inner
Returns all attributes of this node, including inner attributes that may not be directly under this node but under a child.