Documentation
¶
Index ¶
- func Parse(text string, filepath string, parserOptions ParserOptions) (*syntax.File, error)
- func Print(originalText string, filepath string, syntaxOptions SyntaxOptions) (string, error)
- type Comment
- type File
- type Lit
- type Node
- type ParseError
- type ParserOptions
- type Pos
- type PrinterOptions
- type Redirect
- type Result
- type Stmt
- type SyntaxOptions
- type Word
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
`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 ¶
func (Comment) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Comment) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Comment) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Comment) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type File ¶
func (File) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (File) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*File) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*File) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type Lit ¶
func (Lit) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Lit) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Lit) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Lit) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type Node ¶
func (Node) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Node) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Node) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Node) UnmarshalJSON ¶
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 ¶
func (Pos) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Pos) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Pos) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Pos) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type PrinterOptions ¶
type Redirect ¶
func (Redirect) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Redirect) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Redirect) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Redirect) UnmarshalJSON ¶
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 ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Result) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Result) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Result) UnmarshalJSON ¶
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 ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Stmt) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Stmt) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Stmt) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type SyntaxOptions ¶
type SyntaxOptions struct {
ParserOptions
PrinterOptions
}
type Word ¶
func (Word) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Word) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Word) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Word) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface