shellsyntax

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 Quote

func Quote(value string) string

Quote preserves a literal shell argument, including empty strings.

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