interp

package
v0.0.0-...-f53276d Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package interp implements an interpreter for the Shell Command Language (POSIX.1-2017).

Index

Constants

View Source
const ADD_ASSIGN = 57361
View Source
const AND_ASSIGN = 57365
View Source
const DEC = 57349
View Source
const DIV_ASSIGN = 57359
View Source
const EQ = 57354
View Source
const GE = 57353
View Source
const IDENT = 57347
View Source
const IFS = " \t\n"
View Source
const INC = 57348
View Source
const LAND = 57356
View Source
const LE = 57352
View Source
const LOR = 57357
View Source
const LSH = 57350
View Source
const LSH_ASSIGN = 57363
View Source
const MOD_ASSIGN = 57360
View Source
const MUL_ASSIGN = 57358
View Source
const NE = 57355
View Source
const NUMBER = 57346
View Source
const OR_ASSIGN = 57367
View Source
const RSH = 57351
View Source
const RSH_ASSIGN = 57364
View Source
const SUB_ASSIGN = 57362
View Source
const XOR_ASSIGN = 57366

Variables

This section is empty.

Functions

This section is empty.

Types

type ArithExprError

type ArithExprError struct {
	Expr string
	Msg  string
}

ArithExprError represents an arithmetic expression error.

func (ArithExprError) Error

func (e ArithExprError) Error() string

type ExecEnv

type ExecEnv struct {
	Args    []string
	Opts    Option
	Aliases map[string]string
	// contains filtered or unexported fields
}

ExecEnv represents a shell execution environment.

func NewExecEnv

func NewExecEnv(name string, args ...string) *ExecEnv

NewExecEnv returns a new ExecEnv.

func (*ExecEnv) Eval

func (env *ExecEnv) Eval(expr string) (n int, err error)

Eval evaluates an arithmetic expression.

func (*ExecEnv) Expand

func (env *ExecEnv) Expand(word ast.Word, mode ExpMode) ([]string, error)

Expand expands a word into multiple fields.

func (*ExecEnv) Get

func (env *ExecEnv) Get(name string) (v Var, set bool)

Get retrieves the variable named by the name.

func (*ExecEnv) Set

func (env *ExecEnv) Set(name, value string)

Set sets the value of the variable named by the name.

func (*ExecEnv) Unset

func (env *ExecEnv) Unset(name string)

Unset unsets the variable named by the name.

func (*ExecEnv) Walk

func (env *ExecEnv) Walk(fn func(Var))

Walk walks the variables, calling fn for each.

type ExpMode

type ExpMode uint

ExpMode controls the behavior of word expansions.

const (
	// Expand a word into a single field, field splitting and pathname
	// expansion will no be performed. The result will be converted the
	// simplest form of parameter expansions into ANSI C style
	// identifiers except for special parameters and positional
	// parameters.
	Arith ExpMode = 1 << iota

	// Expands multiple tilde-prefixes in a word as if it is in an
	// assignment.
	Assign

	// Expand a word into a single field, field splitting and pathname
	// expansion will not be performed.
	Literal

	// Expand a word into a single field, field splitting and pathname
	// expansion will not be performed. The result will be retained if
	// '?', '*', and '[' are quoted.
	Pattern

	// Expands a word as if it is within double-quotes, field splitting
	// and pathname expansion will not be performed.
	Quote
)

type Option

type Option uint

Option represents a shell option.

const (
	AllExport Option = 1 << iota
	ErrExit
	IgnoreEOF
	Monitor
	NoClobber
	NoGlob
	NoExec
	NoLog
	Notify
	NoUnset
	Verbose
	Vi
	XTrace
)

func (Option) String

func (o Option) String() string

type ParamExpError

type ParamExpError struct {
	ParamExp *ast.ParamExp
	Msg      string
}

ParamExpError represents an error in parameter expansion.

func (ParamExpError) Error

func (e ParamExpError) Error() string

type Var

type Var struct {
	Name  string
	Value string

	Export   bool
	ReadOnly bool
}

Var represents a variable.

Jump to

Keyboard shortcuts

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