ast

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package ast defines spok's abstract syntax tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assign

type Assign struct {
	Value Node  // The value it's set to
	Name  Ident // The name of the identifier
	NodeType
}

Assign holds a global variable assignment.

func (Assign) Literal

func (a Assign) Literal() string

func (Assign) String

func (a Assign) String() string

func (Assign) Write

func (a Assign) Write(s *strings.Builder)

type Command

type Command struct {
	Command string // The shell command to run
	NodeType
}

Command holds a task command.

func (Command) Literal

func (c Command) Literal() string

func (Command) String

func (c Command) String() string

func (Command) Write

func (c Command) Write(s *strings.Builder)

type Comment

type Comment struct {
	Text string // The comment text.
	NodeType
}

Comment holds a comment.

func (Comment) Literal

func (c Comment) Literal() string

Literal returns the go literal version of the comment e.g. "# This is a comment".

func (Comment) String

func (c Comment) String() string

func (Comment) Write

func (c Comment) Write(s *strings.Builder)

type Function

type Function struct {
	Name      Ident  // Function name
	Arguments []Node // Functions arguments
	NodeType
}

Function holds a spok builtin function e.g. 'exec' or 'join'.

func (Function) Literal

func (f Function) Literal() string

func (Function) String

func (f Function) String() string

func (Function) Write

func (f Function) Write(s *strings.Builder)

type Ident

type Ident struct {
	Name string // The name of the identifier.
	NodeType
}

Ident holds an identifier.

func (Ident) Literal

func (i Ident) Literal() string

Literal returns the go representation of an Ident e.g. "GLOBAL".

func (Ident) String

func (i Ident) String() string

func (Ident) Write

func (i Ident) Write(s *strings.Builder)

type Node

type Node interface {
	Type() NodeType           // Return the type of the current node.
	String() string           // Pretty print the node.
	Literal() string          // The go literal representation of the node, saves us from using type conversion.
	Write(s *strings.Builder) // Write the formatted syntax back out to a builder.
}

Node is an element in the AST.

type NodeType

type NodeType int

NodeType identifies the type of an AST node.

const (
	NodeComment  NodeType = iota // A spok comment, preceded by a '#'.
	NodeIdent                    // An identifier e.g. global variable or name of a task.
	NodeAssign                   // A global variable assignment.
	NodeString                   // A quoted string literal e.g "hello".
	NodeFunction                 // A spok builtin function e.g. exec
	NodeTask                     // A spok task.
	NodeCommand                  // A spok task command.
)

func (NodeType) String

func (i NodeType) String() string

func (NodeType) Type

func (t NodeType) Type() NodeType

Type returns itself and allows easy embedding into AST nodes to enable e.g. NodeTask.Type().

type String

type String struct {
	Text string
	NodeType
}

String holds a string.

func (String) Literal

func (s String) Literal() string

Literal returns the go literal value of the string, usable in source code e.g. "hello".

func (String) String

func (s String) String() string

String returns the pretty representation of a string, used for printing out a spokfile during e.g. --fmt.

func (String) Write

func (s String) Write(sb *strings.Builder)

type Task

type Task struct {
	Name         Ident     // The name of the task
	Docstring    Comment   // Task docstring comment
	Dependencies []Node    // Task dependencies
	Outputs      []Node    // Task outputs
	Commands     []Command // Shell commands to run
	NodeType
}

Task holds a spok task.

func (Task) Literal

func (t Task) Literal() string

func (Task) String

func (t Task) String() string

func (Task) Write

func (t Task) Write(s *strings.Builder)

type Tree

type Tree struct {
	Nodes []Node // List of all AST nodes.
}

Tree represents the entire AST for a spokfile.

func (*Tree) Append

func (t *Tree) Append(node Node)

Append adds an AST node to the Tree.

func (*Tree) IsEmpty

func (t *Tree) IsEmpty() bool

IsEmpty returns whether or not the AST contains no nodes i.e. empty file.

func (Tree) String

func (t Tree) String() string

String allows us to pretty print an entire file for e.g. automatic formatting.

func (Tree) Write

func (t Tree) Write(s *strings.Builder)

Write out the entire AST to a strings.Builder.

Jump to

Keyboard shortcuts

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