Help us shape the future of Go! Take the 2026 Go Developer Survey

parser

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package parser exposes the public Parse / ParseString entry points and the typed ParseError returned on failure. Implementation lives in parser.go and translate.go.

ParseError is re-exported from the top-level gobash package as gobash.ParseError via a type alias so consumers can use either spelling interchangeably (see errors.go in the root package).

Index

Constants

View Source
const (
	// MaxInputSize caps the byte length of a single Parse call.
	MaxInputSize = 1 << 20 // 1 MiB

	// MaxTokens caps the number of syntax-tree nodes the parser walks
	// after a successful parse. We count syntax.Walk visits.
	MaxTokens = 100000

	// MaxParserDepth caps how deep the translator may recurse while
	// walking nested commands / words / heredocs.
	MaxParserDepth = 200

	// MaxHeredocSize caps the body of any single here-document.
	// Mirrors the DefaultLimits().MaxHeredocSize used at runtime.
	MaxHeredocSize = 10 * 1024 * 1024
)

Parser-side hard limits enforced by Parse / ParseString. The values are law; do not adjust without updating The spec.

Variables

This section is empty.

Functions

func Parse

func Parse(src string) (*ast.Script, error)

Parse parses src into a typed *ast.Script, enforcing the parser-side hard limits in this package. Returns *ParseError on failure.

func ParseString

func ParseString(src string) (*ast.Script, error)

ParseString is an alias for Parse, mirroring src/parser/parser.ts.

func ParseWithLimits

func ParseWithLimits(src string, limits Limits) (*ast.Script, error)

ParseWithLimits parses src using the supplied input and heredoc budgets.

Types

type Limits

type Limits struct {
	MaxInputSize   int
	MaxHeredocSize int
}

Limits controls parser input and heredoc budgets. A zero value is a real zero-byte budget; use DefaultLimits for the compatibility defaults.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns the parser budgets used by Parse.

type ParseError

type ParseError struct {
	Msg  string
	Line int
	Col  int
}

ParseError reports a syntactic parse failure produced by the parser front-end. Line and Col are 1-based when known and 0 when the parser did not supply a position.

func (*ParseError) Error

func (e *ParseError) Error() string

Jump to

Keyboard shortcuts

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