Documentation
¶
Overview ¶
Package ast defines the TDL parse tree, which mirrors source text 1:1 with names left unresolved. See docs/design/ir.md for the resolved model.
Index ¶
- func Dump(file *File) string
- func Fprint(file *File) string
- func PrintDecl(decl Decl) string
- func PrintTypeRef(t *TypeRef) string
- func PrintUnitExpr(e *UnitExpr) string
- type AliasDecl
- type AssocTypeBind
- type AssocTypeReq
- type ClassDecl
- type ClassRef
- type Comment
- type Constraint
- type Decl
- type DeclHead
- type Deprecation
- type Directive
- type EnumDecl
- type Field
- type File
- type FunDep
- type ImportDecl
- type Include
- type InstanceDecl
- type Kind
- type Literal
- type LiteralKind
- type Member
- type NewtypeDecl
- type PackageDecl
- type Position
- type PrimitiveDecl
- type StructDecl
- type TargetDecl
- type TargetEntry
- type TypeArg
- type TypeParam
- type TypeRef
- type UnitDecl
- type UnitExpr
- type UnitTerm
- type Variant
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dump ¶
Dump renders file as an indented tree, one node per line, with the source position of each. It is the output of `tdl ast`.
func Fprint ¶
Fprint renders file as canonical TDL source, the output of `tdl fmt`. Layout depends only on the tree and its comments, never on the input's whitespace, so formatting is idempotent.
func PrintDecl ¶ added in v0.2.8
PrintDecl renders one declaration in canonical form, without its doc comment, deprecation, or surrounding comments, as a hover shows it.
func PrintTypeRef ¶ added in v0.2.8
PrintTypeRef renders a type reference as the formatter writes it.
func PrintUnitExpr ¶ added in v0.1.4
PrintUnitExpr renders a unit expression without spaces around its operators: `kg*m/s^2`. Lowering uses it to record a unit's spelling.
Types ¶
type AssocTypeBind ¶
AssocTypeBind binds an associated type in an instance.
type AssocTypeReq ¶
AssocTypeReq is a `type Cursor` requirement in a class. Dep is always nil.
type ClassDecl ¶
type ClassDecl struct {
DeclHead
Params []*TypeParam
FunDeps []*FunDep
Conforms []*ClassRef // superclasses
Requires []*ClassRef
Members []Member
End Position // the body's `}`
}
ClassDecl is a class. Conformance to it is nominal and always declared.
type Comment ¶ added in v0.1.7
type Comment struct {
P Position
Text string // the text after the slashes, with one leading space removed
}
Comment is one ordinary `//` comment.
type Constraint ¶
Constraint is one entry in a `where { ... }` block. The set of names is open.
type DeclHead ¶
type DeclHead struct {
Doc []string
// DocP is where the doc comment was written, zero without one.
DocP Position
P Position
N string
Dep *Deprecation
}
DeclHead is the part every declaration shares.
type Deprecation ¶
Deprecation marks a declaration, field, or variant as deprecated.
type EnumDecl ¶
type EnumDecl struct {
DeclHead
Params []*TypeParam
Conforms []*ClassRef
Requires []*ClassRef
Variants []*Variant
End Position // the body's `}`
}
EnumDecl is a closed set of variants, each optionally carrying fields.
type Field ¶
type Field struct {
DeclHead
Owned bool // composition rather than reference
Type *TypeRef
Constraints []*Constraint
Default *Literal
End Position // the constraint block's `}`; zero without one
}
Field is a named, typed member.
type File ¶
type File struct {
Filename string
Package *PackageDecl // nil if omitted
Imports []*ImportDecl
Decls []Decl
// Comments holds every ordinary `//` comment in source order. Doc
// comments live in the Doc of the declaration they precede.
Comments []*Comment
End Position
}
File is a single parsed .tdl source file.
type ImportDecl ¶
type ImportDecl struct {
Doc []string
DocP Position // where the doc comment was written; zero without one
P Position
Path string
Alias string // "_" merges the imported names into the current scope
}
ImportDecl is an `import "path.tdl" as alias` declaration.
type InstanceDecl ¶
type InstanceDecl struct {
DeclHead // N is the class name
Params []*TypeParam
Class *ClassRef
For *TypeRef // set for `instance C for T`, nil for `instance C<T>`
Requires []*ClassRef
Binds []*AssocTypeBind
End Position // the bind block's `}`; zero without one
}
InstanceDecl declares that a type satisfies a class.
type Kind ¶
type Kind struct {
P Position
N string // "type" or "unit"; empty when Paren is set
Paren *Kind
Arrow *Kind // `left -> Arrow`; nil for a bare atom
}
Kind is a kind expression. Arrow associates to the right.
type Literal ¶
type Literal struct {
P Position
Kind LiteralKind
Text string // decoded for LitString, pattern body for LitRegex, source text otherwise
Items []*Literal // set for LitList
Lo *Literal // set for LitRange; nil when the range is open below
Hi *Literal // set for LitRange; nil when the range is open above
}
Literal is a field default, constraint argument, or directive argument.
type LiteralKind ¶
type LiteralKind int
LiteralKind is the form a Literal takes.
const ( LitString LiteralKind = iota LitInt LitFloat LitBool LitList LitName // a dotted name, denoting an enum variant LitRegex // /.../, a constraint argument LitRange // 3..254, 1.., ..254 )
type Member ¶
type Member interface {
Pos() Position
}
Member is one item in a StructDecl body: a Field or an Include.
type NewtypeDecl ¶
type NewtypeDecl struct {
DeclHead
Params []*TypeParam
Base *TypeRef
Requires []*ClassRef
Constraints []*Constraint
End Position // the constraint block's `}`; zero without one
}
NewtypeDecl is a `type Name: Base` declaration.
type PackageDecl ¶
PackageDecl is a `package <dotted.ident>` declaration.
type PrimitiveDecl ¶
PrimitiveDecl is a `primitive Name` or `primitive Name: Kind` declaration of an opaque root type.
type StructDecl ¶
type StructDecl struct {
DeclHead
Keyword string // "type" or "mixin"
Params []*TypeParam
Conforms []*ClassRef
Requires []*ClassRef
Members []Member
End Position // the body's `}`
}
StructDecl is a `type` or `mixin` declaration with a body of members.
type TargetDecl ¶
type TargetDecl struct {
DeclHead
For string // the dotted package name the target applies to
Entries []*TargetEntry
End Position // the block's `}`
}
TargetDecl is a `target go for billing { ... }` block.
type TargetEntry ¶
type TargetEntry struct {
P Position
Path string // "" for a bare directive
Directive *Directive // nil when Entries is set
Entries []*TargetEntry // nil when Directive is set
End Position // the nested block's `}`; zero without one
}
TargetEntry is one entry in a TargetDecl: a nested block, a path mapped to a directive, or a bare directive.
type TypeArg ¶
type TypeArg struct {
P Position
Type *TypeRef // set unless Unit is
Unit *UnitExpr // set only when operators made the argument unambiguous
}
TypeArg is one argument in a `<...>` list: a type or a unit. A bare name is recorded as a type and the resolver decides.
type TypeRef ¶
type TypeRef struct {
P Position
Qualifier string // "" if unqualified; set for "alias.Type"
N string // "" for the collection forms below
Args []*TypeArg
List *TypeRef // [T]
Set *TypeRef // {T}
MapKey *TypeRef // {K -> V}
MapValue *TypeRef
Optional bool // trailing ?
Nullable bool // trailing | null
}
TypeRef is a reference to a type, with collection and optionality sugar recorded as written. The resolver lowers it to prelude types.