shellsyntax

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args added in v0.3.0

func Args(words []*syntax.Word) ([]string, bool)

func EnvArgs added in v0.3.0

func EnvArgs(args []*syntax.Word) ([]*syntax.Word, string)

func Heredoc added in v0.3.0

func Heredoc(redirect *syntax.Redirect, partial bool) (string, bool)

func InterpreterIdentity

func InterpreterIdentity(interpreter string) string

InterpreterIdentity normalizes an interpreter path for policy comparisons.

func IsBatch

func IsBatch(input string) bool

IsBatch recognizes interpreter boundaries outside incomplete shell constructs.

func IsDigits added in v0.3.0

func IsDigits(value string) bool

func Literal added in v0.3.0

func Literal(word *syntax.Word) (string, bool)

func LiteralParts added in v0.3.0

func LiteralParts(parts []syntax.WordPart, quoted bool) bool

func Operand added in v0.3.0

func Operand(word *syntax.Word) (value string, glob bool, ok bool)

func Quote

func Quote(value string) string

Quote preserves a literal shell argument, including empty strings.

func QuoteArgument added in v0.3.0

func QuoteArgument(value string) string

func Split

func Split(input string) ([]string, error)

Split starts programs at column-zero interpreter headers outside shell constructs. Headers stay with their programs; all other source bytes remain unchanged. Only an omitted params directive inherits the preceding complete object.

func SplitSource

func SplitSource(input string) []string

SplitSource returns authored program slices without validating headers or expanding inherited directives. It is also suitable for unfinished display input.

func StatementSource

func StatementSource(stmt *syntax.Stmt, fallback string) string

StatementSource prints a statement that owns a noncontiguous heredoc body. Other statements keep the caller's source slice and separator policy.

Types

type HeaderError

type HeaderError struct {
	Line int
	Err  error
}

HeaderError locates a rejected header in the submitted program. Line is one-based and counts CRLF as one line terminator, just like header parsing.

func (*HeaderError) Error

func (e *HeaderError) Error() string

func (*HeaderError) Unwrap

func (e *HeaderError) Unwrap() error

type Parsed

type Parsed struct {
	Interpreter []string       `json:"interpreter,omitempty"`
	Body        string         `json:"body,omitempty"`
	Params      map[string]any `json:"params"`
	ParamsLine  int            `json:"paramsLine,omitempty"`
	HasParams   bool           `json:"hasParams,omitzero"`
}

Parsed is the portable shell header result.

func Parse

func Parse(input string) (Parsed, error)

Parse reads the portable interpreter selector and shell directives.

Jump to

Keyboard shortcuts

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