...

Package ast

import "cuelang.org/go/cue/ast"
Overview
Index
Subdirectories

Overview ▾

Package ast declares the types used to represent syntax trees for CUE packages.

Index ▾

Variables
func AddComment(n Node, cg *CommentGroup)
func Embed(x Expr) *embedding
func IsValidIdent(ident string) bool
func LabelName(l Label) (name string, isIdent bool, err error)
func Name(n Node) string
func ParseIdent(n *Ident) (string, error)
func SetComments(n Node, cgs []*CommentGroup)
func SetPos(n Node, p token.Pos)
func SetRelPos(n Node, p token.RelPos)
func Walk(node Node, before func(Node) bool, after func(Node))
type Alias
    func (c *Alias) AddComment(cg *CommentGroup)
    func (c *Alias) Comments() []*CommentGroup
    func (a *Alias) End() token.Pos
    func (a *Alias) Pos() token.Pos
    func (c *Alias) SetComments(cgs []*CommentGroup)
type Attribute
    func (c *Attribute) AddComment(cg *CommentGroup)
    func (c *Attribute) Comments() []*CommentGroup
    func (a *Attribute) End() token.Pos
    func (a *Attribute) Pos() token.Pos
    func (c *Attribute) SetComments(cgs []*CommentGroup)
    func (a *Attribute) Split() (key, body string)
type BadDecl
    func (c *BadDecl) AddComment(cg *CommentGroup)
    func (c *BadDecl) Comments() []*CommentGroup
    func (d *BadDecl) End() token.Pos
    func (d *BadDecl) Pos() token.Pos
    func (c *BadDecl) SetComments(cgs []*CommentGroup)
type BadExpr
    func (c *BadExpr) AddComment(cg *CommentGroup)
    func (c *BadExpr) Comments() []*CommentGroup
    func (x *BadExpr) End() token.Pos
    func (x *BadExpr) Pos() token.Pos
    func (c *BadExpr) SetComments(cgs []*CommentGroup)
type BasicLit
    func NewBool(b bool) *BasicLit
    func NewLit(tok token.Token, s string) *BasicLit
    func NewNull() *BasicLit
    func NewString(str string) *BasicLit
    func (c *BasicLit) AddComment(cg *CommentGroup)
    func (c *BasicLit) Comments() []*CommentGroup
    func (x *BasicLit) End() token.Pos
    func (x *BasicLit) Pos() token.Pos
    func (c *BasicLit) SetComments(cgs []*CommentGroup)
type BinaryExpr
    func (c *BinaryExpr) AddComment(cg *CommentGroup)
    func (c *BinaryExpr) Comments() []*CommentGroup
    func (x *BinaryExpr) End() token.Pos
    func (x *BinaryExpr) Pos() token.Pos
    func (c *BinaryExpr) SetComments(cgs []*CommentGroup)
type BottomLit
    func (c *BottomLit) AddComment(cg *CommentGroup)
    func (c *BottomLit) Comments() []*CommentGroup
    func (x *BottomLit) End() token.Pos
    func (x *BottomLit) Pos() token.Pos
    func (c *BottomLit) SetComments(cgs []*CommentGroup)
type CallExpr
    func NewCall(fun Expr, args ...Expr) *CallExpr
    func (c *CallExpr) AddComment(cg *CommentGroup)
    func (c *CallExpr) Comments() []*CommentGroup
    func (x *CallExpr) End() token.Pos
    func (x *CallExpr) Pos() token.Pos
    func (c *CallExpr) SetComments(cgs []*CommentGroup)
type Clause
type Comment
    func (c *Comment) AddComment(*CommentGroup)
    func (c *Comment) Comments() []*CommentGroup
    func (c *Comment) End() token.Pos
    func (c *Comment) Pos() token.Pos
type CommentGroup
    func Comments(n Node) []*CommentGroup
    func (g *CommentGroup) AddComment(*CommentGroup)
    func (g *CommentGroup) Comments() []*CommentGroup
    func (g *CommentGroup) End() token.Pos
    func (g *CommentGroup) Pos() token.Pos
    func (g *CommentGroup) Text() string
type Comprehension
    func (c *Comprehension) AddComment(cg *CommentGroup)
    func (c *Comprehension) Comments() []*CommentGroup
    func (x *Comprehension) End() token.Pos
    func (x *Comprehension) Pos() token.Pos
    func (c *Comprehension) SetComments(cgs []*CommentGroup)
type Decl
type Ellipsis
    func (c *Ellipsis) AddComment(cg *CommentGroup)
    func (c *Ellipsis) Comments() []*CommentGroup
    func (x *Ellipsis) End() token.Pos
    func (x *Ellipsis) Pos() token.Pos
    func (c *Ellipsis) SetComments(cgs []*CommentGroup)
type EmbedDecl
    func (c *EmbedDecl) AddComment(cg *CommentGroup)
    func (c *EmbedDecl) Comments() []*CommentGroup
    func (d *EmbedDecl) End() token.Pos
    func (d *EmbedDecl) Pos() token.Pos
    func (c *EmbedDecl) SetComments(cgs []*CommentGroup)
type Expr
    func NewBinExpr(op token.Token, operands ...Expr) Expr
    func NewSel(x Expr, sel ...string) Expr
type Field
    func (c *Field) AddComment(cg *CommentGroup)
    func (c *Field) Comments() []*CommentGroup
    func (d *Field) End() token.Pos
    func (d *Field) Pos() token.Pos
    func (c *Field) SetComments(cgs []*CommentGroup)
type File
    func (c *File) AddComment(cg *CommentGroup)
    func (c *File) Comments() []*CommentGroup
    func (f *File) End() token.Pos
    func (f *File) PackageName() string
    func (f *File) Pos() token.Pos
    func (f *File) Preamble() []Decl
    func (c *File) SetComments(cgs []*CommentGroup)
    func (f *File) VisitImports(fn func(d *ImportDecl))
type ForClause
    func (c *ForClause) AddComment(cg *CommentGroup)
    func (c *ForClause) Comments() []*CommentGroup
    func (x *ForClause) End() token.Pos
    func (x *ForClause) Pos() token.Pos
    func (c *ForClause) SetComments(cgs []*CommentGroup)
type Func
    func (c *Func) AddComment(cg *CommentGroup)
    func (c *Func) Comments() []*CommentGroup
    func (x *Func) End() token.Pos
    func (x *Func) Pos() token.Pos
    func (c *Func) SetComments(cgs []*CommentGroup)
type Ident
    func NewIdent(name string) *Ident
    func (c *Ident) AddComment(cg *CommentGroup)
    func (c *Ident) Comments() []*CommentGroup
    func (x *Ident) End() token.Pos
    func (x *Ident) Pos() token.Pos
    func (c *Ident) SetComments(cgs []*CommentGroup)
    func (id *Ident) String() string
type IfClause
    func (c *IfClause) AddComment(cg *CommentGroup)
    func (c *IfClause) Comments() []*CommentGroup
    func (x *IfClause) End() token.Pos
    func (x *IfClause) Pos() token.Pos
    func (c *IfClause) SetComments(cgs []*CommentGroup)
type ImportDecl
    func (c *ImportDecl) AddComment(cg *CommentGroup)
    func (c *ImportDecl) Comments() []*CommentGroup
    func (d *ImportDecl) End() token.Pos
    func (d *ImportDecl) Pos() token.Pos
    func (c *ImportDecl) SetComments(cgs []*CommentGroup)
type ImportSpec
    func NewImport(name *Ident, importPath string) *ImportSpec
    func (c *ImportSpec) AddComment(cg *CommentGroup)
    func (c *ImportSpec) Comments() []*CommentGroup
    func (s *ImportSpec) End() token.Pos
    func (s *ImportSpec) Pos() token.Pos
    func (c *ImportSpec) SetComments(cgs []*CommentGroup)
type IndexExpr
    func (c *IndexExpr) AddComment(cg *CommentGroup)
    func (c *IndexExpr) Comments() []*CommentGroup
    func (x *IndexExpr) End() token.Pos
    func (x *IndexExpr) Pos() token.Pos
    func (c *IndexExpr) SetComments(cgs []*CommentGroup)
type Interpolation
    func (c *Interpolation) AddComment(cg *CommentGroup)
    func (c *Interpolation) Comments() []*CommentGroup
    func (x *Interpolation) End() token.Pos
    func (x *Interpolation) Pos() token.Pos
    func (c *Interpolation) SetComments(cgs []*CommentGroup)
type Label
type LetClause
    func (c *LetClause) AddComment(cg *CommentGroup)
    func (c *LetClause) Comments() []*CommentGroup
    func (x *LetClause) End() token.Pos
    func (x *LetClause) Pos() token.Pos
    func (c *LetClause) SetComments(cgs []*CommentGroup)
type ListLit
    func NewList(exprs ...Expr) *ListLit
    func (c *ListLit) AddComment(cg *CommentGroup)
    func (c *ListLit) Comments() []*CommentGroup
    func (x *ListLit) End() token.Pos
    func (x *ListLit) Pos() token.Pos
    func (c *ListLit) SetComments(cgs []*CommentGroup)
type Node
type Package
    func (c *Package) AddComment(cg *CommentGroup)
    func (c *Package) Comments() []*CommentGroup
    func (p *Package) End() token.Pos
    func (p *Package) Pos() token.Pos
    func (c *Package) SetComments(cgs []*CommentGroup)
type ParenExpr
    func (c *ParenExpr) AddComment(cg *CommentGroup)
    func (c *ParenExpr) Comments() []*CommentGroup
    func (x *ParenExpr) End() token.Pos
    func (x *ParenExpr) Pos() token.Pos
    func (c *ParenExpr) SetComments(cgs []*CommentGroup)
type SelectorExpr
    func (c *SelectorExpr) AddComment(cg *CommentGroup)
    func (c *SelectorExpr) Comments() []*CommentGroup
    func (x *SelectorExpr) End() token.Pos
    func (x *SelectorExpr) Pos() token.Pos
    func (c *SelectorExpr) SetComments(cgs []*CommentGroup)
type SliceExpr
    func (c *SliceExpr) AddComment(cg *CommentGroup)
    func (c *SliceExpr) Comments() []*CommentGroup
    func (x *SliceExpr) End() token.Pos
    func (x *SliceExpr) Pos() token.Pos
    func (c *SliceExpr) SetComments(cgs []*CommentGroup)
type Spec
type StructLit
    func NewStruct(fields ...interface{}) *StructLit
    func (c *StructLit) AddComment(cg *CommentGroup)
    func (c *StructLit) Comments() []*CommentGroup
    func (x *StructLit) End() token.Pos
    func (x *StructLit) Pos() token.Pos
    func (c *StructLit) SetComments(cgs []*CommentGroup)
type UnaryExpr
    func (c *UnaryExpr) AddComment(cg *CommentGroup)
    func (c *UnaryExpr) Comments() []*CommentGroup
    func (x *UnaryExpr) End() token.Pos
    func (x *UnaryExpr) Pos() token.Pos
    func (c *UnaryExpr) SetComments(cgs []*CommentGroup)

Package files

ast.go comments.go ident.go walk.go

Variables

ErrIsExpression reports whether a label is an expression. This error is never returned directly. Use errors.Is.

var ErrIsExpression = errors.New("not a concrete label")

func AddComment

func AddComment(n Node, cg *CommentGroup)

AddComment adds the given comment to the node if it supports it. If a node does not support comments, such as for CommentGroup or Comment, this call has no effect.

func Embed

func Embed(x Expr) *embedding

Embed can be used in conjunction with NewStruct to embed values.

func IsValidIdent

func IsValidIdent(ident string) bool

IsValidIdent reports whether str is a valid identifier. Note that the underscore "_" string is considered valid, for top.

func LabelName

func LabelName(l Label) (name string, isIdent bool, err error)

LabelName reports the name of a label, whether it is an identifier (it binds a value to a scope), and whether it is valid. Keywords that are allowed in label positions are interpreted accordingly.

Examples:

Label   Result
foo     "foo"  true   nil
true    "true" true   nil
"foo"   "foo"  false  nil
"x-y"   "x-y"  false  nil
"foo    ""     false  invalid string
"\(x)"  ""     false  errors.Is(err, ErrIsExpression)
X=foo   "foo"  true   nil

func Name

func Name(n Node) string

Name describes the type of n.

func ParseIdent

func ParseIdent(n *Ident) (string, error)

ParseIdent unquotes a possibly quoted identifier and validates if the result is valid.

Deprecated: quoted identifiers are deprecated. Use aliases.

func SetComments

func SetComments(n Node, cgs []*CommentGroup)

SetComments replaces all comments of n with the given set of comments. If a node does not support comments, such as for CommentGroup or Comment, this call has no effect.

func SetPos

func SetPos(n Node, p token.Pos)

SetPos sets a node to the given position, if possible.

func SetRelPos

func SetRelPos(n Node, p token.RelPos)

SetRelPos sets the relative position of a node without modifying its file position. Setting it to token.NoRelPos allows a node to adopt default formatting.

func Walk

func Walk(node Node, before func(Node) bool, after func(Node))

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.

type Alias

An Alias binds another field to the alias name in the current struct.

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
}

func (*Alias) AddComment

func (c *Alias) AddComment(cg *CommentGroup)

func (*Alias) Comments

func (c *Alias) Comments() []*CommentGroup

func (*Alias) End

func (a *Alias) End() token.Pos

func (*Alias) Pos

func (a *Alias) Pos() token.Pos

func (*Alias) SetComments

func (c *Alias) SetComments(cgs []*CommentGroup)

type Attribute

An Attribute provides meta data about a field.

type Attribute struct {
    At   token.Pos
    Text string // must be a valid attribute format.
    // contains filtered or unexported fields
}

func (*Attribute) AddComment

func (c *Attribute) AddComment(cg *CommentGroup)

func (*Attribute) Comments

func (c *Attribute) Comments() []*CommentGroup

func (*Attribute) End

func (a *Attribute) End() token.Pos

func (*Attribute) Pos

func (a *Attribute) Pos() token.Pos

func (*Attribute) SetComments

func (c *Attribute) SetComments(cgs []*CommentGroup)

func (*Attribute) Split

func (a *Attribute) Split() (key, body string)

type BadDecl

A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.

type BadDecl struct {
    From, To token.Pos // position range of bad declaration
    // contains filtered or unexported fields
}

func (*BadDecl) AddComment

func (c *BadDecl) AddComment(cg *CommentGroup)

func (*BadDecl) Comments

func (c *BadDecl) Comments() []*CommentGroup

func (*BadDecl) End

func (d *BadDecl) End() token.Pos

func (*BadDecl) Pos

func (d *BadDecl) Pos() token.Pos

func (*BadDecl) SetComments

func (c *BadDecl) SetComments(cgs []*CommentGroup)

type BadExpr

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.

type BadExpr struct {
    From, To token.Pos // position range of bad expression
    // contains filtered or unexported fields
}

func (*BadExpr) AddComment

func (c *BadExpr) AddComment(cg *CommentGroup)

func (*BadExpr) Comments

func (c *BadExpr) Comments() []*CommentGroup

func (*BadExpr) End

func (x *BadExpr) End() token.Pos

func (*BadExpr) Pos

func (x *BadExpr) Pos() token.Pos

func (*BadExpr) SetComments

func (c *BadExpr) SetComments(cgs []*CommentGroup)

type BasicLit

A BasicLit node represents a literal of basic type.

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
}

func NewBool

func NewBool(b bool) *BasicLit

NewBool creates a new BasicLit with a bool value without position. Useful for ASTs generated by code other than the CUE parser.

func NewLit

func NewLit(tok token.Token, s string) *BasicLit

NewLit creates a new BasicLit with from a token type and string without position. Useful for ASTs generated by code other than the CUE parser.

func NewNull

func NewNull() *BasicLit

NewNull creates a new BasicLit configured to be a null value. Useful for ASTs generated by code other than the CUE parser.

func NewString

func NewString(str string) *BasicLit

NewString creates a new BasicLit with a string value without position. It quotes the given string. Useful for ASTs generated by code other than the CUE parser.

func (*BasicLit) AddComment

func (c *BasicLit) AddComment(cg *CommentGroup)

func (*BasicLit) Comments

func (c *BasicLit) Comments() []*CommentGroup

func (*BasicLit) End

func (x *BasicLit) End() token.Pos

func (*BasicLit) Pos

func (x *BasicLit) Pos() token.Pos

func (*BasicLit) SetComments

func (c *BasicLit) SetComments(cgs []*CommentGroup)

type BinaryExpr

A BinaryExpr node represents a binary expression.

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
}

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

func (*BinaryExpr) SetComments

func (c *BinaryExpr) SetComments(cgs []*CommentGroup)

type BottomLit

A BottomLit indicates an error.

type BottomLit struct {
    Bottom token.Pos
    // contains filtered or unexported fields
}

func (*BottomLit) AddComment

func (c *BottomLit) AddComment(cg *CommentGroup)

func (*BottomLit) Comments

func (c *BottomLit) Comments() []*CommentGroup

func (*BottomLit) End

func (x *BottomLit) End() token.Pos

func (*BottomLit) Pos

func (x *BottomLit) Pos() token.Pos

func (*BottomLit) SetComments

func (c *BottomLit) SetComments(cgs []*CommentGroup)

type CallExpr

A CallExpr node represents an expression followed by an argument list.

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
}

func NewCall

func NewCall(fun Expr, args ...Expr) *CallExpr

NewCall creates a new CallExpr. Useful for ASTs generated by code other than the CUE parser.

func (*CallExpr) AddComment

func (c *CallExpr) AddComment(cg *CommentGroup)

func (*CallExpr) Comments

func (c *CallExpr) Comments() []*CommentGroup

func (*CallExpr) End

func (x *CallExpr) End() token.Pos

func (*CallExpr) Pos

func (x *CallExpr) Pos() token.Pos

func (*CallExpr) SetComments

func (c *CallExpr) SetComments(cgs []*CommentGroup)

type Clause

Clause nodes are part of comprehensions.

type Clause interface {
    Node
    // contains filtered or unexported methods
}

type Comment

A Comment node represents a single //-style or /*-style comment.

type Comment struct {
    Slash token.Pos // position of "/" starting the comment
    Text  string    // comment text (excluding '\n' for //-style comments)
}

func (*Comment) AddComment

func (c *Comment) AddComment(*CommentGroup)

func (*Comment) Comments

func (c *Comment) Comments() []*CommentGroup

func (*Comment) End

func (c *Comment) End() token.Pos

func (*Comment) Pos

func (c *Comment) Pos() token.Pos

type CommentGroup

A CommentGroup represents a sequence of comments with no other tokens and no empty lines between.

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
    // contains filtered or unexported fields
}

func Comments

func Comments(n Node) []*CommentGroup

Comments returns all comments associated with a given node.

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 Comprehension

A Comprehension node represents a comprehension declaration.

type Comprehension struct {
    Clauses []Clause // There must be at least one clause.
    Value   Expr     // Must be a struct TODO: change to Struct
    // contains filtered or unexported fields
}

func (*Comprehension) AddComment

func (c *Comprehension) AddComment(cg *CommentGroup)

func (*Comprehension) Comments

func (c *Comprehension) Comments() []*CommentGroup

func (*Comprehension) End

func (x *Comprehension) End() token.Pos

func (*Comprehension) Pos

func (x *Comprehension) Pos() token.Pos

func (*Comprehension) SetComments

func (c *Comprehension) SetComments(cgs []*CommentGroup)

type Decl

A Decl node is implemented by all declarations.

type Decl interface {
    Node
    // contains filtered or unexported methods
}

type Ellipsis

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

func (c *Ellipsis) AddComment(cg *CommentGroup)

func (*Ellipsis) Comments

func (c *Ellipsis) Comments() []*CommentGroup

func (*Ellipsis) End

func (x *Ellipsis) End() token.Pos

func (*Ellipsis) Pos

func (x *Ellipsis) Pos() token.Pos

func (*Ellipsis) SetComments

func (c *Ellipsis) SetComments(cgs []*CommentGroup)

type EmbedDecl

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.

type EmbedDecl struct {
    Expr Expr
    // contains filtered or unexported fields
}

func (*EmbedDecl) AddComment

func (c *EmbedDecl) AddComment(cg *CommentGroup)

func (*EmbedDecl) Comments

func (c *EmbedDecl) Comments() []*CommentGroup

func (*EmbedDecl) End

func (d *EmbedDecl) End() token.Pos

func (*EmbedDecl) Pos

func (d *EmbedDecl) Pos() token.Pos

func (*EmbedDecl) SetComments

func (c *EmbedDecl) SetComments(cgs []*CommentGroup)

type Expr

An Expr is implemented by all expression nodes.

type Expr interface {
    Node
    // contains filtered or unexported methods
}

func NewBinExpr

func NewBinExpr(op token.Token, operands ...Expr) Expr

NewBinExpr creates for list of expressions of length 2 or greater a chained binary expression of the form (((x1 op x2) op x3) ...). For lists of length 1 it returns the expression itself. It panics for empty lists. Useful for ASTs generated by code other than the CUE parser.

func NewSel

func NewSel(x Expr, sel ...string) Expr

NewSel creates a sequence of selectors. Useful for ASTs generated by code other than the CUE parser.

type Field

A Field represents a field declaration in a struct.

type Field struct {
    Label      Label       // must have at least one element.
    Optional   token.Pos   // Deprecated
    Constraint token.Token // token.ILLEGAL, token.OPTION, or token.NOT

    // No TokenPos: Value must be an StructLit with one field.
    TokenPos token.Pos
    Token    token.Token // Deprecated: always token.COLON

    Value Expr // the value associated with this field.

    Attrs []*Attribute
    // contains filtered or unexported fields
}

func (*Field) AddComment

func (c *Field) AddComment(cg *CommentGroup)

func (*Field) Comments

func (c *Field) Comments() []*CommentGroup

func (*Field) End

func (d *Field) End() token.Pos

func (*Field) Pos

func (d *Field) Pos() token.Pos

func (*Field) SetComments

func (c *Field) SetComments(cgs []*CommentGroup)

type File

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.

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
}

func (*File) AddComment

func (c *File) AddComment(cg *CommentGroup)

func (*File) Comments

func (c *File) Comments() []*CommentGroup

func (*File) End

func (f *File) End() token.Pos

func (*File) PackageName

func (f *File) PackageName() string

PackageName returns the package name associated with this file or "" if no package is associated.

func (*File) Pos

func (f *File) Pos() token.Pos

func (*File) Preamble

func (f *File) Preamble() []Decl

Preamble returns the declarations of the preamble.

func (*File) SetComments

func (c *File) SetComments(cgs []*CommentGroup)

func (*File) VisitImports

func (f *File) VisitImports(fn func(d *ImportDecl))

type ForClause

A ForClause node represents a for clause in a comprehension.

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
}

func (*ForClause) AddComment

func (c *ForClause) AddComment(cg *CommentGroup)

func (*ForClause) Comments

func (c *ForClause) Comments() []*CommentGroup

func (*ForClause) End

func (x *ForClause) End() token.Pos

func (*ForClause) Pos

func (x *ForClause) Pos() token.Pos

func (*ForClause) SetComments

func (c *ForClause) SetComments(cgs []*CommentGroup)

type Func

A Func node represents a function type.

This is an experimental type and the contents will change without notice.

type Func struct {
    Func token.Pos // position of "func"
    Args []Expr    // list of elements; or nil
    Ret  Expr      // return type, must not be nil
    // contains filtered or unexported fields
}

func (*Func) AddComment

func (c *Func) AddComment(cg *CommentGroup)

func (*Func) Comments

func (c *Func) Comments() []*CommentGroup

func (*Func) End

func (x *Func) End() token.Pos

func (*Func) Pos

func (x *Func) Pos() token.Pos

func (*Func) SetComments

func (c *Func) SetComments(cgs []*CommentGroup)

type Ident

An Ident node represents an left-hand side identifier, including the underscore "_" identifier to represent top.

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
    Name string

    Scope Node // scope in which node was found or nil if referring directly
    Node  Node
    // contains filtered or unexported fields
}

func NewIdent

func NewIdent(name string) *Ident

NewIdent creates a new Ident without position. Useful for ASTs generated by code other than the CUE parser.

func (*Ident) AddComment

func (c *Ident) AddComment(cg *CommentGroup)

func (*Ident) Comments

func (c *Ident) Comments() []*CommentGroup

func (*Ident) End

func (x *Ident) End() token.Pos

func (*Ident) Pos

func (x *Ident) Pos() token.Pos

func (*Ident) SetComments

func (c *Ident) SetComments(cgs []*CommentGroup)

func (*Ident) String

func (id *Ident) String() string

type IfClause

A IfClause node represents an if guard clause in a comprehension.

type IfClause struct {
    If        token.Pos
    Condition Expr
    // contains filtered or unexported fields
}

func (*IfClause) AddComment

func (c *IfClause) AddComment(cg *CommentGroup)

func (*IfClause) Comments

func (c *IfClause) Comments() []*CommentGroup

func (*IfClause) End

func (x *IfClause) End() token.Pos

func (*IfClause) Pos

func (x *IfClause) Pos() token.Pos

func (*IfClause) SetComments

func (c *IfClause) SetComments(cgs []*CommentGroup)

type ImportDecl

A ImportDecl node represents a series of import declarations. A valid Lparen position (Lparen.Line > 0) indicates a parenthesized declaration.

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
}

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

func (*ImportDecl) SetComments

func (c *ImportDecl) SetComments(cgs []*CommentGroup)

type ImportSpec

An ImportSpec node represents a single package import.

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
}

func NewImport

func NewImport(name *Ident, importPath string) *ImportSpec

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

func (*ImportSpec) SetComments

func (c *ImportSpec) SetComments(cgs []*CommentGroup)

type IndexExpr

An IndexExpr node represents an expression followed by an index.

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
}

func (*IndexExpr) AddComment

func (c *IndexExpr) AddComment(cg *CommentGroup)

func (*IndexExpr) Comments

func (c *IndexExpr) Comments() []*CommentGroup

func (*IndexExpr) End

func (x *IndexExpr) End() token.Pos

func (*IndexExpr) Pos

func (x *IndexExpr) Pos() token.Pos

func (*IndexExpr) SetComments

func (c *IndexExpr) SetComments(cgs []*CommentGroup)

type Interpolation

A Interpolation node represents a string or bytes interpolation.

type Interpolation struct {
    Elts []Expr // interleaving of strings and expressions.
    // contains filtered or unexported fields
}

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

func (*Interpolation) SetComments

func (c *Interpolation) SetComments(cgs []*CommentGroup)

type Label

A Label is any production that can be used as a LHS label.

type Label interface {
    Node
    // contains filtered or unexported methods
}

type LetClause

A LetClause node represents a let clause in a comprehension.

type LetClause struct {
    Let   token.Pos
    Ident *Ident
    Equal token.Pos
    Expr  Expr
    // contains filtered or unexported fields
}

func (*LetClause) AddComment

func (c *LetClause) AddComment(cg *CommentGroup)

func (*LetClause) Comments

func (c *LetClause) Comments() []*CommentGroup

func (*LetClause) End

func (x *LetClause) End() token.Pos

func (*LetClause) Pos

func (x *LetClause) Pos() token.Pos

func (*LetClause) SetComments

func (c *LetClause) SetComments(cgs []*CommentGroup)

type ListLit

A ListLit node represents a literal list.

type ListLit struct {
    Lbrack token.Pos // position of "["

    // TODO: change to embedding or similar.
    Elts   []Expr    // list of composite elements; or nil
    Rbrack token.Pos // position of "]"
    // contains filtered or unexported fields
}

func NewList

func NewList(exprs ...Expr) *ListLit

NewList creates a list of Expressions. Useful for ASTs generated by code other than the CUE parser.

func (*ListLit) AddComment

func (c *ListLit) AddComment(cg *CommentGroup)

func (*ListLit) Comments

func (c *ListLit) Comments() []*CommentGroup

func (*ListLit) End

func (x *ListLit) End() token.Pos

func (*ListLit) Pos

func (x *ListLit) Pos() token.Pos

func (*ListLit) SetComments

func (c *ListLit) SetComments(cgs []*CommentGroup)

type Node

A Node represents any node in the abstract syntax tree.

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

    // Deprecated: use [Comments]
    Comments() []*CommentGroup

    // Deprecated: use [AddComment]
    AddComment(*CommentGroup)
    // contains filtered or unexported methods
}

type Package

A Package represents a package clause.

type Package struct {
    PackagePos token.Pos // position of "package" pseudo-keyword
    Name       *Ident    // package name
    // contains filtered or unexported fields
}

func (*Package) AddComment

func (c *Package) AddComment(cg *CommentGroup)

func (*Package) Comments

func (c *Package) Comments() []*CommentGroup

func (*Package) End

func (p *Package) End() token.Pos

func (*Package) Pos

func (p *Package) Pos() token.Pos

func (*Package) SetComments

func (c *Package) SetComments(cgs []*CommentGroup)

type ParenExpr

A ParenExpr node represents a parenthesized expression.

type ParenExpr struct {
    Lparen token.Pos // position of "("
    X      Expr      // parenthesized expression
    Rparen token.Pos // position of ")"
    // contains filtered or unexported fields
}

func (*ParenExpr) AddComment

func (c *ParenExpr) AddComment(cg *CommentGroup)

func (*ParenExpr) Comments

func (c *ParenExpr) Comments() []*CommentGroup

func (*ParenExpr) End

func (x *ParenExpr) End() token.Pos

func (*ParenExpr) Pos

func (x *ParenExpr) Pos() token.Pos

func (*ParenExpr) SetComments

func (c *ParenExpr) SetComments(cgs []*CommentGroup)

type SelectorExpr

A SelectorExpr node represents an expression followed by a selector.

type SelectorExpr struct {
    X   Expr  // expression
    Sel Label // field selector
    // contains filtered or unexported fields
}

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

func (*SelectorExpr) SetComments

func (c *SelectorExpr) SetComments(cgs []*CommentGroup)

type SliceExpr

An SliceExpr node represents an expression followed by slice indices.

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
}

func (*SliceExpr) AddComment

func (c *SliceExpr) AddComment(cg *CommentGroup)

func (*SliceExpr) Comments

func (c *SliceExpr) Comments() []*CommentGroup

func (*SliceExpr) End

func (x *SliceExpr) End() token.Pos

func (*SliceExpr) Pos

func (x *SliceExpr) Pos() token.Pos

func (*SliceExpr) SetComments

func (c *SliceExpr) SetComments(cgs []*CommentGroup)

type Spec

type Spec interface {
    Node
    // contains filtered or unexported methods
}

type StructLit

A StructLit node represents a literal struct.

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
}

func NewStruct

func NewStruct(fields ...interface{}) *StructLit

NewStruct creates a struct from the given fields.

A field is either a *Field, an *Ellipsis, *LetClause, a *CommentGroup, or a Label, optionally followed by a token.OPTION or token.NOT to indicate the field is optional or required, followed by an expression for the field value.

It will panic if a values not matching these patterns are given. Useful for ASTs generated by code other than the CUE parser.

func (*StructLit) AddComment

func (c *StructLit) AddComment(cg *CommentGroup)

func (*StructLit) Comments

func (c *StructLit) Comments() []*CommentGroup

func (*StructLit) End

func (x *StructLit) End() token.Pos

func (*StructLit) Pos

func (x *StructLit) Pos() token.Pos

func (*StructLit) SetComments

func (c *StructLit) SetComments(cgs []*CommentGroup)

type UnaryExpr

A UnaryExpr node represents a unary expression.

type UnaryExpr struct {
    OpPos token.Pos   // position of Op
    Op    token.Token // operator
    X     Expr        // operand
    // contains filtered or unexported fields
}

func (*UnaryExpr) AddComment

func (c *UnaryExpr) AddComment(cg *CommentGroup)

func (*UnaryExpr) Comments

func (c *UnaryExpr) Comments() []*CommentGroup

func (*UnaryExpr) End

func (x *UnaryExpr) End() token.Pos

func (*UnaryExpr) Pos

func (x *UnaryExpr) Pos() token.Pos

func (*UnaryExpr) SetComments

func (c *UnaryExpr) SetComments(cgs []*CommentGroup)

Subdirectories

Name Synopsis
..
astutil