processor

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(text string, filepath string, parserOptions ParserOptions) (*syntax.File, error)

`Parse` converts shell script text into a structured syntax tree. It assembles parser options based on the provided configuration—such as whether to keep comments, the shell syntax variant to use, an optional stopping point, and the desired error recovery level. The supplied file path is used for contextual error reporting. It returns a syntax.File representing the parsed script, or an error if parsing fails.

func Print

func Print(originalText string, filepath string, syntaxOptions SyntaxOptions) (string, error)

`Print` returns the formatted shell script defined in originalText. It first parses the input using the parser options in syntaxOptions and then prints the resulting syntax tree using printer options—including indentation, single-line formatting, and others. The filepath parameter is used for context in error messages. On success, Print returns the formatted script as a string, or an error if parsing or printing fails.

Types

type Comment

type Comment struct {
	Hash Pos
	Text string
	Pos  Pos
	End  Pos
}

func (Comment) MarshalEasyJSON

func (v Comment) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Comment) MarshalJSON

func (v Comment) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Comment) UnmarshalEasyJSON

func (v *Comment) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Comment) UnmarshalJSON

func (v *Comment) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type File

type File struct {
	Name string
	Stmt []Stmt
	Last []Comment
	Pos  Pos
	End  Pos
}

func MapFile

func MapFile(file syntax.File) File

func (File) MarshalEasyJSON

func (v File) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (File) MarshalJSON

func (v File) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*File) UnmarshalEasyJSON

func (v *File) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*File) UnmarshalJSON

func (v *File) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Lit

type Lit struct {
	ValuePos Pos
	ValueEnd Pos
	Value    string
	Pos      Pos
	End      Pos
}

func (Lit) MarshalEasyJSON

func (v Lit) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Lit) MarshalJSON

func (v Lit) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Lit) UnmarshalEasyJSON

func (v *Lit) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Lit) UnmarshalJSON

func (v *Lit) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Node

type Node struct {
	Pos Pos
	End Pos
}

func (Node) MarshalEasyJSON

func (v Node) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Node) MarshalJSON

func (v Node) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Node) UnmarshalEasyJSON

func (v *Node) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Node) UnmarshalJSON

func (v *Node) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ParseError

type ParseError struct {
	syntax.ParseError
	Pos Pos
}

func MapParseError

func MapParseError(err error) (*ParseError, string)

func (ParseError) MarshalEasyJSON

func (v ParseError) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (ParseError) MarshalJSON

func (v ParseError) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*ParseError) UnmarshalEasyJSON

func (v *ParseError) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*ParseError) UnmarshalJSON

func (v *ParseError) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ParserOptions

type ParserOptions struct {
	KeepComments  bool
	Variant       syntax.LangVariant
	StopAt        string
	RecoverErrors int
}

type Pos

type Pos struct {
	Offset uint
	Line   uint
	Col    uint
}

func (Pos) MarshalEasyJSON

func (v Pos) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Pos) MarshalJSON

func (v Pos) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Pos) UnmarshalEasyJSON

func (v *Pos) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Pos) UnmarshalJSON

func (v *Pos) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type PrinterOptions

type PrinterOptions struct {
	Indent           uint
	BinaryNextLine   bool
	SwitchCaseIndent bool
	SpaceRedirects   bool
	KeepPadding      bool
	Minify           bool
	SingleLine       bool
	FunctionNextLine bool
}

type Redirect

type Redirect struct {
	OpPos Pos
	Op    string
	N     *Lit
	Word  *Word
	Hdoc  *Word
	Pos   Pos
	End   Pos
}

func (Redirect) MarshalEasyJSON

func (v Redirect) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Redirect) MarshalJSON

func (v Redirect) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Redirect) UnmarshalEasyJSON

func (v *Redirect) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Redirect) UnmarshalJSON

func (v *Redirect) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Result

type Result struct {
	File        `json:"file"`
	Text        string `json:"text"`
	*ParseError `json:"parseError"`
	Message     string `json:"message"`
}

func (Result) MarshalEasyJSON

func (v Result) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Result) MarshalJSON

func (v Result) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Result) UnmarshalEasyJSON

func (v *Result) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Result) UnmarshalJSON

func (v *Result) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Stmt

type Stmt struct {
	Comments   []Comment
	Cmd        *Node
	Position   Pos
	Semicolon  Pos
	Negated    bool
	Background bool
	Coprocess  bool
	Redirs     []Redirect
	Pos        Pos
	End        Pos
}

func (Stmt) MarshalEasyJSON

func (v Stmt) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Stmt) MarshalJSON

func (v Stmt) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Stmt) UnmarshalEasyJSON

func (v *Stmt) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Stmt) UnmarshalJSON

func (v *Stmt) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type SyntaxOptions

type SyntaxOptions struct {
	ParserOptions
	PrinterOptions
}

type Word

type Word struct {
	Parts []Node
	Lit   string
	Pos   Pos
	End   Pos
}

func (Word) MarshalEasyJSON

func (v Word) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Word) MarshalJSON

func (v Word) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Word) UnmarshalEasyJSON

func (v *Word) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Word) UnmarshalJSON

func (v *Word) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

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