ast

package
v0.0.0-...-92390f9 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package ast declares the types used to represent syntax trees for the Shell Command Language.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AndOr

type AndOr struct {
	OpPos    Pos       // position of Op
	Op       string    // "&&" or "||" operator
	Pipeline *Pipeline // pipeline
}

AndOr represents a pipeline of the AND-OR list.

func (*AndOr) End

func (ao *AndOr) End() Pos

func (*AndOr) Pos

func (ao *AndOr) Pos() Pos

type AndOrList

type AndOrList struct {
	Pipeline *Pipeline // pipeline
	List     []*AndOr  // pipelines separated by "&&" or "||" operator; or nil
	SepPos   Pos       // position of "&" or ";" operator (zero if there is no operator)
	Sep      string
}

AndOrList represents an AND-OR list.

func (*AndOrList) End

func (c *AndOrList) End() Pos

func (*AndOrList) Pos

func (c *AndOrList) Pos() Pos

type ArithEval

type ArithEval struct {
	Left  Pos  // position of "((" operator
	Expr  Word // expression
	Right Pos  // position of "))" operator
}

ArithEval represents an arithmetic evaluation.

func (*ArithEval) End

func (x *ArithEval) End() Pos

func (*ArithEval) Pos

func (x *ArithEval) Pos() Pos

type ArithExp

type ArithExp struct {
	Left  Pos  // position of "$(("
	Expr  Word // expression
	Right Pos  // position of "))"
}

ArithExp represents an arithmetic expansion.

func (*ArithExp) End

func (w *ArithExp) End() Pos

func (*ArithExp) Pos

func (w *ArithExp) Pos() Pos

type Assign

type Assign struct {
	Name  *Lit
	Op    string
	Value Word
}

Assign represents a variable assignment.

func (*Assign) End

func (a *Assign) End() Pos

func (*Assign) Pos

func (a *Assign) Pos() Pos

type CaseClause

type CaseClause struct {
	Case  Pos         // position of reserved word "case"
	Word  Word        // word
	In    Pos         // position of reserved word "in"
	Items []*CaseItem // patterns and commands; or nil
	Esac  Pos         // position of reserved word "esac"
}

CaseClause represents a case conditional construct.

func (*CaseClause) End

func (x *CaseClause) End() Pos

func (*CaseClause) Pos

func (x *CaseClause) Pos() Pos

type CaseItem

type CaseItem struct {
	Lparen   Pos       // position of "(" operator (zero if there is no "(" operator)
	Patterns []Word    // patterns
	Rparen   Pos       // position of ")" operator
	List     []Command // commands
	Break    Pos       // position of ";;" operator (zero if there is no ";;" operator)
}

CaseItem represents patterns and commands of the case conditional construct.

func (*CaseItem) End

func (ci *CaseItem) End() Pos

func (*CaseItem) Pos

func (ci *CaseItem) Pos() Pos

type Cmd

type Cmd struct {
	Expr   CmdExpr
	Redirs []*Redir
}

Cmd represents a simple command, a compound command, or a function definition command.

func (*Cmd) End

func (c *Cmd) End() Pos

func (*Cmd) Pos

func (c *Cmd) Pos() Pos

type CmdExpr

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

CmdExpr represents a detail of the command.

type CmdSubst

type CmdSubst struct {
	Dollar bool      // whether this is enclosed in "$()".
	Left   Pos       // position of "(" or "`".
	List   []Command // commands
	Right  Pos       // position of ")" or "`".
}

CmdSubst represents a command substisution.

func (*CmdSubst) End

func (w *CmdSubst) End() Pos

func (*CmdSubst) Pos

func (w *CmdSubst) Pos() Pos

type Command

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

Command represents a command.

type Comment

type Comment struct {
	Hash Pos    // position of "#"
	Text string // comment text (excluding "\n")
}

Comment represents a comment.

func (*Comment) End

func (c *Comment) End() Pos

func (*Comment) Pos

func (c *Comment) Pos() Pos

type ElifClause

type ElifClause struct {
	Elif Pos       // position of reserved word "elif"
	Cond []Command // condition
	Then Pos       // position of reserved word "then"
	List []Command // commands
}

ElifClause represents an elif clause of the if conditional construct.

func (*ElifClause) End

func (e *ElifClause) End() Pos

func (*ElifClause) Pos

func (e *ElifClause) Pos() Pos

type ElseClause

type ElseClause struct {
	Else Pos       // position of reserved word "else"
	List []Command // commands
}

ElseClause represents an else clause of the if conditional construct.

func (*ElseClause) End

func (e *ElseClause) End() Pos

func (*ElseClause) Pos

func (e *ElseClause) Pos() Pos

type ElsePart

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

ElsePart represents an elif clause or an else clause.

type ForClause

type ForClause struct {
	For       Pos       // position of reserved word "for"
	Name      *Lit      // variable name
	In        Pos       // position of reserved word "in" (zero if there is no "in")
	Items     []Word    // list of words; or nil
	Semicolon Pos       // position of ";" operator (zero if there is no ";" operator)
	Do        Pos       // position of reserved word "do"
	List      []Command // commands
	Done      Pos       // position of reserved word "done"
}

ForClause represents a for loop.

func (*ForClause) End

func (x *ForClause) End() Pos

func (*ForClause) Pos

func (x *ForClause) Pos() Pos

type FuncDef

type FuncDef struct {
	Name   *Lit    // function name
	Lparen Pos     // position of '(' operator
	Rparen Pos     // position of ')' operator
	Body   Command // compound command
}

FuncDef represents a function definition command.

func (*FuncDef) End

func (x *FuncDef) End() Pos

func (*FuncDef) Pos

func (x *FuncDef) Pos() Pos

type Group

type Group struct {
	Lbrace Pos       // position of reserved word "{"
	List   []Command // commands
	Rbrace Pos       // position of reserved word "}"
}

Group represents a sequence of commands that executes in the current process environment.

func (*Group) End

func (x *Group) End() Pos

func (*Group) Pos

func (x *Group) Pos() Pos

type IfClause

type IfClause struct {
	If   Pos        // position of reserved word "if"
	Cond []Command  // condition
	Then Pos        // position of reserved word "then"
	List []Command  // commands
	Else []ElsePart // elif clauses and/or an else clause
	Fi   Pos        // position of reserved word "fi"
}

IfClause represents an if conditional construct.

func (*IfClause) End

func (x *IfClause) End() Pos

func (*IfClause) Pos

func (x *IfClause) Pos() Pos

type List

type List []*AndOrList

List represents a list of AND-OR lists.

func (List) End

func (c List) End() Pos

func (List) Pos

func (c List) Pos() Pos

type Lit

type Lit struct {
	ValuePos Pos
	Value    string
}

Lit represents a literal string.

func (*Lit) End

func (w *Lit) End() Pos

func (*Lit) Pos

func (w *Lit) Pos() Pos

type Node

type Node interface {
	Pos() Pos // position of the first character of the node
	End() Pos // position of the character immediately after the node
}

Node represents an abstract syntax tree.

type ParamExp

type ParamExp struct {
	Dollar Pos    // position of "$"
	Braces bool   // whether this is enclosed in braces
	Name   *Lit   // parameter name
	OpPos  Pos    // position of Op
	Op     string // operator
	Word   Word   // nil means string length
}

ParamExp represents a parameter expansion.

func (*ParamExp) End

func (w *ParamExp) End() Pos

func (*ParamExp) Pos

func (w *ParamExp) Pos() Pos

type Pipe

type Pipe struct {
	OpPos Pos    // position of Op
	Op    string // "|" operator
	Cmd   *Cmd   // command
}

Pipe represents a command of the pipeline.

func (*Pipe) End

func (p *Pipe) End() Pos

func (*Pipe) Pos

func (p *Pipe) Pos() Pos

type Pipeline

type Pipeline struct {
	Bang Pos     // position of reserved word "!"
	Cmd  *Cmd    // command
	List []*Pipe // commands separated by "|" operator; or nil
}

Pipeline represents a pipeline.

func (*Pipeline) End

func (c *Pipeline) End() Pos

func (*Pipeline) Pos

func (c *Pipeline) Pos() Pos

type Pos

type Pos struct {
	// contains filtered or unexported fields
}

Pos represents a position.

func NewPos

func NewPos(line, col int) Pos

NewPos returns a new Pos.

func (Pos) After

func (p Pos) After(q Pos) bool

After reports whether the position is after q.

func (Pos) Before

func (p Pos) Before(q Pos) bool

Before reports whether the position is before q.

func (Pos) Col

func (p Pos) Col() int

Col returns the column number of the position.

func (Pos) IsZero

func (p Pos) IsZero() bool

IsZero reports whether the position represents no position.

func (Pos) Line

func (p Pos) Line() int

Line returns the line number of the position.

type Quote

type Quote struct {
	TokPos Pos    // position of Tok
	Tok    string // quoting character
	Value  Word
}

Quote represents a quoted WORD token.

func (*Quote) End

func (w *Quote) End() Pos

func (*Quote) Pos

func (w *Quote) Pos() Pos

type Redir

type Redir struct {
	N       *Lit
	OpPos   Pos
	Op      string
	Word    Word
	Heredoc Word // here-document; or nil
	Delim   Word // here-document delimiter; or nil
}

Redir represents an I/O redirection.

func (*Redir) End

func (r *Redir) End() Pos

func (*Redir) Pos

func (r *Redir) Pos() Pos

type SimpleCmd

type SimpleCmd struct {
	Assigns []*Assign // variable assignments; or nil
	Args    []Word    // command line arguments
}

SimpleCmd represents a simple command.

func (*SimpleCmd) End

func (x *SimpleCmd) End() Pos

func (*SimpleCmd) Pos

func (x *SimpleCmd) Pos() Pos

type Subshell

type Subshell struct {
	Lparen Pos       // position of "(" operator
	List   []Command // commands
	Rparen Pos       // position of ")" operator
}

Subshell represents a sequence of commands that executes in a subshell environment.

func (*Subshell) End

func (x *Subshell) End() Pos

func (*Subshell) Pos

func (x *Subshell) Pos() Pos

type UntilClause

type UntilClause struct {
	Until Pos       // position of reserved word "until"
	Cond  []Command // condition
	Do    Pos       // position of reserved word "do"
	List  []Command // commands
	Done  Pos       // position of reserved word "done"
}

UntilClause represents an until loop.

func (*UntilClause) End

func (x *UntilClause) End() Pos

func (*UntilClause) Pos

func (x *UntilClause) Pos() Pos

type WhileClause

type WhileClause struct {
	While Pos       // position of reserved word "while"
	Cond  []Command // condition
	Do    Pos       // position of reserved word "do"
	List  []Command // commands
	Done  Pos       // position of reserved word "done"
}

WhileClause represents a while loop.

func (*WhileClause) End

func (x *WhileClause) End() Pos

func (*WhileClause) Pos

func (x *WhileClause) Pos() Pos

type Word

type Word []WordPart

Word represents a WORD token.

func (Word) End

func (w Word) End() Pos

func (Word) Pos

func (w Word) Pos() Pos

type WordPart

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

WordPart represents a part of the WORD token.

Jump to

Keyboard shortcuts

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