Documentation ¶
Overview ¶
Package ast declares the types used to represent syntax trees for CUE packages.
Index ¶
- func LabelName(x Label) (name string, ok bool)
- func Walk(node Node, before func(Node) bool, after func(Node))
- type Alias
- type Attribute
- type BadDecl
- type BadExpr
- type BasicLit
- type BinaryExpr
- type BottomLit
- type CallExpr
- type Clause
- type Comment
- type CommentGroup
- type ComprehensionDecl
- type Decl
- type Ellipsis
- type EmbedDecl
- type Expr
- type Field
- type File
- type ForClause
- type Ident
- type IfClause
- type ImportDecl
- type ImportSpec
- type IndexExpr
- type Interpolation
- type Label
- type ListComprehension
- type ListLit
- type Node
- type Package
- type ParenExpr
- type SelectorExpr
- type SliceExpr
- type Spec
- type StructLit
- type TemplateLabel
- type UnaryExpr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Walk ¶
Walk traverses an AST in depth-first order: It starts by calling f(node); node must not be nil. If before returns true, Walk invokes f recursively for each of the non-nil children of node, followed by a call of after. Both functions may be nil. If before is nil, it is assumed to always return true.
Types ¶
type Alias ¶
type Alias struct { Ident *Ident // field name, always an Ident Equal token.Pos // position of "=" Expr Expr // An Ident or SelectorExpr // contains filtered or unexported fields }
An Alias binds another field to the alias name in the current struct.
func (*Alias) AddComment ¶
func (c *Alias) AddComment(cg *CommentGroup)
func (*Alias) Comments ¶
func (c *Alias) Comments() []*CommentGroup
type Attribute ¶
type Attribute struct { At token.Pos Text string // must be a valid attribute format. // contains filtered or unexported fields }
An Attribute provides meta data about a field.
func (*Attribute) AddComment ¶
func (c *Attribute) AddComment(cg *CommentGroup)
func (*Attribute) Comments ¶
func (c *Attribute) Comments() []*CommentGroup
type BadDecl ¶
type BadDecl struct {
From, To token.Pos // position range of bad declaration
// contains filtered or unexported fields
}
A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.
func (*BadDecl) AddComment ¶
func (c *BadDecl) AddComment(cg *CommentGroup)
func (*BadDecl) Comments ¶
func (c *BadDecl) Comments() []*CommentGroup
type BadExpr ¶
type BadExpr struct {
From, To token.Pos // position range of bad expression
// contains filtered or unexported fields
}
A BadExpr node is a placeholder for expressions containing syntax errors for which no correct expression nodes can be created. This is different from an ErrorExpr which represents an explicitly marked error in the source.
func (*BadExpr) AddComment ¶
func (c *BadExpr) AddComment(cg *CommentGroup)
func (*BadExpr) Comments ¶
func (c *BadExpr) Comments() []*CommentGroup
type BasicLit ¶
type BasicLit struct { ValuePos token.Pos // literal position Kind token.Token // INT, FLOAT, DURATION, or STRING Value string // literal string; e.g. 42, 0x7f, 3.14, 1_234_567, 1e-9, 2.4i, 'a', '\x7f', "foo", or '\m\n\o' // contains filtered or unexported fields }
A BasicLit node represents a literal of basic type.
func (*BasicLit) AddComment ¶
func (c *BasicLit) AddComment(cg *CommentGroup)
func (*BasicLit) Comments ¶
func (c *BasicLit) Comments() []*CommentGroup
type BinaryExpr ¶
type BinaryExpr struct { X Expr // left operand OpPos token.Pos // position of Op Op token.Token // operator Y Expr // right operand // contains filtered or unexported fields }
A BinaryExpr node represents a binary expression.
func (*BinaryExpr) AddComment ¶
func (c *BinaryExpr) AddComment(cg *CommentGroup)
func (*BinaryExpr) Comments ¶
func (c *BinaryExpr) Comments() []*CommentGroup
func (*BinaryExpr) End ¶
func (x *BinaryExpr) End() token.Pos
func (*BinaryExpr) Pos ¶
func (x *BinaryExpr) Pos() token.Pos
type BottomLit ¶
A BottomLit indicates an error.
func (*BottomLit) AddComment ¶
func (c *BottomLit) AddComment(cg *CommentGroup)
func (*BottomLit) Comments ¶
func (c *BottomLit) Comments() []*CommentGroup
type CallExpr ¶
type CallExpr struct { Fun Expr // function expression Lparen token.Pos // position of "(" Args []Expr // function arguments; or nil Rparen token.Pos // position of ")" // contains filtered or unexported fields }
A CallExpr node represents an expression followed by an argument list.
func (*CallExpr) AddComment ¶
func (c *CallExpr) AddComment(cg *CommentGroup)
func (*CallExpr) Comments ¶
func (c *CallExpr) Comments() []*CommentGroup
type Clause ¶
type Clause interface { Node // contains filtered or unexported methods }
Clause nodes are part of comprehensions.
type Comment ¶
type Comment struct { Slash token.Pos // position of "/" starting the comment Text string // comment text (excluding '\n' for //-style comments) }
A Comment node represents a single //-style or /*-style comment.
func (*Comment) AddComment ¶
func (g *Comment) AddComment(*CommentGroup)
func (*Comment) Comments ¶
func (g *Comment) Comments() []*CommentGroup
type CommentGroup ¶
type CommentGroup struct { // TODO: remove and use the token position of the first comment. Doc bool Line bool // true if it is on the same line as the node's end pos. // Position indicates where a comment should be attached if a node has // multiple tokens. 0 means before the first token, 1 means before the // second, etc. For instance, for a field, the positions are: // <0> Label <1> ":" <2> Expr <3> "," <4> Position int8 List []*Comment // len(List) > 0 }
A CommentGroup represents a sequence of comments with no other tokens and no empty lines between.
func (*CommentGroup) AddComment ¶
func (g *CommentGroup) AddComment(*CommentGroup)
func (*CommentGroup) Comments ¶
func (g *CommentGroup) Comments() []*CommentGroup
func (*CommentGroup) End ¶
func (g *CommentGroup) End() token.Pos
func (*CommentGroup) Pos ¶
func (g *CommentGroup) Pos() token.Pos
func (*CommentGroup) Text ¶
func (g *CommentGroup) Text() string
Text returns the text of the comment. Comment markers (//, /*, and */), the first space of a line comment, and leading and trailing empty lines are removed. Multiple empty lines are reduced to one, and trailing space on lines is trimmed. Unless the result is empty, it is newline-terminated.
type ComprehensionDecl ¶
type ComprehensionDecl struct { Field *Field Select token.Pos Clauses []Clause // contains filtered or unexported fields }
A ComprehensionDecl node represents a field comprehension.
func (*ComprehensionDecl) AddComment ¶
func (c *ComprehensionDecl) AddComment(cg *CommentGroup)
func (*ComprehensionDecl) Comments ¶
func (c *ComprehensionDecl) Comments() []*CommentGroup
func (*ComprehensionDecl) End ¶
func (x *ComprehensionDecl) End() token.Pos
func (*ComprehensionDecl) Pos ¶
func (x *ComprehensionDecl) Pos() token.Pos
type Decl ¶
type Decl interface { Node // contains filtered or unexported methods }
A Decl node is implemented by all declarations.
type Ellipsis ¶ added in v0.0.6
type Ellipsis struct { Ellipsis token.Pos // open list if set Type Expr // type for the remaining elements // contains filtered or unexported fields }
func (*Ellipsis) AddComment ¶ added in v0.0.6
func (c *Ellipsis) AddComment(cg *CommentGroup)
func (*Ellipsis) Comments ¶ added in v0.0.6
func (c *Ellipsis) Comments() []*CommentGroup
type EmbedDecl ¶ added in v0.0.5
type EmbedDecl struct { Expr Expr // contains filtered or unexported fields }
An EmbedDecl node represents a single expression used as a declaration. The expressions in this declaration is what will be emitted as configuration output.
An EmbedDecl may only appear at the top level.
func (*EmbedDecl) AddComment ¶ added in v0.0.5
func (c *EmbedDecl) AddComment(cg *CommentGroup)
func (*EmbedDecl) Comments ¶ added in v0.0.5
func (c *EmbedDecl) Comments() []*CommentGroup
type Expr ¶
type Expr interface { Node // contains filtered or unexported methods }
An Expr is implemented by all expression nodes.
type Field ¶
type Field struct { Label Label // must have at least one element. Optional token.Pos // No TokenPos: Value must be an StructLit with one field. TokenPos token.Pos Token token.Token // ':' or '::', ILLEGAL implies ':' Value Expr // the value associated with this field. Attrs []*Attribute // contains filtered or unexported fields }
A Field represents a field declaration in a struct.
func (*Field) AddComment ¶
func (c *Field) AddComment(cg *CommentGroup)
func (*Field) Comments ¶
func (c *Field) Comments() []*CommentGroup
type File ¶
type File struct { Filename string Decls []Decl // top-level declarations; or nil Imports []*ImportSpec // imports in this file Unresolved []*Ident // unresolved identifiers in this file // contains filtered or unexported fields }
A File node represents a Go source file.
The Comments list contains all comments in the source file in order of appearance, including the comments that are pointed to from other nodes via Doc and Comment fields.
func (*File) AddComment ¶
func (c *File) AddComment(cg *CommentGroup)
func (*File) Comments ¶
func (c *File) Comments() []*CommentGroup
type ForClause ¶
type ForClause struct { For token.Pos Key *Ident // allow pattern matching? // TODO: change to Comma Colon token.Pos Value *Ident // allow pattern matching? In token.Pos Source Expr // contains filtered or unexported fields }
A ForClause node represents a for clause in a comprehension.
func (*ForClause) AddComment ¶
func (c *ForClause) AddComment(cg *CommentGroup)
func (*ForClause) Comments ¶
func (c *ForClause) Comments() []*CommentGroup
type Ident ¶
type Ident struct { NamePos token.Pos // identifier position // This LHS path element may be an identifier. Possible forms: // foo: a normal identifier // "foo": JSON compatible // <foo>: a template shorthand Name string Scope Node // scope in which node was found or nil if referring directly Node Node // contains filtered or unexported fields }
An Ident node represents an left-hand side identifier.
func NewIdent ¶
NewIdent creates a new Ident without position. Useful for ASTs generated by code other than the Go
func (*Ident) AddComment ¶
func (c *Ident) AddComment(cg *CommentGroup)
func (*Ident) Comments ¶
func (c *Ident) Comments() []*CommentGroup
type IfClause ¶
A IfClause node represents an if guard clause in a comprehension.
func (*IfClause) AddComment ¶
func (c *IfClause) AddComment(cg *CommentGroup)
func (*IfClause) Comments ¶
func (c *IfClause) Comments() []*CommentGroup
type ImportDecl ¶
type ImportDecl struct { Import token.Pos Lparen token.Pos // position of '(', if any Specs []*ImportSpec Rparen token.Pos // position of ')', if any // contains filtered or unexported fields }
A ImportDecl node represents a series of import declarations. A valid Lparen position (Lparen.Line > 0) indicates a parenthesized declaration.
func (*ImportDecl) AddComment ¶
func (c *ImportDecl) AddComment(cg *CommentGroup)
func (*ImportDecl) Comments ¶
func (c *ImportDecl) Comments() []*CommentGroup
func (*ImportDecl) End ¶
func (d *ImportDecl) End() token.Pos
func (*ImportDecl) Pos ¶
func (d *ImportDecl) Pos() token.Pos
type ImportSpec ¶
type ImportSpec struct { Name *Ident // local package name (including "."); or nil Path *BasicLit // import path EndPos token.Pos // end of spec (overrides Path.Pos if nonzero) // contains filtered or unexported fields }
An ImportSpec node represents a single package import.
func (*ImportSpec) AddComment ¶
func (c *ImportSpec) AddComment(cg *CommentGroup)
func (*ImportSpec) Comments ¶
func (c *ImportSpec) Comments() []*CommentGroup
func (*ImportSpec) End ¶
func (s *ImportSpec) End() token.Pos
func (*ImportSpec) Pos ¶
func (s *ImportSpec) Pos() token.Pos
type IndexExpr ¶
type IndexExpr struct { X Expr // expression Lbrack token.Pos // position of "[" Index Expr // index expression Rbrack token.Pos // position of "]" // contains filtered or unexported fields }
An IndexExpr node represents an expression followed by an index.
func (*IndexExpr) AddComment ¶
func (c *IndexExpr) AddComment(cg *CommentGroup)
func (*IndexExpr) Comments ¶
func (c *IndexExpr) Comments() []*CommentGroup
type Interpolation ¶
type Interpolation struct { Elts []Expr // interleaving of strings and expressions. // contains filtered or unexported fields }
A Interpolation node represents a string or bytes interpolation.
func (*Interpolation) AddComment ¶
func (c *Interpolation) AddComment(cg *CommentGroup)
func (*Interpolation) Comments ¶
func (c *Interpolation) Comments() []*CommentGroup
func (*Interpolation) End ¶
func (x *Interpolation) End() token.Pos
func (*Interpolation) Pos ¶
func (x *Interpolation) Pos() token.Pos
type Label ¶
type Label interface { Node // contains filtered or unexported methods }
A Label is any prduction that can be used as a LHS label.
type ListComprehension ¶
type ListComprehension struct { Lbrack token.Pos // position of "[" Expr Expr Clauses []Clause // Feed or Guard (TODO let) Rbrack token.Pos // position of "]" // contains filtered or unexported fields }
A ListComprehension node represents as list comprehension.
func (*ListComprehension) AddComment ¶
func (c *ListComprehension) AddComment(cg *CommentGroup)
func (*ListComprehension) Comments ¶
func (c *ListComprehension) Comments() []*CommentGroup
func (*ListComprehension) End ¶
func (x *ListComprehension) End() token.Pos
func (*ListComprehension) Pos ¶
func (x *ListComprehension) Pos() token.Pos
type ListLit ¶
type ListLit struct { Lbrack token.Pos // position of "[" Elts []Expr // list of composite elements; or nil Rbrack token.Pos // position of "]" // contains filtered or unexported fields }
A ListLit node represents a literal list.
func (*ListLit) AddComment ¶
func (c *ListLit) AddComment(cg *CommentGroup)
func (*ListLit) Comments ¶
func (c *ListLit) Comments() []*CommentGroup
type Node ¶
type Node interface { Pos() token.Pos // position of first character belonging to the node End() token.Pos // position of first character immediately after the node Comments() []*CommentGroup AddComment(*CommentGroup) }
A Node represents any node in the abstract syntax tree.
type Package ¶ added in v0.0.6
type Package struct { PackagePos token.Pos // position of "package" pseudo-keyword Name *Ident // package name // contains filtered or unexported fields }
A Package represents a package clause.
func (*Package) AddComment ¶ added in v0.0.6
func (c *Package) AddComment(cg *CommentGroup)
func (*Package) Comments ¶ added in v0.0.6
func (c *Package) Comments() []*CommentGroup
type ParenExpr ¶
type ParenExpr struct { Lparen token.Pos // position of "(" X Expr // parenthesized expression Rparen token.Pos // position of ")" // contains filtered or unexported fields }
A ParenExpr node represents a parenthesized expression.
func (*ParenExpr) AddComment ¶
func (c *ParenExpr) AddComment(cg *CommentGroup)
func (*ParenExpr) Comments ¶
func (c *ParenExpr) Comments() []*CommentGroup
type SelectorExpr ¶
type SelectorExpr struct { X Expr // expression Sel *Ident // field selector // contains filtered or unexported fields }
A SelectorExpr node represents an expression followed by a selector.
func (*SelectorExpr) AddComment ¶
func (c *SelectorExpr) AddComment(cg *CommentGroup)
func (*SelectorExpr) Comments ¶
func (c *SelectorExpr) Comments() []*CommentGroup
func (*SelectorExpr) End ¶
func (x *SelectorExpr) End() token.Pos
func (*SelectorExpr) Pos ¶
func (x *SelectorExpr) Pos() token.Pos
type SliceExpr ¶
type SliceExpr struct { X Expr // expression Lbrack token.Pos // position of "[" Low Expr // begin of slice range; or nil High Expr // end of slice range; or nil Rbrack token.Pos // position of "]" // contains filtered or unexported fields }
An SliceExpr node represents an expression followed by slice indices.
func (*SliceExpr) AddComment ¶
func (c *SliceExpr) AddComment(cg *CommentGroup)
func (*SliceExpr) Comments ¶
func (c *SliceExpr) Comments() []*CommentGroup
type StructLit ¶
type StructLit struct { Lbrace token.Pos // position of "{" Elts []Decl // list of elements; or nil Rbrace token.Pos // position of "}" // contains filtered or unexported fields }
A StructLit node represents a literal struct.
func (*StructLit) AddComment ¶
func (c *StructLit) AddComment(cg *CommentGroup)
func (*StructLit) Comments ¶
func (c *StructLit) Comments() []*CommentGroup
type TemplateLabel ¶
type TemplateLabel struct { Langle token.Pos Ident *Ident Rangle token.Pos // contains filtered or unexported fields }
A TemplateLabel represents a field template declaration in a struct.
func (*TemplateLabel) AddComment ¶
func (c *TemplateLabel) AddComment(cg *CommentGroup)
func (*TemplateLabel) Comments ¶
func (c *TemplateLabel) Comments() []*CommentGroup
func (*TemplateLabel) End ¶
func (x *TemplateLabel) End() token.Pos
func (*TemplateLabel) Pos ¶
func (x *TemplateLabel) Pos() token.Pos
type UnaryExpr ¶
type UnaryExpr struct { OpPos token.Pos // position of Op Op token.Token // operator X Expr // operand // contains filtered or unexported fields }
A UnaryExpr node represents a unary expression.
func (*UnaryExpr) AddComment ¶
func (c *UnaryExpr) AddComment(cg *CommentGroup)
func (*UnaryExpr) Comments ¶
func (c *UnaryExpr) Comments() []*CommentGroup