hcl: github.com/hashicorp/hcl/hcl/ast Index | Files

package ast

import "github.com/hashicorp/hcl/hcl/ast"

Package ast declares the types used to represent syntax trees for HCL (HashiCorp Configuration Language)

Index

Package Files

ast.go walk.go

type Comment Uses

type Comment struct {
    Start token.Pos // position of / or #
    Text  string
}

Comment node represents a single //, # style or /*- style commment

func (*Comment) Pos Uses

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

type CommentGroup Uses

type CommentGroup struct {
    List []*Comment // len(List) > 0
}

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

func (*CommentGroup) Pos Uses

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

type File Uses

type File struct {
    Node     Node            // usually a *ObjectList
    Comments []*CommentGroup // list of all comments in the source
}

File represents a single HCL file

func (*File) Pos Uses

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

type ListType Uses

type ListType struct {
    Lbrack token.Pos // position of "["
    Rbrack token.Pos // position of "]"
    List   []Node    // the elements in lexical order
}

ListStatement represents a HCL List type

func (*ListType) Add Uses

func (l *ListType) Add(node Node)

func (*ListType) Pos Uses

func (l *ListType) Pos() token.Pos

type LiteralType Uses

type LiteralType struct {
    Token token.Token

    // comment types, only used when in a list
    LeadComment *CommentGroup
    LineComment *CommentGroup
}

LiteralType represents a literal of basic type. Valid types are: token.NUMBER, token.FLOAT, token.BOOL and token.STRING

func (*LiteralType) Pos Uses

func (l *LiteralType) Pos() token.Pos

type Node Uses

type Node interface {
    Pos() token.Pos
    // contains filtered or unexported methods
}

Node is an element in the abstract syntax tree.

func Walk Uses

func Walk(node Node, fn WalkFunc) Node

Walk traverses an AST in depth-first order: It starts by calling fn(node); node must not be nil. If fn returns true, Walk invokes fn recursively for each of the non-nil children of node, followed by a call of fn(nil). The returned node of fn can be used to rewrite the passed node to fn.

type ObjectItem Uses

type ObjectItem struct {
    // keys is only one length long if it's of type assignment. If it's a
    // nested object it can be larger than one. In that case "assign" is
    // invalid as there is no assignments for a nested object.
    Keys []*ObjectKey

    // assign contains the position of "=", if any
    Assign token.Pos

    // val is the item itself. It can be an object,list, number, bool or a
    // string. If key length is larger than one, val can be only of type
    // Object.
    Val Node

    LeadComment *CommentGroup // associated lead comment
    LineComment *CommentGroup // associated line comment
}

ObjectItem represents a HCL Object Item. An item is represented with a key (or keys). It can be an assignment or an object (both normal and nested)

func (*ObjectItem) Pos Uses

func (o *ObjectItem) Pos() token.Pos

type ObjectKey Uses

type ObjectKey struct {
    Token token.Token
}

ObjectKeys are either an identifier or of type string.

func (*ObjectKey) GoString Uses

func (o *ObjectKey) GoString() string

func (*ObjectKey) Pos Uses

func (o *ObjectKey) Pos() token.Pos

type ObjectList Uses

type ObjectList struct {
    Items []*ObjectItem
}

ObjectList represents a list of ObjectItems. An HCL file itself is an ObjectList.

func (*ObjectList) Add Uses

func (o *ObjectList) Add(item *ObjectItem)

func (*ObjectList) Children Uses

func (o *ObjectList) Children() *ObjectList

Children returns further nested objects (key length > 0) within this ObjectList. This should be used with Filter to get at child items.

func (*ObjectList) Elem Uses

func (o *ObjectList) Elem() *ObjectList

Elem returns items in the list that are direct element assignments (key length == 0). This should be used with Filter to get at elements.

func (*ObjectList) Filter Uses

func (o *ObjectList) Filter(keys ...string) *ObjectList

Filter filters out the objects with the given key list as a prefix.

The returned list of objects contain ObjectItems where the keys have this prefix already stripped off. This might result in objects with zero-length key lists if they have no children.

If no matches are found, an empty ObjectList (non-nil) is returned.

func (*ObjectList) GoString Uses

func (o *ObjectList) GoString() string

func (*ObjectList) Pos Uses

func (o *ObjectList) Pos() token.Pos

type ObjectType Uses

type ObjectType struct {
    Lbrace token.Pos   // position of "{"
    Rbrace token.Pos   // position of "}"
    List   *ObjectList // the nodes in lexical order
}

ObjectType represents a HCL Object Type

func (*ObjectType) Pos Uses

func (o *ObjectType) Pos() token.Pos

type WalkFunc Uses

type WalkFunc func(Node) (Node, bool)

WalkFunc describes a function to be called for each node during a Walk. The returned node can be used to rewrite the AST. Walking stops the returned bool is false.

Package ast imports 3 packages (graph) and is imported by 345 packages. Updated 2019-08-05. Refresh now. Tools for package owners.