ast

package
v0.0.0-...-8f83adf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2015 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(node Node, fn func(Node) bool)

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

Types

type Comment

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

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

func (*Comment) Pos

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

type CommentGroup

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

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

type File

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

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

type ListType

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

func (l *ListType) Add(node Node)

func (*ListType) Pos

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

type LiteralType

type LiteralType struct {
	Token token.Token

	// associated line comment, only when used in a list
	LineComment *CommentGroup
}

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

func (*LiteralType) Pos

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

type Node

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

Node is an element in the abstract syntax tree.

type ObjectItem

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

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

type ObjectKey

type ObjectKey struct {
	Token token.Token
}

ObjectKeys are either an identifier or of type string.

func (*ObjectKey) Pos

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

type ObjectList

type ObjectList struct {
	Items []*ObjectItem
}

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

func (*ObjectList) Add

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

func (*ObjectList) Pos

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

type ObjectType

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL