ast

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ast exposes AST elements used by Alloy syntax.

The various interfaces exposed by ast are all closed; only types within this package can satisfy an AST interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EndPos

func EndPos(n Node) token.Pos

EndPos returns the position of the final character in a Node.

func StartPos

func StartPos(n Node) token.Pos

StartPos returns the position of the first character belonging to a Node.

func Walk

func Walk(v Visitor, node Node)

Walk traverses an AST in depth-first order: it starts by calling v.Visit(node); node must not be nil. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).

Types

type AccessExpr

type AccessExpr struct {
	Value Expr
	Name  *Ident
}

AccessExpr accesses a field in an object value by name.

type ArrayExpr

type ArrayExpr struct {
	Elements             []Expr
	LBrackPos, RBrackPos token.Pos
}

ArrayExpr is an array of values.

type AttributeStmt

type AttributeStmt struct {
	Name  *Ident
	Value Expr
}

AttributeStmt is a key-value pair being set in a Body or BlockStmt.

type BinaryExpr

type BinaryExpr struct {
	Kind        token.Token
	KindPos     token.Pos
	Left, Right Expr
}

BinaryExpr performs a binary operation against two values.

type BlockStmt

type BlockStmt struct {
	Name     []string
	NamePos  token.Pos
	Label    string
	LabelPos token.Pos
	Body     Body

	LCurlyPos, RCurlyPos token.Pos
}

BlockStmt declares a block.

func (*BlockStmt) GetBlockName

func (block *BlockStmt) GetBlockName() string

GetBlockName retrieves the "." delimited block name.

type Body

type Body []Stmt

Body is a list of statements.

type CallExpr

type CallExpr struct {
	Value Expr
	Args  []Expr

	LParenPos, RParenPos token.Pos
}

CallExpr invokes a function value with a set of arguments.

type Comment

type Comment struct {
	StartPos token.Pos // Starting position of comment
	// Text of the comment. Text will not contain '\n' for line comments.
	Text string
}

A Comment represents a single line or block comment.

The Text field contains the comment text without any carriage returns (\r) that may have been present in the source. Since carriage returns get removed, EndPos will not be accurate for any comment which contained carriage returns.

type CommentGroup

type CommentGroup []*Comment

A CommentGroup represents a sequence of comments that are not separated by any empty lines or other non-comment tokens.

type Expr

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

Expr is an expression within the AST.

type File

type File struct {
	Name     string         // Filename provided to parser
	Body     Body           // Content of File
	Comments []CommentGroup // List of all comments in the File
}

File is a parsed file.

type Ident

type Ident struct {
	Name    string
	NamePos token.Pos
}

Ident holds an identifier with its position.

type IdentifierExpr

type IdentifierExpr struct {
	Ident *Ident
}

IdentifierExpr refers to a named value.

type IndexExpr

type IndexExpr struct {
	Value, Index         Expr
	LBrackPos, RBrackPos token.Pos
}

IndexExpr accesses an index in an array value.

type LiteralExpr

type LiteralExpr struct {
	Kind     token.Token
	ValuePos token.Pos

	// Value holds the unparsed literal value. For example, if Kind ==
	// token.STRING, then Value would be wrapped in the original quotes (e.g.,
	// `"foobar"`).
	Value string
}

LiteralExpr is a constant value of a specific token kind.

type Node

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

Node represents any node in the AST.

type ObjectExpr

type ObjectExpr struct {
	Fields               []*ObjectField
	LCurlyPos, RCurlyPos token.Pos
}

ObjectExpr declares an object of key-value pairs.

type ObjectField

type ObjectField struct {
	Name   *Ident
	Quoted bool // True if the name was wrapped in quotes
	Value  Expr
}

ObjectField defines an individual key-value pair within an object. ObjectField does not implement Node.

type ParenExpr

type ParenExpr struct {
	Inner                Expr
	LParenPos, RParenPos token.Pos
}

ParenExpr represents an expression wrapped in parentheses.

type Stmt

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

Stmt is a type of statement within the body of a file or block.

type UnaryExpr

type UnaryExpr struct {
	Kind    token.Token
	KindPos token.Pos
	Value   Expr
}

UnaryExpr performs a unary operation on a single value.

type Visitor

type Visitor interface {
	Visit(node Node) (w Visitor)
}

A Visitor has its Visit method invoked for each node encountered by Walk. If the resulting visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).

Jump to

Keyboard shortcuts

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