Documentation
¶
Overview ¶
Package syntax reads the text of a bash script into an abstract syntax tree. The tree is the input of the interpreter of hail.
The package is a port of the crate brush-parser of brush, at the release that docs/PORT.md pins. brush is under the MIT license, and LICENSE.brush holds its notice. Each file names the file of brush-parser that it ports.
The package holds the tokenizer, the parser, the tree, the parser of the parts of a word, and the parser of the expressions of test. It answers whether a text is complete, incomplete or wrong, so that the prompt can ask for more input with PS2 (D5).
The package departs from brush in a few places, as docs/PORT.md says. Reader reads a program one complete command at a time, as bash does, where brush-parser reads the whole program first (W28). With ParserOptions.Aliases, the tokenizer expands an alias while it reads, as bash does, where brush expands one when it runs a simple command (W24). The parser keeps the result of one rule of arithmetic for each token, so that a run of "(" does not take exponential time (W25). The parser of words reads ${!}, ${x~} and ${x~~} as bash does, reads a ${...} that matches no form as a WordPieceBadSubstitution, reads [k]+=v in the value of an array as an element that adds. The tokenizer ends a here-document whose tag is written as $'...' or $"..." at the tag that bash uses (W29).
Index ¶
- func ANSIC(text string) string
- func ANSICWith(text string, cs *Codeset) string
- func ArithQuotes(t string) string
- func CommandSubstitutionCloses(text string, options ParserOptions) bool
- func CommandText(c Command, options ParserOptions) string
- func EchoEscapes(text string) (string, bool)
- func EchoEscapesWith(text string, cs *Codeset) (string, bool)
- func FunctionText(name string, body *FunctionBody, multiline bool, options ParserOptions) string
- func ListText(l *CompoundList, options ParserOptions) string
- func SubscriptEnd(s string, open int) (int, bool)
- func SubstText(text string, options ParserOptions) (string, bool)
- func UnicodeText(v uint32) string
- func UnquoteHereTag(s string) string
- func UnquoteStr(s string) string
- func WordText(word string, options ParserOptions) string
- func WriteChar(b *strings.Builder, v rune, cs *Codeset)
- type AndOr
- type AndOrAnd
- type AndOrList
- type AndOrOr
- type ArithmeticCommand
- type ArithmeticExpr
- type ArithmeticExprAssignment
- type ArithmeticExprBinaryAssignment
- type ArithmeticExprBinaryOp
- type ArithmeticExprConditional
- type ArithmeticExprLiteral
- type ArithmeticExprReference
- type ArithmeticExprUnaryAssignment
- type ArithmeticExprUnaryOp
- type ArithmeticForClauseCommand
- type ArithmeticTarget
- type ArithmeticTargetArrayElement
- type ArithmeticTargetVariable
- type Assignment
- type AssignmentArrayElement
- type AssignmentName
- type AssignmentNameArrayElementName
- type AssignmentNameVariableName
- type AssignmentValue
- type AssignmentValueArray
- type AssignmentValueScalar
- type BinaryOperator
- type BinaryPredicate
- type BraceExpression
- type BraceExpressionMember
- type BraceExpressionMemberCharSequence
- type BraceExpressionMemberChild
- type BraceExpressionMemberNumberSequence
- type BraceExpressionOrText
- type BraceExpressionOrTextExpr
- type BraceExpressionOrTextText
- type BraceGroupCommand
- type CaseClauseCommand
- type CaseItem
- type CaseItemPostAction
- type Codeset
- type Command
- type CommandCompound
- type CommandFunction
- type CommandPrefix
- type CommandPrefixOrSuffixItem
- type CommandPrefixOrSuffixItemAssignmentWord
- type CommandPrefixOrSuffixItemIoRedirect
- type CommandPrefixOrSuffixItemProcessSubstitution
- type CommandPrefixOrSuffixItemWord
- type CommandSimple
- type CommandSuffix
- type CompleteCommand
- type CompleteCommandItem
- type CompoundCommand
- type CompoundCommandArithmetic
- type CompoundCommandArithmeticForClause
- type CompoundCommandBraceGroup
- type CompoundCommandCaseClause
- type CompoundCommandCoprocess
- type CompoundCommandExtendedTest
- type CompoundCommandForClause
- type CompoundCommandIfClause
- type CompoundCommandSelectClause
- type CompoundCommandSubshell
- type CompoundCommandUntilClause
- type CompoundCommandWhileClause
- type CompoundList
- type CompoundListItem
- type CoprocessCommand
- type DoGroupCommand
- type DoubleQuotedTextKind
- type ElseClause
- type ErrArithForExpressions
- type ErrCondSyntax
- type ErrExpansionNestingTooDeep
- type ErrFailedDecoding
- type ErrHereDocumentCount
- type ErrMissingHereTag
- type ErrMissingHereTagAtEndOfInput
- type ErrMissingHereTagForDocumentBody
- type ErrParseArithmeticExpression
- type ErrParseBraceExpansion
- type ErrParseParameter
- type ErrParsePattern
- type ErrParsePrompt
- type ErrParseWord
- type ErrParsingAtEndOfInput
- type ErrParsingInArray
- type ErrParsingNear
- type ErrRead
- type ErrSubstSyntax
- type ErrTokenizing
- type ErrUnterminatedAnsiCQuote
- type ErrUnterminatedArithmeticCommand
- type ErrUnterminatedBackquote
- type ErrUnterminatedCommandSubstitution
- type ErrUnterminatedDoubleQuote
- type ErrUnterminatedEscapeSequence
- type ErrUnterminatedExpansion
- type ErrUnterminatedExtendedGlob
- type ErrUnterminatedFunctionSubstitution
- type ErrUnterminatedHereDocuments
- type ErrUnterminatedSingleQuote
- type ErrUnterminatedSubscript
- type ErrUnterminatedVariable
- type ExtendedTestExpr
- type ExtendedTestExprAnd
- type ExtendedTestExprBinaryTest
- type ExtendedTestExprCommand
- type ExtendedTestExprNot
- type ExtendedTestExprOr
- type ExtendedTestExprParenthesized
- type ExtendedTestExprUnaryTest
- type ForClauseCommand
- type FunctionBody
- type FunctionDefinition
- type HereDocCut
- type HereDocLeft
- type IfClauseCommand
- type InputStatus
- type InputUnit
- type IoFd
- type IoFileRedirectKind
- type IoFileRedirectTarget
- type IoFileRedirectTargetDuplicate
- type IoFileRedirectTargetFd
- type IoFileRedirectTargetFilename
- type IoFileRedirectTargetProcessSubstitution
- type IoHereDocument
- type IoRedirect
- type IoRedirectFile
- type IoRedirectHereDocument
- type IoRedirectHereString
- type IoRedirectOutputAndError
- type Locator
- type Node
- type Opener
- type OperatorToken
- type Parameter
- type ParameterExpr
- type ParameterExprAssignDefaultValues
- type ParameterExprIndicateErrorIfNullOrUnset
- type ParameterExprLowercaseFirstChar
- type ParameterExprLowercasePattern
- type ParameterExprMemberKeys
- type ParameterExprParameter
- type ParameterExprParameterLength
- type ParameterExprRemoveLargestPrefixPattern
- type ParameterExprRemoveLargestSuffixPattern
- type ParameterExprRemoveSmallestPrefixPattern
- type ParameterExprRemoveSmallestSuffixPattern
- type ParameterExprReplaceSubstring
- type ParameterExprSubstring
- type ParameterExprToggleCaseFirstChar
- type ParameterExprToggleCasePattern
- type ParameterExprTransform
- type ParameterExprUppercaseFirstChar
- type ParameterExprUppercasePattern
- type ParameterExprUseAlternativeValue
- type ParameterExprUseDefaultValues
- type ParameterExprVariableNames
- type ParameterNamed
- type ParameterNamedWithAllIndices
- type ParameterNamedWithIndex
- type ParameterPositional
- type ParameterSpecial
- type ParameterTestType
- type ParameterTransformOp
- type ParameterTransformOpCapitalizeInitial
- type ParameterTransformOpExpandEscapeSequences
- type ParameterTransformOpPossiblyQuoteWithArraysExpanded
- type ParameterTransformOpPromptExpand
- type ParameterTransformOpQuoted
- type ParameterTransformOpToAssignmentLogic
- type ParameterTransformOpToAttributeFlags
- type ParameterTransformOpToLowerCase
- type ParameterTransformOpToUpperCase
- type ParseError
- type ParseErrorLocation
- type Parser
- type ParserOptions
- type Pipeline
- type PipelineOperator
- type PipelineTimed
- type PipelineTimedTimed
- type PipelineTimedTimedWithPosixOutput
- type Position
- type PositionOffset
- type ProcessSubstitutionKind
- type Program
- type Reader
- type RedirectList
- type SeparatorOperator
- type SimpleCommand
- type Span
- type SpecialParameter
- type SpecialParameterAllPositionalParameters
- type SpecialParameterCurrentOptionFlags
- type SpecialParameterLastBackgroundProcessID
- type SpecialParameterLastExitStatus
- type SpecialParameterPositionalParameterCount
- type SpecialParameterProcessID
- type SpecialParameterShellName
- type SubshellCommand
- type SubstringMatchKind
- type TestCommandParseError
- type TestExpr
- type TestExprAnd
- type TestExprBinaryTest
- type TestExprFalse
- type TestExprLiteral
- type TestExprNot
- type TestExprOr
- type TestExprParenthesized
- type TestExprUnaryTest
- type TildeExpr
- type TildeExprHome
- type TildeExprNthDirFromBottomOfDirStack
- type TildeExprNthDirFromTopOfDirStack
- type TildeExprOldWorkingDir
- type TildeExprUserHome
- type TildeExprWorkingDir
- type Token
- type TokenizerError
- type TokenizerOptions
- type UnaryAssignmentOperator
- type UnaryOperator
- type UnaryPredicate
- type UnexpandedArithmeticExpr
- type WhileOrUntilClauseCommand
- type Word
- type WordParseError
- type WordPiece
- type WordPieceAnsiCQuotedText
- type WordPieceArithmeticExpression
- type WordPieceBackquotedCommandSubstitution
- type WordPieceBadSubstitution
- type WordPieceCommandSubstitution
- type WordPieceDoubleQuotedSequence
- type WordPieceEscapeSequence
- type WordPieceFunctionSubstitution
- type WordPieceGettextDoubleQuotedSequence
- type WordPieceParameterExpansion
- type WordPieceProcessSubstitution
- type WordPieceSingleQuotedText
- type WordPieceText
- type WordPieceTildeExpansion
- type WordPieceWithSource
- type WordToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ANSIC ¶
ANSIC returns the text of an ANSI-C quote, $'...', with its escapes expanded. text is the text between the quotes.
The escapes are \a, \b, \e, \E, \f, \n, \r, \t, \v, \\, \', \", \?, an octal number of one to three digits, \x and one or two hex digits, \u and one to four hex digits, \U and one to eight hex digits, and \c and a character for a control character. A backslash before another character stays, with the character. A NUL character ends the text, as in bash.
func ANSICWith ¶
ANSICWith is ANSIC in the codeset cs, as ansicstr of bash does in the locale: a character of more than one byte is copied whole, so that its trail byte escapes nothing, and \u and \U write their character in cs, as u32cconv of bash does. A character that cs lacks is written as the escape of ISO C, such as \u00E9, as in bash. A nil cs is UTF-8, as for ANSIC.
func ArithQuotes ¶
ArithQuotes returns the text t of an arithmetic expression that the parser read, as in ((...)), $((...)) and for ((...)), with each $'...' outside double quotes replaced by its value in single quotes, as parse_matched_pair of bash replaces it when it reads the text. The expression then holds the single quotes, and is wrong, as in bash, where (( i = $'3' )) is an error. brush has no such step.
func CommandSubstitutionCloses ¶
func CommandSubstitutionCloses(text string, options ParserOptions) bool
CommandSubstitutionCloses reports whether text, the text after the "$(" of a command substitution, holds the ")" that closes it. It finds the ")" as the parser of a word finds it, and does not check the syntax of the command.
func CommandText ¶
func CommandText(c Command, options ParserOptions) string
CommandText returns the text of the command c, as make_command_string of bash returns it.
func EchoEscapes ¶
EchoEscapes returns text with the escapes of echo -e expanded, and whether the text held \c, which ends the output of echo. The escapes are those of ANSIC, except that an octal number starts with \0 and has up to three more digits, and \c ends the text.
func EchoEscapesWith ¶
EchoEscapesWith is EchoEscapes in the codeset cs, as ANSICWith is ANSIC.
func FunctionText ¶
func FunctionText(name string, body *FunctionBody, multiline bool, options ParserOptions) string
FunctionText returns the text of the function name with the body, as named_function_string of bash returns it. When multiline is true, it is the text of declare -f and type, on more than one line. When it is false, it is the value of the variable of an exported function, and name is "". The options of the parser read each command substitution again, as bash prints the text that it read again.
func ListText ¶
func ListText(l *CompoundList, options ParserOptions) string
ListText returns the text of the list l, as bash prints a command that it read, for --pretty-print. bash prints in the mode of POSIX there.
func SubscriptEnd ¶
SubscriptEnd returns the offset of the "]" that closes the subscript that starts with the "[" at the offset open of s, as skipsubscript of bash finds it. A "[" inside opens one more level. A backslash escapes the byte after it. Quotes, `...`, $(...) and ${...} hide the brackets inside them. SubscriptEnd returns false when no "]" closes the subscript.
func SubstText ¶
func SubstText(text string, options ParserOptions) (string, bool)
SubstText returns the text of the command of a command substitution, as print_comsub of bash prints it after it reads the command substitution. bash runs that text, so the lines of the commands in it are the lines of that text. It returns false when the text does not parse.
func UnicodeText ¶
UnicodeText returns the text that bash gives for the escape \u or \U with the value v, in a UTF-8 locale. bash encodes each value below 0x80000000 in the old form of UTF-8 (u32toutf8), which has sequences of up to six bytes. So a surrogate, such as 0xd800, and a value past 0x10ffff get bytes too, where Go gives U+FFFD. A larger value gives no text.
func UnquoteHereTag ¶
UnquoteHereTag returns the end tag of a here-document whose tag is quoted, which is the line that ends its body. It removes the quotes as UnquoteStr does, and also reads $'...' and $"..." as bash 5.3 does. The text of $'...' is the text between the quotes with its escapes expanded, as ANSIC gives it. $"..." is "..." without the "$". So the tag $'EOF' ends at the line EOF.
brush reads the tag with UnquoteStr alone, so the tag $'EOF' ends only at the line $EOF. The port departs from brush here (W29).
func UnquoteStr ¶
UnquoteStr returns s with its quotes removed, as the quote removal of the shell does.
It removes the quote characters that open or close a quote, and each backslash that escapes the character after it. As in the shell, a backslash in single quotes is literal. In double quotes, a backslash escapes only "$", "`", "\"", "\\" and a new line. The function keeps an escaped new line, which the line continuation of the shell removes. It expands nothing, and it does not treat $'...' and $"..." in a special way.
func WordText ¶
func WordText(word string, options ParserOptions) string
WordText returns the text of the word as bash keeps it after it reads it, which bash prints for set -x where it prints a word that it has not expanded: the text of the script, with each $'...' in single quotes, and each command substitution printed again.
Types ¶
type AndOr ¶
type AndOr interface {
Node
// Operator returns the operator of the AndOr.
Operator() PipelineOperator
// contains filtered or unexported methods
}
AndOr is a boolean operator and the pipeline after it.
func NewAndOr ¶
func NewAndOr(op PipelineOperator, p Pipeline) AndOr
NewAndOr returns an AndOr with the operator op and the pipeline p.
type AndOrAnd ¶
type AndOrAnd struct {
// Pipeline is the pipeline after the operator.
Pipeline Pipeline
}
AndOrAnd runs its pipeline only when the command before it succeeded.
func (*AndOrAnd) Location ¶
Location returns the location of the pipeline. It does not include the operator.
func (*AndOrAnd) Operator ¶
func (*AndOrAnd) Operator() PipelineOperator
Operator returns PipelineOperatorAnd.
type AndOrList ¶
type AndOrList struct {
// First is the first pipeline.
First Pipeline
// Additional holds the pipelines after the first, in order.
Additional []AndOr
}
AndOrList is a sequence of pipelines that boolean operators connect.
func (*AndOrList) All ¶
func (l *AndOrList) All() iter.Seq2[PipelineOperator, *Pipeline]
All returns each pipeline of the list with the operator before it. The first pipeline comes with PipelineOperatorAnd.
type AndOrOr ¶
type AndOrOr struct {
// Pipeline is the pipeline after the operator.
Pipeline Pipeline
}
AndOrOr runs its pipeline only when the command before it did not succeed.
func (*AndOrOr) Location ¶
Location returns the location of the pipeline. It does not include the operator.
func (*AndOrOr) Operator ¶
func (*AndOrOr) Operator() PipelineOperator
Operator returns PipelineOperatorOr.
type ArithmeticCommand ¶
type ArithmeticCommand struct {
// Expr is the text of the expression. It is not parsed or expanded.
Expr UnexpandedArithmeticExpr
// Text is the text between "((" and "))" as the script wrote it, with
// its spaces, or "" when the parser does not know it. bash prints this
// text when it prints the command. brush has no such field.
Text string
// Loc is the location of the command.
Loc Span
}
ArithmeticCommand is an arithmetic command. It evaluates an arithmetic expression.
func (*ArithmeticCommand) Location ¶
func (c *ArithmeticCommand) Location() (Span, bool)
Location returns the location of the command.
func (*ArithmeticCommand) String ¶
func (c *ArithmeticCommand) String() string
String returns the expression in "((" and "))".
type ArithmeticExpr ¶
type ArithmeticExpr interface {
Node
// contains filtered or unexported methods
}
ArithmeticExpr is an arithmetic expression.
type ArithmeticExprAssignment ¶
type ArithmeticExprAssignment struct {
// Target is the variable or the element to assign.
Target ArithmeticTarget
// Value is the expression to assign.
Value ArithmeticExpr
}
ArithmeticExprAssignment is an assignment, x = e.
func (*ArithmeticExprAssignment) Location ¶
func (*ArithmeticExprAssignment) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of an arithmetic expression.
func (*ArithmeticExprAssignment) String ¶
func (e *ArithmeticExprAssignment) String() string
String returns the assignment as "x = e".
type ArithmeticExprBinaryAssignment ¶
type ArithmeticExprBinaryAssignment struct {
// Op is the operator.
Op BinaryOperator
// Target is the variable or the element to assign.
Target ArithmeticTarget
// Operand is the expression on the right.
Operand ArithmeticExpr
}
ArithmeticExprBinaryAssignment is an assignment with an operator, such as x += e.
func (*ArithmeticExprBinaryAssignment) Location ¶
func (*ArithmeticExprBinaryAssignment) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of an arithmetic expression.
func (*ArithmeticExprBinaryAssignment) String ¶
func (e *ArithmeticExprBinaryAssignment) String() string
String returns the assignment as "x op= e".
type ArithmeticExprBinaryOp ¶
type ArithmeticExprBinaryOp struct {
// Op is the operator.
Op BinaryOperator
// Left is the expression on the left.
Left ArithmeticExpr
// Right is the expression on the right.
Right ArithmeticExpr
}
ArithmeticExprBinaryOp is an operation on two expressions.
func (*ArithmeticExprBinaryOp) Location ¶
func (*ArithmeticExprBinaryOp) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of an arithmetic expression.
func (*ArithmeticExprBinaryOp) String ¶
func (e *ArithmeticExprBinaryOp) String() string
String returns the two operands with the operator between them. It writes a space on each side of the operator, except for a comma, which gets a space after it only.
type ArithmeticExprConditional ¶
type ArithmeticExprConditional struct {
// Condition is the expression to test.
Condition ArithmeticExpr
// Then is the result when the condition is true.
Then ArithmeticExpr
// Else is the result when the condition is false.
Else ArithmeticExpr
}
ArithmeticExprConditional is a conditional expression, c ? a : b.
func (*ArithmeticExprConditional) Location ¶
func (*ArithmeticExprConditional) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of an arithmetic expression.
func (*ArithmeticExprConditional) String ¶
func (e *ArithmeticExprConditional) String() string
String returns the expression as "c ? a : b".
type ArithmeticExprLiteral ¶
type ArithmeticExprLiteral struct {
// Value is the integer.
Value int64
}
ArithmeticExprLiteral is an integer.
func (*ArithmeticExprLiteral) Location ¶
func (*ArithmeticExprLiteral) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of an arithmetic expression.
func (*ArithmeticExprLiteral) String ¶
func (e *ArithmeticExprLiteral) String() string
String returns the integer in decimal.
type ArithmeticExprReference ¶
type ArithmeticExprReference struct {
// Target is the variable or the element.
Target ArithmeticTarget
}
ArithmeticExprReference is the value of a variable or of an element of an array.
func (*ArithmeticExprReference) Location ¶
func (*ArithmeticExprReference) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of an arithmetic expression.
func (*ArithmeticExprReference) String ¶
func (e *ArithmeticExprReference) String() string
String returns the target.
type ArithmeticExprUnaryAssignment ¶
type ArithmeticExprUnaryAssignment struct {
// Op is the operator.
Op UnaryAssignmentOperator
// Target is the variable or the element to change.
Target ArithmeticTarget
}
ArithmeticExprUnaryAssignment is an increment or a decrement, such as x++.
func (*ArithmeticExprUnaryAssignment) Location ¶
func (*ArithmeticExprUnaryAssignment) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of an arithmetic expression.
func (*ArithmeticExprUnaryAssignment) String ¶
func (e *ArithmeticExprUnaryAssignment) String() string
String returns the target with the operator before it or after it.
type ArithmeticExprUnaryOp ¶
type ArithmeticExprUnaryOp struct {
// Op is the operator.
Op UnaryOperator
// Operand is the expression to operate on.
Operand ArithmeticExpr
}
ArithmeticExprUnaryOp is an operation on one expression.
func (*ArithmeticExprUnaryOp) Location ¶
func (*ArithmeticExprUnaryOp) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of an arithmetic expression.
func (*ArithmeticExprUnaryOp) String ¶
func (e *ArithmeticExprUnaryOp) String() string
String returns the operator and the operand, with no space between them.
type ArithmeticForClauseCommand ¶
type ArithmeticForClauseCommand struct {
// Initializer is evaluated before the first pass of the loop. It is nil
// when the loop has none.
Initializer *UnexpandedArithmeticExpr
// Condition is evaluated before each pass, and ends the loop. It is nil
// when the loop has none.
Condition *UnexpandedArithmeticExpr
// Updater is evaluated after each pass. It is nil when the loop has none.
Updater *UnexpandedArithmeticExpr
// Text is the text between "((" and "))" as the script wrote it, with
// its spaces, or "" when the parser does not know it. bash prints this
// text when it prints the loop. brush has no such field.
Text string
// Body is the command that runs on each pass.
Body DoGroupCommand
// Loc is the location of the loop.
Loc Span
}
ArithmeticForClauseCommand is an arithmetic for loop. It runs until an arithmetic condition is false.
func (*ArithmeticForClauseCommand) Location ¶
func (c *ArithmeticForClauseCommand) Location() (Span, bool)
Location returns the location of the loop.
func (*ArithmeticForClauseCommand) String ¶
func (c *ArithmeticForClauseCommand) String() string
String returns the loop as shell text.
type ArithmeticTarget ¶
type ArithmeticTarget interface {
Node
// contains filtered or unexported methods
}
ArithmeticTarget is the target of an arithmetic assignment.
type ArithmeticTargetArrayElement ¶
type ArithmeticTargetArrayElement struct {
// Name is the name of the array.
Name string
// Index is the expression of the index.
Index ArithmeticExpr
}
ArithmeticTargetArrayElement is an element of an array.
func (*ArithmeticTargetArrayElement) Location ¶
func (*ArithmeticTargetArrayElement) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of an arithmetic target.
func (*ArithmeticTargetArrayElement) String ¶
func (t *ArithmeticTargetArrayElement) String() string
String returns the name of the array and the index in brackets.
type ArithmeticTargetVariable ¶
type ArithmeticTargetVariable struct {
// Name is the name of the variable.
Name string
}
ArithmeticTargetVariable is a variable.
func (*ArithmeticTargetVariable) Location ¶
func (*ArithmeticTargetVariable) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of an arithmetic target.
func (*ArithmeticTargetVariable) String ¶
func (t *ArithmeticTargetVariable) String() string
String returns the name of the variable.
type Assignment ¶
type Assignment struct {
// Name is the target of the assignment.
Name AssignmentName
// Value is the value to assign.
Value AssignmentValue
// Append tells whether the value is added to the value that the variable
// holds (+=).
Append bool
// Loc is the location of the assignment.
Loc Span
}
Assignment is the assignment of a value to a variable.
func ParseScalarAssignment ¶
func ParseScalarAssignment(word string, options ParserOptions) (Assignment, error)
ParseScalarAssignment parses word as an assignment of a scalar, such as x=1 or a[2]+=b. A value in parentheses is read as text. The location of the assignment is the zero Span. The error is an ErrParseWord.
func (*Assignment) Location ¶
func (a *Assignment) Location() (Span, bool)
Location returns the location of the assignment.
func (*Assignment) String ¶
func (a *Assignment) String() string
String returns the assignment as shell text, such as "x+=1".
type AssignmentArrayElement ¶
type AssignmentArrayElement struct {
// Key is the index of the element, as in [2]=b. It is nil when the
// element has no index.
Key *Word
// Value is the value of the element.
Value Word
// Append tells whether the value adds to the element, as in [2]+=b.
// brush-parser reads [2]+=b as a value with no index. bash adds b to
// the element 2, and the port follows bash.
Append bool
}
AssignmentArrayElement is one element of an AssignmentValueArray. It is the Go form of the tuple (Option<Word>, Word) of brush-parser, with the field Append, which brush does not have (W29).
type AssignmentName ¶
type AssignmentName interface {
// BaseName returns the name of the variable, without an index.
BaseName() string
String() string
// contains filtered or unexported methods
}
AssignmentName is the target of an assignment.
type AssignmentNameArrayElementName ¶
type AssignmentNameArrayElementName struct {
// Name is the name of the array.
Name string
// Index is the text of the index.
Index string
}
AssignmentNameArrayElementName is an element of an array.
func (*AssignmentNameArrayElementName) BaseName ¶
func (n *AssignmentNameArrayElementName) BaseName() string
BaseName returns the name of the array.
func (*AssignmentNameArrayElementName) String ¶
func (n *AssignmentNameArrayElementName) String() string
String returns the name and the index in brackets.
type AssignmentNameVariableName ¶
type AssignmentNameVariableName struct {
// Name is the name of the variable.
Name string
}
AssignmentNameVariableName is the name of a variable.
func (*AssignmentNameVariableName) BaseName ¶
func (n *AssignmentNameVariableName) BaseName() string
BaseName returns the name of the variable.
func (*AssignmentNameVariableName) String ¶
func (n *AssignmentNameVariableName) String() string
String returns the name.
type AssignmentValue ¶
type AssignmentValue interface {
Node
// contains filtered or unexported methods
}
AssignmentValue is the value of an assignment.
type AssignmentValueArray ¶
type AssignmentValueArray struct {
// Elements holds the elements, in order.
Elements []AssignmentArrayElement
}
AssignmentValueArray is an array of values, such as (a [2]=b).
func (*AssignmentValueArray) Location ¶
func (v *AssignmentValueArray) Location() (Span, bool)
Location returns the span from the value of the first element to the value of the last. It does not include the parentheses.
func (*AssignmentValueArray) String ¶
func (v *AssignmentValueArray) String() string
String returns the elements in parentheses, such as "(a [2]=b)".
type AssignmentValueScalar ¶
type AssignmentValueScalar struct {
// Word is the value.
Word Word
}
AssignmentValueScalar is a value of one word.
func (*AssignmentValueScalar) Location ¶
func (v *AssignmentValueScalar) Location() (Span, bool)
Location returns the location of the word.
func (*AssignmentValueScalar) String ¶
func (v *AssignmentValueScalar) String() string
String returns the word.
type BinaryOperator ¶
type BinaryOperator int
BinaryOperator is an arithmetic operator with two operands.
const ( // BinaryOperatorPower raises to a power (x ** y). BinaryOperatorPower BinaryOperator = iota // BinaryOperatorMultiply multiplies (x * y). BinaryOperatorMultiply // BinaryOperatorDivide divides (x / y). BinaryOperatorDivide // BinaryOperatorModulo gives the remainder of a division (x % y). BinaryOperatorModulo // BinaryOperatorComma evaluates both operands and gives the right one // (x, y). BinaryOperatorComma // BinaryOperatorAdd adds (x + y). BinaryOperatorAdd // BinaryOperatorSubtract subtracts (x - y). BinaryOperatorSubtract // BinaryOperatorShiftLeft shifts the bits to the left (x << y). BinaryOperatorShiftLeft // BinaryOperatorShiftRight shifts the bits to the right (x >> y). BinaryOperatorShiftRight // BinaryOperatorLessThan compares with less than (x < y). BinaryOperatorLessThan // BinaryOperatorLessThanOrEqualTo compares with less than or equal to // (x <= y). BinaryOperatorLessThanOrEqualTo // BinaryOperatorGreaterThan compares with greater than (x > y). BinaryOperatorGreaterThan // BinaryOperatorGreaterThanOrEqualTo compares with greater than or equal // to (x >= y). BinaryOperatorGreaterThanOrEqualTo // BinaryOperatorEquals compares for equality (x == y). BinaryOperatorEquals // BinaryOperatorNotEquals compares for inequality (x != y). BinaryOperatorNotEquals // BinaryOperatorBitwiseAnd is the bitwise AND (x & y). BinaryOperatorBitwiseAnd // BinaryOperatorBitwiseXor is the bitwise exclusive OR (x ^ y). BinaryOperatorBitwiseXor // BinaryOperatorBitwiseOr is the bitwise OR (x | y). BinaryOperatorBitwiseOr // BinaryOperatorLogicalAnd is the logical AND (x && y). BinaryOperatorLogicalAnd // BinaryOperatorLogicalOr is the logical OR (x || y). BinaryOperatorLogicalOr )
The arithmetic operators with two operands.
func (BinaryOperator) String ¶
func (o BinaryOperator) String() string
String returns the operator, such as "**".
type BinaryPredicate ¶
type BinaryPredicate int
BinaryPredicate is a test with two operands, in a test or an extended test.
const ( // BinaryPredicateFilesReferToSameDeviceAndInodeNumbers tests that two // files have the same device and inode numbers (-ef). BinaryPredicateFilesReferToSameDeviceAndInodeNumbers BinaryPredicate = iota // BinaryPredicateLeftFileIsNewerOrExistsWhenRightDoesNot tests that the // left file is newer than the right file, or exists when the right file // does not (-nt). BinaryPredicateLeftFileIsNewerOrExistsWhenRightDoesNot // BinaryPredicateLeftFileIsOlderOrDoesNotExistWhenRightDoes tests that // the left file is older than the right file, or does not exist when the // right file does (-ot). BinaryPredicateLeftFileIsOlderOrDoesNotExistWhenRightDoes // BinaryPredicateStringExactlyMatchesPattern tests that a string matches // a pattern (==). BinaryPredicateStringExactlyMatchesPattern // BinaryPredicateStringDoesNotExactlyMatchPattern tests that a string // does not match a pattern (!=). BinaryPredicateStringDoesNotExactlyMatchPattern // BinaryPredicateStringMatchesRegex tests that a string matches a regular // expression (=~). BinaryPredicateStringMatchesRegex // BinaryPredicateStringExactlyMatchesString tests that two strings are // the same (==). BinaryPredicateStringExactlyMatchesString // BinaryPredicateStringDoesNotExactlyMatchString tests that two strings // differ (!=). BinaryPredicateStringDoesNotExactlyMatchString // BinaryPredicateStringContainsSubstring tests that a string contains // another string (=~). BinaryPredicateStringContainsSubstring // BinaryPredicateLeftSortsBeforeRight tests that the left value sorts // before the right value (<). BinaryPredicateLeftSortsBeforeRight // BinaryPredicateLeftSortsAfterRight tests that the left value sorts // after the right value (>). BinaryPredicateLeftSortsAfterRight // BinaryPredicateArithmeticEqualTo tests that two numbers are equal // (-eq). BinaryPredicateArithmeticEqualTo // BinaryPredicateArithmeticNotEqualTo tests that two numbers are not // equal (-ne). BinaryPredicateArithmeticNotEqualTo // BinaryPredicateArithmeticLessThan tests that the left number is less // than the right number (-lt). BinaryPredicateArithmeticLessThan // BinaryPredicateArithmeticLessThanOrEqualTo tests that the left number // is less than or equal to the right number (-le). BinaryPredicateArithmeticLessThanOrEqualTo // BinaryPredicateArithmeticGreaterThan tests that the left number is // greater than the right number (-gt). BinaryPredicateArithmeticGreaterThan // BinaryPredicateArithmeticGreaterThanOrEqualTo tests that the left // number is greater than or equal to the right number (-ge). BinaryPredicateArithmeticGreaterThanOrEqualTo )
The tests with two operands.
func (BinaryPredicate) String ¶
func (p BinaryPredicate) String() string
String returns the operator of the test, such as "-nt" or "==".
type BraceExpression ¶
type BraceExpression = []BraceExpressionMember
BraceExpression is a brace expression, such as {a,b} or {1..3}. It holds the members of the expression.
type BraceExpressionMember ¶
type BraceExpressionMember interface {
// contains filtered or unexported methods
}
BraceExpressionMember is a member of a brace expression. The types are BraceExpressionMemberNumberSequence, BraceExpressionMemberCharSequence and BraceExpressionMemberChild.
type BraceExpressionMemberCharSequence ¶
type BraceExpressionMemberCharSequence struct {
// Start is the first character.
Start rune
// End is the last character.
End rune
// Increment is the step from one character to the next.
Increment int64
}
BraceExpressionMemberCharSequence is a sequence of characters, such as {a..e}. It includes the two ends.
type BraceExpressionMemberChild ¶
type BraceExpressionMemberChild struct {
// Children holds the text and the expressions of the member.
Children []BraceExpressionOrText
}
BraceExpressionMemberChild is a member of a list, such as the a of {a,b}. It can hold text and nested brace expressions.
type BraceExpressionMemberNumberSequence ¶
type BraceExpressionMemberNumberSequence struct {
// Start is the first number.
Start int64
// End is the last number.
End int64
// Increment is the step from one number to the next.
Increment int64
// ZeroPaddedWidth is the width to pad each number to with zeros. It is
// set when one of the two ends starts with a zero. It is nil when the
// numbers are not padded.
ZeroPaddedWidth *int
}
BraceExpressionMemberNumberSequence is a sequence of numbers, such as {1..9..2}. It includes the two ends.
type BraceExpressionOrText ¶
type BraceExpressionOrText interface {
// contains filtered or unexported methods
}
BraceExpressionOrText is a part of a word for brace expansion: a brace expression, or other text. The types are BraceExpressionOrTextExpr and BraceExpressionOrTextText.
func ParseBraceExpansions ¶
func ParseBraceExpansions(word string, options ParserOptions) ([]BraceExpressionOrText, error)
ParseBraceExpansions parses word for brace expansion. It returns nil when the word has no part that the grammar of brace expansion reads, which is the None of brush. The error is an ErrParseBraceExpansion.
type BraceExpressionOrTextExpr ¶
type BraceExpressionOrTextExpr struct {
// Expr is the brace expression.
Expr BraceExpression
}
BraceExpressionOrTextExpr is a brace expression.
type BraceExpressionOrTextText ¶
type BraceExpressionOrTextText struct {
// Text is the text.
Text string
}
BraceExpressionOrTextText is text that is not a brace expression.
type BraceGroupCommand ¶
type BraceGroupCommand struct {
// List is the list of commands.
List CompoundList
// Loc is the location of the group.
Loc Span
}
BraceGroupCommand is a group of commands in braces.
func (*BraceGroupCommand) Location ¶
func (c *BraceGroupCommand) Location() (Span, bool)
Location returns the location of the group.
func (*BraceGroupCommand) String ¶
func (c *BraceGroupCommand) String() string
String returns the group as shell text, on more than one line.
type CaseClauseCommand ¶
type CaseClauseCommand struct {
// Value is the value to match.
Value Word
// Cases holds the branches of the command.
Cases []CaseItem
// Loc is the location of the command.
Loc Span
}
CaseClauseCommand is a case command. It selects commands by patterns that match a value.
func (*CaseClauseCommand) Location ¶
func (c *CaseClauseCommand) Location() (Span, bool)
Location returns the location of the command.
func (*CaseClauseCommand) String ¶
func (c *CaseClauseCommand) String() string
String returns the command as shell text. It writes a space after "in", as the shell does when it prints a case command.
type CaseItem ¶
type CaseItem struct {
// Patterns holds the patterns that select the branch.
Patterns []Word
// Cmd is the command that runs when the branch is selected. It is nil
// when the branch has no command.
Cmd *CompoundList
// PostAction is what happens after the command runs.
PostAction CaseItemPostAction
// Loc is the location of the branch. It is nil when it is not known.
Loc *Span
}
CaseItem is one branch of a case command.
type CaseItemPostAction ¶
type CaseItemPostAction int
CaseItemPostAction is what happens after the command of a case branch runs.
const ( // CaseItemPostActionExitCase leaves the case command (;;). CaseItemPostActionExitCase CaseItemPostAction = iota // CaseItemPostActionUnconditionallyExecuteNextCaseItem runs the command // of the next branch, if there is one, without a test of its patterns // (;&). CaseItemPostActionUnconditionallyExecuteNextCaseItem // CaseItemPostActionContinueEvaluatingCases tests the patterns of the // branches that remain, as if this branch did not run (;;&). CaseItemPostActionContinueEvaluatingCases )
The actions after a case branch.
func (CaseItemPostAction) String ¶
func (a CaseItemPostAction) String() string
String returns ";;", ";&" or ";;&".
type Codeset ¶
type Codeset struct {
// CharLen returns the length of the character at the start of s,
// whose first byte is 0x80 or more, or 1 when no valid character
// starts there.
CharLen func(s string) int
// Encode writes the character r, and reports whether the codeset has
// it.
Encode func(r rune) (string, bool)
}
Codeset is how the locale reads and writes its characters, for the escapes of ANSI-C quotes and of echo -e. A nil *Codeset is UTF-8, whose characters of more than one byte hold no ASCII byte.
type Command ¶
type Command interface {
Node
// contains filtered or unexported methods
}
Command is a shell command.
type CommandCompound ¶
type CommandCompound struct {
// Command is the compound command.
Command CompoundCommand
// Redirects holds the redirections of the command. It is nil when the
// command has none.
Redirects *RedirectList
}
CommandCompound is a compound command, made of other commands.
func (*CommandCompound) Location ¶
func (c *CommandCompound) Location() (Span, bool)
Location returns the span from the compound command to its last redirection. When the redirections have no known location, it returns the location of the compound command.
func (*CommandCompound) String ¶
func (c *CommandCompound) String() string
String returns the command and its redirections as shell text.
type CommandFunction ¶
type CommandFunction struct {
// Definition is the definition of the function.
Definition FunctionDefinition
}
CommandFunction defines a shell function.
func (*CommandFunction) Location ¶
func (c *CommandFunction) Location() (Span, bool)
Location returns the location of the function definition.
func (*CommandFunction) String ¶
func (c *CommandFunction) String() string
String returns the function definition as shell text.
type CommandPrefix ¶
type CommandPrefix struct {
// Items holds the items, in order.
Items []CommandPrefixOrSuffixItem
}
CommandPrefix holds the items before the name of a simple command.
func (*CommandPrefix) Location ¶
func (p *CommandPrefix) Location() (Span, bool)
Location returns the span from the first item to the last.
func (*CommandPrefix) String ¶
func (p *CommandPrefix) String() string
String returns the items, with a space between two items.
type CommandPrefixOrSuffixItem ¶
type CommandPrefixOrSuffixItem interface {
Node
// contains filtered or unexported methods
}
CommandPrefixOrSuffixItem is one item before or after the name of a simple command.
type CommandPrefixOrSuffixItemAssignmentWord ¶
type CommandPrefixOrSuffixItemAssignmentWord struct {
// Assignment is the parsed assignment.
Assignment Assignment
// Word is the text of the assignment.
Word Word
}
CommandPrefixOrSuffixItemAssignmentWord is an assignment, such as x=1.
func (*CommandPrefixOrSuffixItemAssignmentWord) Location ¶
func (i *CommandPrefixOrSuffixItemAssignmentWord) Location() (Span, bool)
Location returns the location of the assignment.
func (*CommandPrefixOrSuffixItemAssignmentWord) String ¶
func (i *CommandPrefixOrSuffixItemAssignmentWord) String() string
String returns the text of the assignment.
type CommandPrefixOrSuffixItemIoRedirect ¶
type CommandPrefixOrSuffixItemIoRedirect struct {
// Redirect is the redirection.
Redirect IoRedirect
}
CommandPrefixOrSuffixItemIoRedirect is a redirection.
func (*CommandPrefixOrSuffixItemIoRedirect) Location ¶
func (i *CommandPrefixOrSuffixItemIoRedirect) Location() (Span, bool)
Location returns the location of the redirection.
func (*CommandPrefixOrSuffixItemIoRedirect) String ¶
func (i *CommandPrefixOrSuffixItemIoRedirect) String() string
String returns the redirection as shell text.
type CommandPrefixOrSuffixItemProcessSubstitution ¶
type CommandPrefixOrSuffixItemProcessSubstitution struct {
// Kind is the direction of the substitution.
Kind ProcessSubstitutionKind
// Command is the command that runs in the subshell.
Command SubshellCommand
}
CommandPrefixOrSuffixItemProcessSubstitution is a process substitution, such as <(ls).
func (*CommandPrefixOrSuffixItemProcessSubstitution) Location ¶
func (i *CommandPrefixOrSuffixItemProcessSubstitution) Location() (Span, bool)
Location returns the location of the subshell. It does not include the kind.
func (*CommandPrefixOrSuffixItemProcessSubstitution) String ¶
func (i *CommandPrefixOrSuffixItemProcessSubstitution) String() string
String returns the kind and the subshell in parentheses. The subshell prints its own parentheses too, so the text is like "<(( ls ))".
type CommandPrefixOrSuffixItemWord ¶
type CommandPrefixOrSuffixItemWord struct {
// Word is the word.
Word Word
}
CommandPrefixOrSuffixItemWord is a word.
func (*CommandPrefixOrSuffixItemWord) Location ¶
func (i *CommandPrefixOrSuffixItemWord) Location() (Span, bool)
Location returns the location of the word.
func (*CommandPrefixOrSuffixItemWord) String ¶
func (i *CommandPrefixOrSuffixItemWord) String() string
String returns the word.
type CommandSimple ¶
type CommandSimple struct {
// Command is the simple command.
Command SimpleCommand
}
CommandSimple is a simple command. It runs an external command, a builtin, a shell function or the like.
func (*CommandSimple) Location ¶
func (c *CommandSimple) Location() (Span, bool)
Location returns the location of the simple command.
func (*CommandSimple) String ¶
func (c *CommandSimple) String() string
String returns the command as shell text.
type CommandSuffix ¶
type CommandSuffix struct {
// Items holds the items, in order.
Items []CommandPrefixOrSuffixItem
}
CommandSuffix holds the items after the name of a simple command: words, assignments and redirections.
func (*CommandSuffix) Location ¶
func (s *CommandSuffix) Location() (Span, bool)
Location returns the span from the first item to the last.
func (*CommandSuffix) String ¶
func (s *CommandSuffix) String() string
String returns the items, with a space between two items.
type CompleteCommand ¶
type CompleteCommand = CompoundList
CompleteCommand is a complete shell command.
type CompleteCommandItem ¶
type CompleteCommandItem = CompoundListItem
CompleteCommandItem is one item of a complete shell command.
type CompoundCommand ¶
type CompoundCommand interface {
Node
// contains filtered or unexported methods
}
CompoundCommand is a compound command, which can hold other commands.
type CompoundCommandArithmetic ¶
type CompoundCommandArithmetic struct {
// Command is the arithmetic command.
Command ArithmeticCommand
}
CompoundCommandArithmetic is an arithmetic command, such as ((x+1)).
func (*CompoundCommandArithmetic) Location ¶
func (c *CompoundCommandArithmetic) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandArithmetic) String ¶
func (c *CompoundCommandArithmetic) String() string
String returns the command as shell text.
type CompoundCommandArithmeticForClause ¶
type CompoundCommandArithmeticForClause struct {
// Command is the arithmetic for loop.
Command ArithmeticForClauseCommand
}
CompoundCommandArithmeticForClause is an arithmetic for loop, such as for ((i=0; i<3; i++)).
func (*CompoundCommandArithmeticForClause) Location ¶
func (c *CompoundCommandArithmeticForClause) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandArithmeticForClause) String ¶
func (c *CompoundCommandArithmeticForClause) String() string
String returns the command as shell text.
type CompoundCommandBraceGroup ¶
type CompoundCommandBraceGroup struct {
// Command is the brace group.
Command BraceGroupCommand
}
CompoundCommandBraceGroup is a group of commands in braces.
func (*CompoundCommandBraceGroup) Location ¶
func (c *CompoundCommandBraceGroup) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandBraceGroup) String ¶
func (c *CompoundCommandBraceGroup) String() string
String returns the command as shell text.
type CompoundCommandCaseClause ¶
type CompoundCommandCaseClause struct {
// Command is the case command.
Command CaseClauseCommand
}
CompoundCommandCaseClause is a case command. It selects commands by patterns that match a value.
func (*CompoundCommandCaseClause) Location ¶
func (c *CompoundCommandCaseClause) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandCaseClause) String ¶
func (c *CompoundCommandCaseClause) String() string
String returns the command as shell text.
type CompoundCommandCoprocess ¶
type CompoundCommandCoprocess struct {
// Command is the coprocess.
Command CoprocessCommand
}
CompoundCommandCoprocess is a coprocess. It runs a command asynchronously in a subshell.
func (*CompoundCommandCoprocess) Location ¶
func (c *CompoundCommandCoprocess) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandCoprocess) String ¶
func (c *CompoundCommandCoprocess) String() string
String returns the command as shell text.
type CompoundCommandExtendedTest ¶
type CompoundCommandExtendedTest struct {
// Command is the extended test command.
Command ExtendedTestExprCommand
}
CompoundCommandExtendedTest is an extended test command, such as [[ -f x ]].
func (*CompoundCommandExtendedTest) Location ¶
func (c *CompoundCommandExtendedTest) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandExtendedTest) String ¶
func (c *CompoundCommandExtendedTest) String() string
String returns the expression in "[[ " and " ]]".
type CompoundCommandForClause ¶
type CompoundCommandForClause struct {
// Command is the for loop.
Command ForClauseCommand
}
CompoundCommandForClause is a for loop over a list of values.
func (*CompoundCommandForClause) Location ¶
func (c *CompoundCommandForClause) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandForClause) String ¶
func (c *CompoundCommandForClause) String() string
String returns the command as shell text.
type CompoundCommandIfClause ¶
type CompoundCommandIfClause struct {
// Command is the if command.
Command IfClauseCommand
}
CompoundCommandIfClause is an if command.
func (*CompoundCommandIfClause) Location ¶
func (c *CompoundCommandIfClause) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandIfClause) String ¶
func (c *CompoundCommandIfClause) String() string
String returns the command as shell text.
type CompoundCommandSelectClause ¶
type CompoundCommandSelectClause struct {
// Command is the select command, in the form of a for loop.
Command ForClauseCommand
}
CompoundCommandSelectClause is a select command, which reads the choice of a word of a menu and runs its body for it, until a break. Its syntax is that of a for loop. brush-parser has no select, and the port departs from it here.
func (*CompoundCommandSelectClause) Location ¶
func (c *CompoundCommandSelectClause) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandSelectClause) String ¶
func (c *CompoundCommandSelectClause) String() string
String returns the command as shell text.
type CompoundCommandSubshell ¶
type CompoundCommandSubshell struct {
// Command is the subshell.
Command SubshellCommand
}
CompoundCommandSubshell is a list of commands that runs in a subshell.
func (*CompoundCommandSubshell) Location ¶
func (c *CompoundCommandSubshell) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandSubshell) String ¶
func (c *CompoundCommandSubshell) String() string
String returns the command as shell text.
type CompoundCommandUntilClause ¶
type CompoundCommandUntilClause struct {
// Command is the loop.
Command WhileOrUntilClauseCommand
}
CompoundCommandUntilClause is an until loop. It runs until a condition is true.
func (*CompoundCommandUntilClause) Location ¶
func (c *CompoundCommandUntilClause) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandUntilClause) String ¶
func (c *CompoundCommandUntilClause) String() string
String returns "until " and the loop as shell text.
type CompoundCommandWhileClause ¶
type CompoundCommandWhileClause struct {
// Command is the loop.
Command WhileOrUntilClauseCommand
}
CompoundCommandWhileClause is a while loop. It runs while a condition is true.
func (*CompoundCommandWhileClause) Location ¶
func (c *CompoundCommandWhileClause) Location() (Span, bool)
Location returns the location of the command.
func (*CompoundCommandWhileClause) String ¶
func (c *CompoundCommandWhileClause) String() string
String returns "while " and the loop as shell text.
type CompoundList ¶
type CompoundList struct {
// Items holds the commands, each with its separator.
Items []CompoundListItem
}
CompoundList is a sequence of commands.
func (*CompoundList) Location ¶
func (l *CompoundList) Location() (Span, bool)
Location returns the span from the first item to the last. It does not include a separator after the last item.
func (*CompoundList) String ¶
func (l *CompoundList) String() string
String returns the list as shell text, one item on each line. It leaves out a ";" after the last item.
type CompoundListItem ¶
type CompoundListItem struct {
// AndOrList is the command of the item.
AndOrList AndOrList
// Separator is the separator after the command.
Separator SeparatorOperator
}
CompoundListItem is one item of a CompoundList.
func (*CompoundListItem) Location ¶
func (i *CompoundListItem) Location() (Span, bool)
Location returns the location of the command. It does not include the separator.
func (*CompoundListItem) String ¶
func (i *CompoundListItem) String() string
String returns the command and its separator.
type CoprocessCommand ¶
type CoprocessCommand struct {
// Name is the name of the coprocess. It is nil when the coprocess has no
// name.
Name *Word
// Body is the command that runs as the coprocess. It can be a simple or a
// compound command.
Body Command
// Loc is the location of the command.
Loc Span
}
CoprocessCommand is a coprocess. It runs a command asynchronously in a subshell.
func (*CoprocessCommand) Location ¶
func (c *CoprocessCommand) Location() (Span, bool)
Location returns the location of the command.
func (*CoprocessCommand) String ¶
func (c *CoprocessCommand) String() string
String returns the command as shell text.
type DoGroupCommand ¶
type DoGroupCommand struct {
// List is the list of commands.
List CompoundList
// Loc is the location of the group.
Loc Span
}
DoGroupCommand is the group of commands between do and done.
func (*DoGroupCommand) String ¶
func (c *DoGroupCommand) String() string
String returns the group as shell text, on more than one line.
type DoubleQuotedTextKind ¶
type DoubleQuotedTextKind int
DoubleQuotedTextKind is a kind of text that is read as if it were in double quotes, but that has no quotes around it. See ParseDoubleQuotedText.
In each kind, only "$", "`" and "\" are special, and "'" is text. The kinds differ in what else a backslash escapes, in whether a '"' is text, and in whether $'...' and $"..." are quotes.
const ( // DoubleQuotedTextHereDoc is the body of a here-document. A backslash // escapes only "$", "`" and "\". A '"', $'...' and $"..." are text. DoubleQuotedTextHereDoc DoubleQuotedTextKind = iota // DoubleQuotedTextPrompt is a prompt string, such as PS1. It is read as // the body of a here-document, but \" stands for '"', and a backslash // before a new line removes both. DoubleQuotedTextPrompt // DoubleQuotedTextWordInHereDocOrPrompt is the word of a parameter // expansion, such as the word of ${param:-word}, in the body of a // here-document or in a prompt. It is read as a prompt, but its own '"' // characters are removed, \} stands for "}", and between a pair of its // quotes a backslash escapes any character. DoubleQuotedTextWordInHereDocOrPrompt // DoubleQuotedTextWordInDoubleQuotes is the word of such a parameter // expansion in double quotes, as in "${param:-word}". It is read as // DoubleQuotedTextWordInHereDocOrPrompt, but outside the quotes of the // word, $'...' is text in ANSI-C quotes and $"..." is a double-quoted // string to translate. DoubleQuotedTextWordInDoubleQuotes )
The kinds of double-quoted text.
func (DoubleQuotedTextKind) Quote ¶
func (k DoubleQuotedTextKind) Quote(text string) string
Quote returns text with a backslash before each character that is special in text of the kind. ParseDoubleQuotedText reads the result, as text of the kind, as the text given.
func (DoubleQuotedTextKind) String ¶
func (k DoubleQuotedTextKind) String() string
String returns the name of the kind in brush.
type ElseClause ¶
type ElseClause struct {
// Condition is the condition of an elif clause. It is nil for an else
// clause.
Condition *CompoundList
// Body is the command that runs when the clause is selected.
Body CompoundList
}
ElseClause is an elif clause or an else clause of an if command.
func (*ElseClause) String ¶
func (c *ElseClause) String() string
String returns the clause as shell text. It starts with a new line.
type ErrArithForExpressions ¶
type ErrArithForExpressions struct {
// Count is the number of expressions, which is not 3.
Count int
// Text is the text between "((" and "))".
Text string
// Position is the start of the word for.
Position Position
// Brush is the error that brush-parser gives for the same input.
Brush ParseError
}
ErrArithForExpressions is a syntax error in the header of an arithmetic for loop that does not hold three expressions, as in for ((i=0; i<3)). brush-parser reports it as an ErrParsingNear, and the port departs from it here. bash reports how many expressions it found, and the header.
func (ErrArithForExpressions) Error ¶
func (e ErrArithForExpressions) Error() string
Error returns the text of the error that brush-parser gives, so that the errors of the two parsers read the same. Message returns the message of bash.
func (ErrArithForExpressions) Message ¶
func (e ErrArithForExpressions) Message() string
Message returns the message of bash.
type ErrCondSyntax ¶
type ErrCondSyntax struct {
// Message is the message of the parser of [[ ]], such as "unexpected
// token `&' in conditional command". It is "" when bash prints none,
// as in [[ ]].
Message string
// MessageLine is the line that the message names.
MessageLine int
// Near is the token that bash names after "syntax error near", and
// NearPosition is where it starts.
Near string
NearPosition Position
// AtEnd is true when the input ends inside the command. The message
// then comes before the error of the end of the file.
AtEnd bool
// Brush is the error that brush-parser gives for the same input.
Brush ParseError
}
ErrCondSyntax is a syntax error in an extended test command, [[ ]].
func CondErrorAtEnd ¶
func CondErrorAtEnd(text string, options ParserOptions) (ErrCondSyntax, bool)
CondErrorAtEnd returns the error of the extended test command that the end of text cuts short, as bash reports it before the error of the end of the file. ok is false when text holds no such command.
func (ErrCondSyntax) Error ¶
func (e ErrCondSyntax) Error() string
Error returns the text of the error that brush-parser gives, so that the errors of the two parsers read the same. The fields hold the message of bash.
type ErrExpansionNestingTooDeep ¶
type ErrExpansionNestingTooDeep struct{}
ErrExpansionNestingTooDeep is the error for expansions in brackets ($(...), $((...)), $[...] and ${...}) that nest deeper than maxExpansionNesting.
func (ErrExpansionNestingTooDeep) Error ¶
func (ErrExpansionNestingTooDeep) Error() string
Error returns the message of the error.
func (ErrExpansionNestingTooDeep) IsIncomplete ¶
func (ErrExpansionNestingTooDeep) IsIncomplete() bool
IsIncomplete returns false.
type ErrFailedDecoding ¶
type ErrFailedDecoding struct{}
ErrFailedDecoding is the error for input that is not UTF-8.
func (ErrFailedDecoding) Error ¶
func (ErrFailedDecoding) Error() string
Error returns the message of the error.
func (ErrFailedDecoding) IsIncomplete ¶
func (ErrFailedDecoding) IsIncomplete() bool
IsIncomplete returns false.
type ErrHereDocumentCount ¶
type ErrHereDocumentCount struct {
// Pos is the position after the tag of the here-document.
Pos Position
}
ErrHereDocumentCount is the error for a here-document past the maxHereDocs that wait for their bodies. bash then ends the shell. brush has no such error.
func (ErrHereDocumentCount) Error ¶
func (e ErrHereDocumentCount) Error() string
Error returns the message of the error.
func (ErrHereDocumentCount) IsIncomplete ¶
func (ErrHereDocumentCount) IsIncomplete() bool
IsIncomplete returns false.
type ErrMissingHereTag ¶
type ErrMissingHereTag struct {
// Found is the operator that the tokenizer found.
Found string
}
ErrMissingHereTag is the error for an operator (such as a newline, ";" or ")") in the place of the tag after a here-document operator (<< or <<-).
func (ErrMissingHereTag) Error ¶
func (e ErrMissingHereTag) Error() string
Error returns the message of the error.
func (ErrMissingHereTag) IsIncomplete ¶
func (ErrMissingHereTag) IsIncomplete() bool
IsIncomplete returns false.
type ErrMissingHereTagAtEndOfInput ¶
type ErrMissingHereTagAtEndOfInput struct{}
ErrMissingHereTagAtEndOfInput is the error for input that ends after a here-document operator (<< or <<-) and before its tag, but not right at the operator. An example is input that ends with blanks after the operator. Input that ends right at the operator gives no error, and the parser reports the end. More input can supply the tag.
func (ErrMissingHereTagAtEndOfInput) Error ¶
func (ErrMissingHereTagAtEndOfInput) Error() string
Error returns the message of the error.
func (ErrMissingHereTagAtEndOfInput) IsIncomplete ¶
func (ErrMissingHereTagAtEndOfInput) IsIncomplete() bool
IsIncomplete returns true.
type ErrMissingHereTagForDocumentBody ¶
type ErrMissingHereTagForDocumentBody struct{}
ErrMissingHereTagForDocumentBody is the error for the body of a here-document that has no tag. It shows a fault in the state of the tokenizer, not in the input.
func (ErrMissingHereTagForDocumentBody) Error ¶
func (ErrMissingHereTagForDocumentBody) Error() string
Error returns the message of the error.
func (ErrMissingHereTagForDocumentBody) IsIncomplete ¶
func (ErrMissingHereTagForDocumentBody) IsIncomplete() bool
IsIncomplete returns false.
type ErrParseArithmeticExpression ¶
type ErrParseArithmeticExpression struct {
// Location is where the parse failed.
Location ParseErrorLocation
}
ErrParseArithmeticExpression is the error of an arithmetic expression that does not parse.
func (ErrParseArithmeticExpression) Error ¶
func (ErrParseArithmeticExpression) Error() string
Error returns the text of the error.
type ErrParseBraceExpansion ¶
type ErrParseBraceExpansion struct {
// Text is the word that did not parse.
Text string
// Location is where the parse failed.
Location ParseErrorLocation
}
ErrParseBraceExpansion is the error of a word that does not parse for brace expansion.
func (ErrParseBraceExpansion) Error ¶
func (e ErrParseBraceExpansion) Error() string
Error returns the text of the error, which quotes the word.
type ErrParseParameter ¶
type ErrParseParameter struct {
// Text is the text that did not parse.
Text string
// Location is where the parse failed.
Location ParseErrorLocation
}
ErrParseParameter is the error of a parameter that does not parse.
func (ErrParseParameter) Error ¶
func (e ErrParseParameter) Error() string
Error returns the text of the error, which quotes the parameter.
type ErrParsePattern ¶
type ErrParsePattern struct {
// Location is where the parse failed.
Location ParseErrorLocation
}
ErrParsePattern is the error of a shell pattern that does not parse.
func (ErrParsePattern) Error ¶
func (ErrParsePattern) Error() string
Error returns the text of the error.
type ErrParsePrompt ¶
type ErrParsePrompt struct {
// Location is where the parse failed.
Location ParseErrorLocation
}
ErrParsePrompt is the error of a prompt string that does not parse.
func (ErrParsePrompt) Error ¶
func (ErrParsePrompt) Error() string
Error returns the text of the error.
type ErrParseWord ¶
type ErrParseWord struct {
// Text is the word that did not parse.
Text string
// Location is where the parse failed.
Location ParseErrorLocation
}
ErrParseWord is the error of a word that does not parse.
func (ErrParseWord) Error ¶
func (e ErrParseWord) Error() string
Error returns the text of the error, which quotes the word.
type ErrParsingAtEndOfInput ¶
type ErrParsingAtEndOfInput struct {
// Array is the position of the "(" of the value of an assignment of an
// array that the input does not close, as in a=(1 2, or nil. bash reads
// the value as it reads the word, and reports the ")" that it looks
// for. brush has no such field.
Array *Position
// Opener is the innermost compound command that the input does not
// close, such as an if or a "{", when the shell knows it, or nil. bash
// names it. brush has no such field.
Opener *Opener
}
ErrParsingAtEndOfInput is a syntax error at the end of the input. The input stops before the end of a command, so more input can complete it.
func (ErrParsingAtEndOfInput) Error ¶
func (ErrParsingAtEndOfInput) Error() string
Error returns the text of the error.
type ErrParsingInArray ¶
type ErrParsingInArray struct {
// Near is the error at the token that cannot be in the value.
Near ErrParsingNear
}
ErrParsingInArray is a syntax error in the value of an assignment of an array, such as the "&" of a=(x & y). brush-parser reports it as an ErrParsingNear, and the port departs from it here. bash reports it as it reads the value, and then drops the rest of the line and goes on with the next line, with the status 1. Reader goes on in the same way after it.
func (ErrParsingInArray) Error ¶
func (e ErrParsingInArray) Error() string
Error returns the text of the error near the token.
func (ErrParsingInArray) Unwrap ¶
func (e ErrParsingInArray) Unwrap() error
Unwrap returns the error near the token.
type ErrParsingNear ¶
type ErrParsingNear struct {
// Position is the start of the token where the parser failed.
Position Position
}
ErrParsingNear is a syntax error near a token.
func (ErrParsingNear) Error ¶
func (e ErrParsingNear) Error() string
Error returns the text of the error, with the line and the column of the token.
type ErrRead ¶
type ErrRead struct {
// Err is the error of the read.
Err error
}
ErrRead is the error for a read of the input that failed.
type ErrSubstSyntax ¶
type ErrSubstSyntax struct {
// Near is where the token that bash names starts. It is nil when the
// command ends too soon, and bash then names the closing character.
Near *Position
// Closer is the character that closes the command substitution: ")"
// for $(command), or "}" for ${ command; }.
Closer rune
}
ErrSubstSyntax is a syntax error in the command of a command substitution, which bash finds when it reads the script, and not when the command runs. The Reader finds it as bash does. brush does not have it.
func (ErrSubstSyntax) Error ¶
func (e ErrSubstSyntax) Error() string
Error returns the message of the error.
func (ErrSubstSyntax) IsIncomplete ¶
func (ErrSubstSyntax) IsIncomplete() bool
IsIncomplete returns false.
type ErrTokenizing ¶
type ErrTokenizing struct {
// Inner is the error of the tokenizer.
Inner TokenizerError
// Position is the position of the tokenizer when it failed. It is nil
// when the position is not known.
Position *Position
}
ErrTokenizing is an error of the tokenizer, found while the parser read the input.
func (ErrTokenizing) Error ¶
func (e ErrTokenizing) Error() string
Error returns the text of the inner error, and the position, such as "unterminated expansion (detected near line 2 col 4)".
func (ErrTokenizing) Unwrap ¶
func (e ErrTokenizing) Unwrap() error
Unwrap returns the error of the tokenizer.
type ErrUnterminatedAnsiCQuote ¶
type ErrUnterminatedAnsiCQuote struct {
// Pos is the position of the opening quote.
Pos Position
}
ErrUnterminatedAnsiCQuote is the error for an ANSI C quote ($'...') that the input does not close.
func (ErrUnterminatedAnsiCQuote) Error ¶
func (e ErrUnterminatedAnsiCQuote) Error() string
Error returns the message of the error.
func (ErrUnterminatedAnsiCQuote) IsIncomplete ¶
func (ErrUnterminatedAnsiCQuote) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedArithmeticCommand ¶
type ErrUnterminatedArithmeticCommand struct {
// Pos is the position of the first "(".
Pos Position
}
ErrUnterminatedArithmeticCommand is the error for a "((" whose text the input ends in, before the ")" that balances its second "(", as in "((x". bash reports the ")" that it looks for, on the line of the "((". brush has no such error.
func (ErrUnterminatedArithmeticCommand) Error ¶
func (e ErrUnterminatedArithmeticCommand) Error() string
Error returns the message of the error.
func (ErrUnterminatedArithmeticCommand) IsIncomplete ¶
func (ErrUnterminatedArithmeticCommand) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedBackquote ¶
type ErrUnterminatedBackquote struct {
// Pos is the position of the opening backquote.
Pos Position
}
ErrUnterminatedBackquote is the error for a backquote that the input does not close.
func (ErrUnterminatedBackquote) Error ¶
func (e ErrUnterminatedBackquote) Error() string
Error returns the message of the error.
func (ErrUnterminatedBackquote) IsIncomplete ¶
func (ErrUnterminatedBackquote) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedCommandSubstitution ¶
type ErrUnterminatedCommandSubstitution struct{}
ErrUnterminatedCommandSubstitution is the error for a command substitution that the input does not close. The tokenizer of brush does not return it.
func (ErrUnterminatedCommandSubstitution) Error ¶
func (ErrUnterminatedCommandSubstitution) Error() string
Error returns the message of the error.
func (ErrUnterminatedCommandSubstitution) IsIncomplete ¶
func (ErrUnterminatedCommandSubstitution) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedDoubleQuote ¶
type ErrUnterminatedDoubleQuote struct {
// Pos is the position of the opening quote.
Pos Position
}
ErrUnterminatedDoubleQuote is the error for a double quote that the input does not close.
func (ErrUnterminatedDoubleQuote) Error ¶
func (e ErrUnterminatedDoubleQuote) Error() string
Error returns the message of the error.
func (ErrUnterminatedDoubleQuote) IsIncomplete ¶
func (ErrUnterminatedDoubleQuote) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedEscapeSequence ¶
type ErrUnterminatedEscapeSequence struct{}
ErrUnterminatedEscapeSequence is the error for a backslash at the end of the input.
func (ErrUnterminatedEscapeSequence) Error ¶
func (ErrUnterminatedEscapeSequence) Error() string
Error returns the message of the error.
func (ErrUnterminatedEscapeSequence) IsIncomplete ¶
func (ErrUnterminatedEscapeSequence) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedExpansion ¶
type ErrUnterminatedExpansion struct{}
ErrUnterminatedExpansion is the error for a command substitution or an arithmetic expansion that the input does not close.
func (ErrUnterminatedExpansion) Error ¶
func (ErrUnterminatedExpansion) Error() string
Error returns the message of the error.
func (ErrUnterminatedExpansion) IsIncomplete ¶
func (ErrUnterminatedExpansion) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedExtendedGlob ¶
type ErrUnterminatedExtendedGlob struct {
// Pos is the position at the end of the input.
Pos Position
}
ErrUnterminatedExtendedGlob is the error for an extended glob pattern (extglob) that the input does not close.
func (ErrUnterminatedExtendedGlob) Error ¶
func (e ErrUnterminatedExtendedGlob) Error() string
Error returns the message of the error.
func (ErrUnterminatedExtendedGlob) IsIncomplete ¶
func (ErrUnterminatedExtendedGlob) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedFunctionSubstitution ¶
type ErrUnterminatedFunctionSubstitution struct{}
ErrUnterminatedFunctionSubstitution is the error for a ${ command; } that the input does not close. brush does not have it (W42).
func (ErrUnterminatedFunctionSubstitution) Error ¶
func (ErrUnterminatedFunctionSubstitution) Error() string
Error returns the message of the error.
func (ErrUnterminatedFunctionSubstitution) IsIncomplete ¶
func (ErrUnterminatedFunctionSubstitution) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedHereDocuments ¶
type ErrUnterminatedHereDocuments struct {
// Tags holds the tags, each in backquotes, separated by ", ".
Tags string
// Positions holds the positions of the tags, separated by ", ".
Positions string
// BodyLines holds, for each tag, the line of the new line after which
// its body starts, or 0 when no body started, separated by ", ". bash
// names that line in its warning. brush has no such field.
BodyLines string
}
ErrUnterminatedHereDocuments is the error for input that ends before the end tag of one or more here-documents.
func (ErrUnterminatedHereDocuments) Error ¶
func (e ErrUnterminatedHereDocuments) Error() string
Error returns the message of the error.
func (ErrUnterminatedHereDocuments) IsIncomplete ¶
func (ErrUnterminatedHereDocuments) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedSingleQuote ¶
type ErrUnterminatedSingleQuote struct {
// Pos is the position of the opening quote.
Pos Position
}
ErrUnterminatedSingleQuote is the error for a single quote that the input does not close.
func (ErrUnterminatedSingleQuote) Error ¶
func (e ErrUnterminatedSingleQuote) Error() string
Error returns the message of the error.
func (ErrUnterminatedSingleQuote) IsIncomplete ¶
func (ErrUnterminatedSingleQuote) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedSubscript ¶
type ErrUnterminatedSubscript struct {
// Pos is the position at the end of the input.
Pos Position
}
ErrUnterminatedSubscript is the error for the subscript of an element of an array in an assignment, as in "a[1 + 1]=x", that the input does not close. brush has no such error, because it reads no such subscript.
func (ErrUnterminatedSubscript) Error ¶
func (e ErrUnterminatedSubscript) Error() string
Error returns the message of the error.
func (ErrUnterminatedSubscript) IsIncomplete ¶
func (ErrUnterminatedSubscript) IsIncomplete() bool
IsIncomplete returns true.
type ErrUnterminatedVariable ¶
type ErrUnterminatedVariable struct {
// Pos is where the contents of the expansion start, after "${". bash
// names its line. brush does not keep it.
Pos Position
}
ErrUnterminatedVariable is the error for a parameter expansion (${...}) that the input does not close.
func (ErrUnterminatedVariable) Error ¶
func (ErrUnterminatedVariable) Error() string
Error returns the message of the error.
func (ErrUnterminatedVariable) IsIncomplete ¶
func (ErrUnterminatedVariable) IsIncomplete() bool
IsIncomplete returns true.
type ExtendedTestExpr ¶
type ExtendedTestExpr interface {
String() string
// contains filtered or unexported methods
}
ExtendedTestExpr is an expression of an extended test, [[ ]].
type ExtendedTestExprAnd ¶
type ExtendedTestExprAnd struct {
// Left is the expression on the left.
Left ExtendedTestExpr
// Right is the expression on the right.
Right ExtendedTestExpr
}
ExtendedTestExprAnd is the logical AND of two expressions.
func (*ExtendedTestExprAnd) String ¶
func (e *ExtendedTestExprAnd) String() string
String returns the two expressions with " && " between them.
type ExtendedTestExprBinaryTest ¶
type ExtendedTestExprBinaryTest struct {
// Predicate is the test.
Predicate BinaryPredicate
// Left is the operand on the left.
Left Word
// Right is the operand on the right.
Right Word
}
ExtendedTestExprBinaryTest is a test with two operands.
func (*ExtendedTestExprBinaryTest) String ¶
func (e *ExtendedTestExprBinaryTest) String() string
String returns the left operand, the predicate and the right operand.
type ExtendedTestExprCommand ¶
type ExtendedTestExprCommand struct {
// Expr is the expression of the test.
Expr ExtendedTestExpr
// Loc is the location of the command.
Loc Span
}
ExtendedTestExprCommand is an extended test command, [[ ]].
func (*ExtendedTestExprCommand) Location ¶
func (c *ExtendedTestExprCommand) Location() (Span, bool)
Location returns the location of the command.
func (*ExtendedTestExprCommand) String ¶
func (c *ExtendedTestExprCommand) String() string
String returns the expression. It does not write "[[" and "]]".
type ExtendedTestExprNot ¶
type ExtendedTestExprNot struct {
// Expr is the expression to negate.
Expr ExtendedTestExpr
}
ExtendedTestExprNot is the logical NOT of an expression.
func (*ExtendedTestExprNot) String ¶
func (e *ExtendedTestExprNot) String() string
String returns "! " and the expression.
type ExtendedTestExprOr ¶
type ExtendedTestExprOr struct {
// Left is the expression on the left.
Left ExtendedTestExpr
// Right is the expression on the right.
Right ExtendedTestExpr
}
ExtendedTestExprOr is the logical OR of two expressions.
func (*ExtendedTestExprOr) String ¶
func (e *ExtendedTestExprOr) String() string
String returns the two expressions with " || " between them.
type ExtendedTestExprParenthesized ¶
type ExtendedTestExprParenthesized struct {
// Expr is the expression in the parentheses.
Expr ExtendedTestExpr
}
ExtendedTestExprParenthesized is an expression in parentheses.
func (*ExtendedTestExprParenthesized) String ¶
func (e *ExtendedTestExprParenthesized) String() string
String returns the expression in "( " and " )".
type ExtendedTestExprUnaryTest ¶
type ExtendedTestExprUnaryTest struct {
// Predicate is the test.
Predicate UnaryPredicate
// Operand is the operand.
Operand Word
}
ExtendedTestExprUnaryTest is a test with one operand.
func (*ExtendedTestExprUnaryTest) String ¶
func (e *ExtendedTestExprUnaryTest) String() string
String returns the predicate and the operand.
type ForClauseCommand ¶
type ForClauseCommand struct {
// VariableName is the name of the variable that takes each value.
VariableName string
// Values holds the values of the loop. It is nil when the loop has no
// in, and the loop then runs over the positional parameters. A list
// that is empty but not nil is a list that is present.
Values []Word
// Body is the command that runs for each value.
Body DoGroupCommand
// Loc is the location of the loop.
Loc Span
}
ForClauseCommand is a for loop over a list of values.
func (*ForClauseCommand) Location ¶
func (c *ForClauseCommand) Location() (Span, bool)
Location returns the location of the loop.
func (*ForClauseCommand) String ¶
func (c *ForClauseCommand) String() string
String returns the loop as shell text. It writes "in" even when the loop has no values.
type FunctionBody ¶
type FunctionBody struct {
// Command is the compound command of the body.
Command CompoundCommand
// Redirects holds the redirections of the body. It is nil when the body
// has none.
Redirects *RedirectList
}
FunctionBody is the body of a function definition.
func (*FunctionBody) Location ¶
func (b *FunctionBody) Location() (Span, bool)
Location returns the span from the command to its last redirection. When the redirections have no known location, it returns the location of the command.
func (*FunctionBody) String ¶
func (fb *FunctionBody) String() string
String returns the body and its redirections as shell text.
type FunctionDefinition ¶
type FunctionDefinition struct {
// Name is the name of the function.
Name Word
// Body is the body of the function.
Body FunctionBody
}
FunctionDefinition is the definition of a shell function.
func (*FunctionDefinition) Location ¶
func (d *FunctionDefinition) Location() (Span, bool)
Location returns the span from the name to the end of the body. It does not include a function keyword before the name.
func (*FunctionDefinition) String ¶
func (d *FunctionDefinition) String() string
String returns the definition as shell text.
type HereDocCut ¶
type HereDocCut struct {
// Tag is the tag, with its quotes removed.
Tag string
// Line is the line of the here tag, and EndLine the line that ended
// the body. They count from 1 at the start of the text read.
Line, EndLine int
}
HereDocCut is a here-document in a command substitution whose body ended at a line of its tag and the ")" that closes the command substitution, such as "EOF)". bash ends the body there, and warns that it ends at the end of the file. brush has no such type.
type HereDocLeft ¶
type HereDocLeft struct {
// Count is the number of here-documents whose bodies were left.
Count int
// Line is the line where the command substitution ends. It counts
// from 1 at the start of the text read.
Line int
}
HereDocLeft is a command substitution that ended before the bodies of its here-documents, as in $(cat <<EOF). bash reads the bodies from the lines after it, and warns. brush has no such type.
type IfClauseCommand ¶
type IfClauseCommand struct {
// Condition is the command whose result is tested.
Condition CompoundList
// Then is the command that runs when the condition is true.
Then CompoundList
// Elses holds the elif and else clauses, in order. They are tested when
// the condition is false. It is nil when the command has none.
Elses []ElseClause
// Loc is the location of the command.
Loc Span
}
IfClauseCommand is an if command.
func (*IfClauseCommand) Location ¶
func (c *IfClauseCommand) Location() (Span, bool)
Location returns the location of the command.
func (*IfClauseCommand) String ¶
func (c *IfClauseCommand) String() string
String returns the command as shell text, on more than one line.
type InputStatus ¶
type InputStatus int
InputStatus is the answer of CheckInput: whether a text is a whole program, the start of one, or wrong.
const ( // InputComplete is a text that parses. The shell can run it. InputComplete InputStatus = iota // InputIncomplete is a text that stops before the end of a command, // such as "if true" or a quote that is not closed. The shell reads // more input, and shows PS2. InputIncomplete // InputInvalid is a text with a syntax error that more input cannot // correct, such as "echo ;;". The shell reports the error. InputInvalid )
The answers of CheckInput.
func CheckInput ¶
func CheckInput(input string, options ParserOptions) InputStatus
CheckInput tells whether input, the text that the shell has read so far, is complete, incomplete or invalid. It ports needs_more_input_locked.
The text is incomplete when the tokenizer stops in a token, such as in a quote or a here-document that is not closed, or when the parser stops at the end of the text in a command. The text is also incomplete when it parses but ends with a backslash and a new line. The tokenizer drops such a line continuation at the end of the text. A syntax error at a token is invalid, because more text after the token cannot correct it.
func (InputStatus) String ¶
func (s InputStatus) String() string
String returns the name of the status.
type InputUnit ¶
type InputUnit struct {
// Program holds the commands. It is nil when the text does not parse.
Program *Program
// Text is the text that the Reader read for the command, as written,
// with its new line.
Text string
// Expanded is the text that the offsets of the tree count: Text with
// each alias replaced by its text. It is Text when no alias expanded.
Expanded string
// Line is the line of the input where the command starts, from the
// line that SetLine gave. The lines of the positions in the tree count
// from 1 at that line.
Line int
// HereDocCuts holds the here-documents in command substitutions whose
// bodies ended at the ")" of the command substitution, for which bash
// warns. Their lines count as the lines of the tree do.
HereDocCuts []HereDocCut
// HereDocsLeft holds the command substitutions that ended before the
// bodies of their here-documents, as in $(cat <<EOF), for which bash
// warns. Their lines count as the lines of the tree do.
HereDocsLeft []HereDocLeft
}
InputUnit is one complete command that a Reader read, as the inputunit of the grammar of bash: the commands of one line, or of the lines that a compound command, a quote or a here-document joins.
type IoFileRedirectKind ¶
type IoFileRedirectKind int
IoFileRedirectKind is the kind of a redirection to or from a file.
const ( // IoFileRedirectKindRead reads (<). IoFileRedirectKindRead IoFileRedirectKind = iota // IoFileRedirectKindWrite writes (>). IoFileRedirectKindWrite // IoFileRedirectKindAppend appends (>>). IoFileRedirectKindAppend // IoFileRedirectKindReadAndWrite reads and writes (<>). IoFileRedirectKindReadAndWrite // IoFileRedirectKindClobber writes over a file even when noclobber is set // (>|). IoFileRedirectKindClobber // IoFileRedirectKindDuplicateInput duplicates an input (<&). IoFileRedirectKindDuplicateInput // IoFileRedirectKindDuplicateOutput duplicates an output (>&). IoFileRedirectKindDuplicateOutput )
The kinds of file redirection.
func (IoFileRedirectKind) String ¶
func (k IoFileRedirectKind) String() string
String returns the operator of the redirection, such as ">>".
type IoFileRedirectTarget ¶
type IoFileRedirectTarget interface {
String() string
// contains filtered or unexported methods
}
IoFileRedirectTarget is the target of a redirection to or from a file.
type IoFileRedirectTargetDuplicate ¶
type IoFileRedirectTargetDuplicate struct {
// Word is the word to duplicate.
Word Word
}
IoFileRedirectTargetDuplicate is the word of a duplication, as in >&2. After expansion, it can be a file name, a file descriptor, or a file descriptor and a "-" that asks to close it.
func (*IoFileRedirectTargetDuplicate) String ¶
func (t *IoFileRedirectTargetDuplicate) String() string
String returns the word.
type IoFileRedirectTargetFd ¶
type IoFileRedirectTargetFd struct {
// Fd is the file descriptor.
Fd IoFd
}
IoFileRedirectTargetFd is the number of a file descriptor.
func (*IoFileRedirectTargetFd) String ¶
func (t *IoFileRedirectTargetFd) String() string
String returns the number of the file descriptor.
type IoFileRedirectTargetFilename ¶
type IoFileRedirectTargetFilename struct {
// Word is the path.
Word Word
}
IoFileRedirectTargetFilename is the path of a file.
func (*IoFileRedirectTargetFilename) String ¶
func (t *IoFileRedirectTargetFilename) String() string
String returns the path.
type IoFileRedirectTargetProcessSubstitution ¶
type IoFileRedirectTargetProcessSubstitution struct {
// Kind is the direction of the substitution.
Kind ProcessSubstitutionKind
// Command is the command that runs in the subshell.
Command SubshellCommand
}
IoFileRedirectTargetProcessSubstitution is a process substitution. The target is the result of a command that runs in a subshell.
func (*IoFileRedirectTargetProcessSubstitution) String ¶
func (t *IoFileRedirectTargetProcessSubstitution) String() string
String returns the kind and the subshell, such as "<( ls )".
type IoHereDocument ¶
type IoHereDocument struct {
// RemoveTabs tells whether the tabs at the start of each line are
// removed (<<-).
RemoveTabs bool
// RequiresExpansion tells whether the body goes through basic expansion.
RequiresExpansion bool
// HereEnd is the delimiter that ends the here-document.
HereEnd Word
// Doc is the body of the here-document.
Doc Word
}
IoHereDocument is a here-document.
func (*IoHereDocument) Location ¶
func (*IoHereDocument) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a here-document.
func (*IoHereDocument) String ¶
func (d *IoHereDocument) String() string
String returns the here-document as shell text: the delimiter, a new line, the body, the delimiter and a new line. It writes "-" first when tabs are removed. It does not write "<<".
type IoRedirect ¶
type IoRedirect interface {
Node
// contains filtered or unexported methods
}
IoRedirect is a redirection.
type IoRedirectFile ¶
type IoRedirectFile struct {
// Fd is the file descriptor to redirect. It is nil when the redirection
// names none.
Fd *IoFd
// FdVar is the name in braces before the operator, such as the fd of
// {fd}>file, or "". The shell gives the redirection a new descriptor
// of 10 or more, and sets the variable to its number. Fd is then nil.
// brush has no such field.
FdVar string
// Kind is the kind of the redirection.
Kind IoFileRedirectKind
// Target is the target of the redirection.
Target IoFileRedirectTarget
}
IoRedirectFile is a redirection to or from a file.
func (*IoRedirectFile) Location ¶
func (*IoRedirectFile) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a redirection.
func (*IoRedirectFile) String ¶
func (r *IoRedirectFile) String() string
String returns the redirection as shell text, such as "2> file".
type IoRedirectHereDocument ¶
type IoRedirectHereDocument struct {
// Fd is the file descriptor to redirect. It is nil when the redirection
// names none.
Fd *IoFd
// FdVar is the name in braces before the operator, such as the fd of
// {fd}>file, or "". The shell gives the redirection a new descriptor
// of 10 or more, and sets the variable to its number. Fd is then nil.
// brush has no such field.
FdVar string
// Doc is the here-document.
Doc IoHereDocument
}
IoRedirectHereDocument is a redirection from a here-document.
func (*IoRedirectHereDocument) Location ¶
func (*IoRedirectHereDocument) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a redirection.
func (*IoRedirectHereDocument) String ¶
func (r *IoRedirectHereDocument) String() string
String returns "<<" and the here-document as shell text.
type IoRedirectHereString ¶
type IoRedirectHereString struct {
// Fd is the file descriptor to redirect. It is nil when the redirection
// names none.
Fd *IoFd
// FdVar is the name in braces before the operator, such as the fd of
// {fd}>file, or "". The shell gives the redirection a new descriptor
// of 10 or more, and sets the variable to its number. Fd is then nil.
// brush has no such field.
FdVar string
// Word is the here-string.
Word Word
}
IoRedirectHereString is a redirection from a here-string.
func (*IoRedirectHereString) Location ¶
func (*IoRedirectHereString) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a redirection.
func (*IoRedirectHereString) String ¶
func (r *IoRedirectHereString) String() string
String returns "<<< " and the word.
type IoRedirectOutputAndError ¶
type IoRedirectOutputAndError struct {
// Target is the file to redirect to.
Target Word
// Append tells whether the output is added to the end of the file.
Append bool
}
IoRedirectOutputAndError redirects both the standard output and the standard error (&> and &>>).
func (*IoRedirectOutputAndError) Location ¶
func (*IoRedirectOutputAndError) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a redirection.
func (*IoRedirectOutputAndError) String ¶
func (r *IoRedirectOutputAndError) String() string
String returns "&> " or "&>> " and the target.
type Locator ¶
type Locator interface {
// Location returns the span of the text that the part comes from. The
// second result is false when the span is not known.
Location() (Span, bool)
}
Locator is a part of a script that can know where it is in the text. It ports the trait SourceLocation of brush-parser.
type Node ¶
Node is a node of the abstract syntax tree. String prints the node as shell text, and Location gives its place in the script.
type OperatorToken ¶
type OperatorToken struct {
// Text is the text of the operator.
Text string
// Span is the span of the operator in the script.
Span Span
}
OperatorToken is an operator, such as "&&", "<<" or a new line.
func (OperatorToken) Location ¶
func (t OperatorToken) Location() Span
Location returns the span of the operator in the script.
func (OperatorToken) Str ¶
func (t OperatorToken) Str() string
Str returns the text of the operator.
type Parameter ¶
type Parameter interface {
String() string
// contains filtered or unexported methods
}
Parameter is a parameter of a parameter expansion. Each kind of parameter is a type of its own, whose name starts with Parameter. String returns the parameter as an expansion, such as $1 or ${x[2]}.
func ParseParameter ¶
func ParseParameter(word string, options ParserOptions) (Parameter, error)
ParseParameter parses word as a parameter, such as x, x[1] or @. The error is an ErrParseParameter.
type ParameterExpr ¶
type ParameterExpr interface {
// contains filtered or unexported methods
}
ParameterExpr is the expression of a parameter expansion. Each kind of expression is a type of its own, whose name starts with ParameterExpr.
In each type, Indirect tells whether the value of the parameter is the name of the parameter to expand, as in ${!x}.
type ParameterExprAssignDefaultValues ¶
type ParameterExprAssignDefaultValues struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// TestType is the test.
TestType ParameterTestType
// DefaultValue is the default value, or nil.
DefaultValue *string
}
ParameterExprAssignDefaultValues assigns a default value when the test is true, as in ${x:=y}.
type ParameterExprIndicateErrorIfNullOrUnset ¶
type ParameterExprIndicateErrorIfNullOrUnset struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// TestType is the test.
TestType ParameterTestType
// ErrorMessage is the message of the error, or nil.
ErrorMessage *string
}
ParameterExprIndicateErrorIfNullOrUnset gives an error when the test is true, as in ${x:?message}.
type ParameterExprLowercaseFirstChar ¶
type ParameterExprLowercaseFirstChar struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern that the character must match, or nil.
Pattern *string
}
ParameterExprLowercaseFirstChar changes the first character of the value to lowercase, as in ${x,}.
type ParameterExprLowercasePattern ¶
type ParameterExprLowercasePattern struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern, or nil.
Pattern *string
}
ParameterExprLowercasePattern changes the characters of the value that the pattern matches to lowercase, as in ${x,,}.
type ParameterExprMemberKeys ¶
type ParameterExprMemberKeys struct {
// VariableName is the name of the array.
VariableName string
// Concatenate tells whether the keys are joined into one word, as with
// "*".
Concatenate bool
}
ParameterExprMemberKeys is the keys of an array, as in ${!x[@]} or ${!x[*]}.
type ParameterExprParameter ¶
type ParameterExprParameter struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
}
ParameterExprParameter is the value of a parameter, as in ${x} or ${!x}.
type ParameterExprParameterLength ¶
type ParameterExprParameterLength struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
}
ParameterExprParameterLength is the length of the value of the parameter, as in ${#x}.
type ParameterExprRemoveLargestPrefixPattern ¶
type ParameterExprRemoveLargestPrefixPattern struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern, or nil.
Pattern *string
}
ParameterExprRemoveLargestPrefixPattern removes the longest prefix that the pattern matches, as in ${x##y}.
type ParameterExprRemoveLargestSuffixPattern ¶
type ParameterExprRemoveLargestSuffixPattern struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern, or nil.
Pattern *string
}
ParameterExprRemoveLargestSuffixPattern removes the longest suffix that the pattern matches, as in ${x%%y}.
type ParameterExprRemoveSmallestPrefixPattern ¶
type ParameterExprRemoveSmallestPrefixPattern struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern, or nil.
Pattern *string
}
ParameterExprRemoveSmallestPrefixPattern removes the shortest prefix that the pattern matches, as in ${x#y}.
type ParameterExprRemoveSmallestSuffixPattern ¶
type ParameterExprRemoveSmallestSuffixPattern struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern, or nil.
Pattern *string
}
ParameterExprRemoveSmallestSuffixPattern removes the shortest suffix that the pattern matches, as in ${x%y}.
type ParameterExprReplaceSubstring ¶
type ParameterExprReplaceSubstring struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern.
Pattern string
// Replacement is the text that replaces the match, or nil.
Replacement *string
// MatchKind tells which matches are replaced.
MatchKind SubstringMatchKind
}
ParameterExprReplaceSubstring replaces the text that the pattern matches, as in ${x/y/z}.
type ParameterExprSubstring ¶
type ParameterExprSubstring struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Offset is the arithmetic expression that gives the offset of the
// part. It is not expanded.
Offset UnexpandedArithmeticExpr
// Length is the arithmetic expression that gives the length of the
// part. It is not expanded. It is nil when the part runs to the end of
// the value.
Length *UnexpandedArithmeticExpr
}
ParameterExprSubstring is a part of the value of the parameter, as in ${x:1:2}.
type ParameterExprToggleCaseFirstChar ¶
type ParameterExprToggleCaseFirstChar struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern that the character must match, or nil.
Pattern *string
}
ParameterExprToggleCaseFirstChar changes the case of the first character of the value, as in ${x~}. bash has this form, and does not document it. brush-parser does not read it, and the port departs from it here (W29).
type ParameterExprToggleCasePattern ¶
type ParameterExprToggleCasePattern struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern, or nil.
Pattern *string
}
ParameterExprToggleCasePattern changes the case of each character of the value that the pattern matches, as in ${x~~}. bash has this form, and does not document it. brush-parser does not read it, and the port departs from it here (W29).
type ParameterExprTransform ¶
type ParameterExprTransform struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Op is the transformation.
Op ParameterTransformOp
}
ParameterExprTransform transforms the value of the parameter, as in ${x@U}.
type ParameterExprUppercaseFirstChar ¶
type ParameterExprUppercaseFirstChar struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern that the character must match, or nil.
Pattern *string
}
ParameterExprUppercaseFirstChar changes the first character of the value to uppercase, as in ${x^}.
type ParameterExprUppercasePattern ¶
type ParameterExprUppercasePattern struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// Pattern is the pattern, or nil.
Pattern *string
}
ParameterExprUppercasePattern changes the characters of the value that the pattern matches to uppercase, as in ${x^^}.
type ParameterExprUseAlternativeValue ¶
type ParameterExprUseAlternativeValue struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// TestType is the test.
TestType ParameterTestType
// AlternativeValue is the other value, or nil.
AlternativeValue *string
}
ParameterExprUseAlternativeValue uses another value when the test is false, as in ${x:+y}.
type ParameterExprUseDefaultValues ¶
type ParameterExprUseDefaultValues struct {
// Parameter is the parameter.
Parameter Parameter
// Indirect tells whether the expansion is indirect.
Indirect bool
// TestType is the test.
TestType ParameterTestType
// DefaultValue is the default value, or nil.
DefaultValue *string
}
ParameterExprUseDefaultValues uses a default value when the test is true, as in ${x:-y}.
type ParameterExprVariableNames ¶
type ParameterExprVariableNames struct {
// Prefix is the prefix.
Prefix string
// Concatenate tells whether the names are joined into one word, as with
// "*".
Concatenate bool
}
ParameterExprVariableNames is the names of the variables that start with a prefix, as in ${!x*} or ${!x@}.
type ParameterNamed ¶
type ParameterNamed struct {
// Name is the name of the variable.
Name string
}
ParameterNamed is a variable, such as $x.
func (*ParameterNamed) String ¶
func (p *ParameterNamed) String() string
String returns the parameter as ${name}.
type ParameterNamedWithAllIndices ¶
type ParameterNamedWithAllIndices struct {
// Name is the name of the array.
Name string
// Concatenate tells whether the values are joined into one word, as
// with "*".
Concatenate bool
}
ParameterNamedWithAllIndices is every element of an array, as in ${x[@]} or ${x[*]}.
func (*ParameterNamedWithAllIndices) String ¶
func (p *ParameterNamedWithAllIndices) String() string
String returns the parameter as ${name[*]} or ${name[@]}.
type ParameterNamedWithIndex ¶
type ParameterNamedWithIndex struct {
// Name is the name of the array.
Name string
// Index is the text of the index.
Index string
}
ParameterNamedWithIndex is an element of an array, such as ${x[2]}.
func (*ParameterNamedWithIndex) String ¶
func (p *ParameterNamedWithIndex) String() string
String returns the parameter as ${name[index]}.
type ParameterPositional ¶
type ParameterPositional struct {
// N is the number of the parameter.
N uint32
}
ParameterPositional is a positional parameter, such as $1.
func (*ParameterPositional) String ¶
func (p *ParameterPositional) String() string
String returns the parameter as $N.
type ParameterSpecial ¶
type ParameterSpecial struct {
// Param is the special parameter.
Param SpecialParameter
}
ParameterSpecial is a special parameter, such as $? or $#.
func (*ParameterSpecial) String ¶
func (p *ParameterSpecial) String() string
String returns the parameter as $ and its character.
type ParameterTestType ¶
type ParameterTestType int
ParameterTestType is the test of a parameter expansion such as ${x:-y}.
const ( // ParameterTestTypeUnsetOrNull tests that the parameter is unset or // empty, as in ${x:-y}. ParameterTestTypeUnsetOrNull ParameterTestType = iota // ParameterTestTypeUnset tests that the parameter is unset, as in // ${x-y}. ParameterTestTypeUnset )
The kinds of test.
func (ParameterTestType) String ¶
func (t ParameterTestType) String() string
String returns the name of the test in brush.
type ParameterTransformOp ¶
type ParameterTransformOp interface {
// contains filtered or unexported methods
}
ParameterTransformOp is the transformation of ${x@op}. Each kind is a type of its own, whose name starts with ParameterTransformOp.
type ParameterTransformOpCapitalizeInitial ¶
type ParameterTransformOpCapitalizeInitial struct{}
ParameterTransformOpCapitalizeInitial changes the first character to uppercase, ${x@u}.
type ParameterTransformOpExpandEscapeSequences ¶
type ParameterTransformOpExpandEscapeSequences struct{}
ParameterTransformOpExpandEscapeSequences expands the escapes as $'...' does, ${x@E}.
type ParameterTransformOpPossiblyQuoteWithArraysExpanded ¶
type ParameterTransformOpPossiblyQuoteWithArraysExpanded struct {
// SeparateWords tells whether each key and each value is a word of its
// own, as with "k".
SeparateWords bool
}
ParameterTransformOpPossiblyQuoteWithArraysExpanded quotes the value, and gives the keys and the values of an array, ${x@K} or ${x@k}.
type ParameterTransformOpPromptExpand ¶
type ParameterTransformOpPromptExpand struct{}
ParameterTransformOpPromptExpand expands the value as a prompt, ${x@P}.
type ParameterTransformOpQuoted ¶
type ParameterTransformOpQuoted struct{}
ParameterTransformOpQuoted quotes the value, ${x@Q}.
type ParameterTransformOpToAssignmentLogic ¶
type ParameterTransformOpToAssignmentLogic struct{}
ParameterTransformOpToAssignmentLogic gives an assignment or a declare command that sets the parameter, ${x@A}.
type ParameterTransformOpToAttributeFlags ¶
type ParameterTransformOpToAttributeFlags struct{}
ParameterTransformOpToAttributeFlags gives the flags of the attributes of the parameter, ${x@a}.
type ParameterTransformOpToLowerCase ¶
type ParameterTransformOpToLowerCase struct{}
ParameterTransformOpToLowerCase changes the value to lowercase, ${x@L}.
type ParameterTransformOpToUpperCase ¶
type ParameterTransformOpToUpperCase struct{}
ParameterTransformOpToUpperCase changes the value to uppercase, ${x@U}.
type ParseError ¶
type ParseError interface {
error
// contains filtered or unexported methods
}
ParseError is an error of the parser of programs. Each kind of error is a type of its own: ErrParsingNear, ErrParsingAtEndOfInput and ErrTokenizing.
type ParseErrorLocation ¶
type ParseErrorLocation struct {
// Position is the farthest position where a rule of the grammar failed.
// Offset counts bytes. Line and Column start from 1, and Column counts
// characters.
Position Position
// Expected holds the text of each thing that the grammar expected at the
// position, sorted, with no duplicates. Each item is written as the
// grammar of brush writes it, such as "\"}\"" for a literal or "EOF" for
// the end of the input.
Expected []string
}
ParseErrorLocation is where a parser of the PEG grammars failed, and what it expected to find there. It ports the type of brush-parser that wraps the error of the crate peg, ParseError<LineCol>.
func (ParseErrorLocation) Error ¶
func (e ParseErrorLocation) Error() string
Error returns the text that the crate peg prints for the error, such as "error at 1:4: expected one of \"(\", EOF".
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses a shell program that it reads from a reader.
func NewParser ¶
func NewParser(r io.Reader, options ParserOptions) *Parser
NewParser returns a parser that reads the program from r, with the options.
func (*Parser) ParseFunctionParensAndBody ¶
func (p *Parser) ParseFunctionParensAndBody() (*FunctionBody, error)
ParseFunctionParensAndBody reads the whole input, and parses it as the body of a function definition after the name, such as "() { echo hi; }". The input starts with "()". The error is a ParseError.
func (*Parser) ParseProgram ¶
ParseProgram reads the whole input, and parses it into the tree of a shell program. The error is a ParseError.
type ParserOptions ¶
type ParserOptions struct {
// EnableExtendedGlobbing enables the extended glob patterns (extglob).
EnableExtendedGlobbing bool
// PosixMode enables the POSIX mode.
PosixMode bool
// ShMode enables the emulation of sh. It turns off the syntax that sh
// does not have, such as ${!name} and ${name[@]}.
ShMode bool
// TildeExpansionAtWordStart expands a tilde at the start of a word.
TildeExpansionAtWordStart bool
// TildeExpansionAfterColon expands a tilde that comes after a colon.
TildeExpansionAfterColon bool
// Big5 reads the characters of Big5, as bash does in a Big5 locale,
// and not of UTF-8. brush has no such option.
Big5 bool
// Aliases returns the text of the alias name, and whether name is an
// alias. When it is not nil, the parser of a program expands aliases
// while it reads, as bash does with shopt expand_aliases on. brush has
// no such option. It expands an alias when it runs a simple command.
// The parsers of words, of parts of words and of tokens ignore it.
Aliases func(name string) (string, bool)
// NoDollarQuotes reads $'...' and $"..." as a "$" and a quoted string,
// as bash reads the words in the body of a here-document and in a
// prompt, which it parses only when it expands them. brush has no such
// option.
NoDollarQuotes bool
}
ParserOptions holds the options of the parser. The parser of words uses them too.
func DefaultParserOptions ¶
func DefaultParserOptions() ParserOptions
DefaultParserOptions returns the options that brush uses when the caller gives none: extended glob patterns on, the POSIX mode and the sh mode off, and the expansion of a tilde at the start of a word only.
func (ParserOptions) TokenizerOptions ¶
func (o ParserOptions) TokenizerOptions() TokenizerOptions
TokenizerOptions returns the options of the tokenizer that the parser options give.
type Pipeline ¶
type Pipeline struct {
// Timed asks for the time of the pipeline to be reported. It is nil when
// the pipeline is not timed.
Timed PipelineTimed
// Bang tells whether the result of the pipeline is negated.
Bang bool
// Seq is the sequence of commands in the pipeline.
Seq []Command
}
Pipeline is a sequence of commands. The output of each command goes to the standard input of the command after it.
type PipelineOperator ¶
type PipelineOperator int
PipelineOperator is a boolean operator that connects pipelines in an AndOrList.
const ( // PipelineOperatorAnd is the boolean AND operator. PipelineOperatorAnd PipelineOperator = iota // PipelineOperatorOr is the boolean OR operator. PipelineOperatorOr )
The pipeline operators.
func (PipelineOperator) Matches ¶
func (o PipelineOperator) Matches(a AndOr) bool
Matches reports whether a uses the operator o.
type PipelineTimed ¶
type PipelineTimed interface {
Node
// IsPosixOutput reports whether the timing uses the output of POSIX.
IsPosixOutput() bool
// contains filtered or unexported methods
}
PipelineTimed is the kind of timing that a pipeline asks for.
type PipelineTimedTimed ¶
type PipelineTimedTimed struct {
// Loc is the location of the time keyword.
Loc Span
}
PipelineTimedTimed times the pipeline with the output of bash.
func (*PipelineTimedTimed) IsPosixOutput ¶
func (*PipelineTimedTimed) IsPosixOutput() bool
IsPosixOutput returns false.
func (*PipelineTimedTimed) Location ¶
func (t *PipelineTimedTimed) Location() (Span, bool)
Location returns the location of the keyword.
func (*PipelineTimedTimed) String ¶
func (t *PipelineTimedTimed) String() string
String returns "time".
type PipelineTimedTimedWithPosixOutput ¶
type PipelineTimedTimedWithPosixOutput struct {
// Loc is the location of the time keyword and its option.
Loc Span
}
PipelineTimedTimedWithPosixOutput times the pipeline with the output of POSIX.
func (*PipelineTimedTimedWithPosixOutput) IsPosixOutput ¶
func (*PipelineTimedTimedWithPosixOutput) IsPosixOutput() bool
IsPosixOutput returns true.
func (*PipelineTimedTimedWithPosixOutput) Location ¶
func (t *PipelineTimedTimedWithPosixOutput) Location() (Span, bool)
Location returns the location of the keyword and its option.
func (*PipelineTimedTimedWithPosixOutput) String ¶
func (t *PipelineTimedTimedWithPosixOutput) String() string
String returns "time -p".
type Position ¶
type Position struct {
// Offset is the offset in bytes from the start of the text, from 0.
Offset int
// Line is the line, from 1.
Line int
// Column is the column, from 1. It counts characters, not bytes.
Column int
}
Position is a position in the text of a script.
func (Position) Add ¶
func (p Position) Add(off PositionOffset) Position
Add returns the position moved by off.
type PositionOffset ¶
type PositionOffset struct {
// Offset is the distance in bytes.
Offset int
// Line is the distance in lines.
Line int
// Column is the distance in columns.
Column int
}
PositionOffset is the distance between two positions.
type ProcessSubstitutionKind ¶
type ProcessSubstitutionKind int
ProcessSubstitutionKind is the direction of a process substitution.
const ( // ProcessSubstitutionKindRead reads from the process (<). ProcessSubstitutionKindRead ProcessSubstitutionKind = iota // ProcessSubstitutionKindWrite writes to the process (>). ProcessSubstitutionKindWrite )
The kinds of process substitution.
func (ProcessSubstitutionKind) String ¶
func (k ProcessSubstitutionKind) String() string
String returns "<" or ">".
type Program ¶
type Program struct {
// CompleteCommands is the sequence of complete commands.
CompleteCommands []CompleteCommand
}
Program is a complete shell program.
func ParseTokens ¶
func ParseTokens(tokens []Token, options ParserOptions) (*Program, error)
ParseTokens parses a sequence of tokens into the tree of a shell program. The error is a ParseError.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads a program one complete command at a time, as bash does. It reads its input one byte at a time, and never past the new line that ends a command, so that a command that reads the same input, such as read, finds the next line. The input is not read before ReadCommand asks for it.
func NewReader ¶
NewReader returns a Reader that reads the program from r. The first line of r is line 1.
func (*Reader) ReadAll ¶
func (r *Reader) ReadAll(options ParserOptions) (*InputUnit, error)
ReadAll reads the rest of the input as one program, with the options, and parses it, as the text of a command substitution is read. It returns io.EOF when no text is left.
func (*Reader) ReadCommand ¶
func (r *Reader) ReadCommand(options ParserOptions) (*InputUnit, error)
ReadCommand reads the next complete command, with the options, and parses it. The options can change from one command to the next, as shopt extglob and the aliases do. It returns io.EOF at the end of the input.
The command ends at the first new line where the text read so far parses. A text that cannot parse whatever comes after it is a syntax error, which ReadCommand returns with the unit. An InputUnit is returned with every other error too. The error is a ParseError, and the Reader reads no more after it.
type RedirectList ¶
type RedirectList struct {
// Items holds the redirections, in order.
Items []IoRedirect
}
RedirectList is a list of redirections for a command.
func (*RedirectList) Location ¶
func (l *RedirectList) Location() (Span, bool)
Location returns the span from the first redirection to the last.
func (*RedirectList) String ¶
func (l *RedirectList) String() string
String returns the redirections, with nothing between them.
type SeparatorOperator ¶
type SeparatorOperator int
SeparatorOperator tells whether the command before it runs synchronously or asynchronously.
const ( // SeparatorOperatorAsync runs the command before it asynchronously (&). SeparatorOperatorAsync SeparatorOperator = iota // SeparatorOperatorSequence runs the command before it synchronously (;). SeparatorOperatorSequence )
The separator operators.
func (SeparatorOperator) String ¶
func (o SeparatorOperator) String() string
String returns "&" or ";".
type SimpleCommand ¶
type SimpleCommand struct {
// Prefix holds the assignments and redirections before the name. It is
// nil when the command has none.
Prefix *CommandPrefix
// WordOrName is the name of the command to run. It is nil when the
// command has no name.
WordOrName *Word
// Suffix holds the arguments and redirections after the name. It is nil
// when the command has none.
Suffix *CommandSuffix
}
SimpleCommand is a simple command.
func (*SimpleCommand) Location ¶
func (c *SimpleCommand) Location() (Span, bool)
Location returns the span from the first part of the command to the last.
func (*SimpleCommand) String ¶
func (c *SimpleCommand) String() string
String returns the command as shell text.
type Span ¶
Span is a stretch of the text of a script. End is the position after the last character.
type SpecialParameter ¶
type SpecialParameter interface {
String() string
// contains filtered or unexported methods
}
SpecialParameter is a special parameter. Each kind is a type of its own, whose name starts with SpecialParameter. String returns the character of the parameter, such as "?".
type SpecialParameterAllPositionalParameters ¶
type SpecialParameterAllPositionalParameters struct {
// Concatenate tells whether the values are joined into one word, as
// with "*".
Concatenate bool
}
SpecialParameterAllPositionalParameters is every positional parameter, as in $@ or $*.
func (*SpecialParameterAllPositionalParameters) String ¶
func (p *SpecialParameterAllPositionalParameters) String() string
String returns "*" or "@".
type SpecialParameterCurrentOptionFlags ¶
type SpecialParameterCurrentOptionFlags struct{}
SpecialParameterCurrentOptionFlags is the flags of the shell options that are set, $-.
func (*SpecialParameterCurrentOptionFlags) String ¶
func (*SpecialParameterCurrentOptionFlags) String() string
String returns "-".
type SpecialParameterLastBackgroundProcessID ¶
type SpecialParameterLastBackgroundProcessID struct{}
SpecialParameterLastBackgroundProcessID is the process ID of the last command that the shell started in the background, $!.
func (*SpecialParameterLastBackgroundProcessID) String ¶
func (*SpecialParameterLastBackgroundProcessID) String() string
String returns "!".
type SpecialParameterLastExitStatus ¶
type SpecialParameterLastExitStatus struct{}
SpecialParameterLastExitStatus is the exit status of the last command, $?.
func (*SpecialParameterLastExitStatus) String ¶
func (*SpecialParameterLastExitStatus) String() string
String returns "?".
type SpecialParameterPositionalParameterCount ¶
type SpecialParameterPositionalParameterCount struct{}
SpecialParameterPositionalParameterCount is the count of positional parameters, $#.
func (*SpecialParameterPositionalParameterCount) String ¶
func (*SpecialParameterPositionalParameterCount) String() string
String returns "#".
type SpecialParameterProcessID ¶
type SpecialParameterProcessID struct{}
SpecialParameterProcessID is the process ID of the shell, $$.
func (*SpecialParameterProcessID) String ¶
func (*SpecialParameterProcessID) String() string
String returns "$".
type SpecialParameterShellName ¶
type SpecialParameterShellName struct{}
SpecialParameterShellName is the name of the shell, $0.
func (*SpecialParameterShellName) String ¶
func (*SpecialParameterShellName) String() string
String returns "0".
type SubshellCommand ¶
type SubshellCommand struct {
// List is the list of commands.
List CompoundList
// Loc is the location of the subshell.
Loc Span
}
SubshellCommand is a list of commands that runs in a subshell.
func (*SubshellCommand) Location ¶
func (c *SubshellCommand) Location() (Span, bool)
Location returns the location of the subshell.
func (*SubshellCommand) String ¶
func (c *SubshellCommand) String() string
String returns the list in "( " and " )".
type SubstringMatchKind ¶
type SubstringMatchKind int
SubstringMatchKind tells which matches of a pattern a replacement replaces.
const ( // SubstringMatchKindPrefix matches at the start of the value, as in // ${x/#y/z}. SubstringMatchKindPrefix SubstringMatchKind = iota // SubstringMatchKindSuffix matches at the end of the value, as in // ${x/%y/z}. SubstringMatchKindSuffix // SubstringMatchKindFirstOccurrence matches the first match in the // value, as in ${x/y/z}. SubstringMatchKindFirstOccurrence // SubstringMatchKindAnywhere matches every match in the value, as in // ${x//y/z}. SubstringMatchKindAnywhere )
The kinds of match.
func (SubstringMatchKind) String ¶
func (k SubstringMatchKind) String() string
String returns the name of the kind in brush.
type TestCommandParseError ¶
type TestCommandParseError struct {
// Index is the index of the farthest argument where a rule of the
// grammar failed. It is the number of arguments when the parser failed
// after the last one.
Index int
// Expected holds the text of each thing that the grammar expected at the
// index, sorted, with no duplicates, such as "[\"-a\"]" or "EOF".
Expected []string
}
TestCommandParseError is an error of the parser of the arguments of the command test, which is not the extended test of [[ ]]. It ports the type of brush-parser that wraps the error of the crate peg, ParseError<usize>.
func (TestCommandParseError) Error ¶
func (e TestCommandParseError) Error() string
Error returns the text that the crate peg prints for the error, such as "error at 2: expected [\")\"]".
type TestExpr ¶
type TestExpr interface {
Node
// contains filtered or unexported methods
}
TestExpr is an expression of the test command. It is not an extended test.
func ParseTestCommand ¶
ParseTestCommand parses the arguments of the command test, or of [ with no closing ], into an expression. The error is a TestCommandParseError.
type TestExprAnd ¶
type TestExprAnd struct {
// Left is the expression on the left.
Left TestExpr
// Right is the expression on the right.
Right TestExpr
}
TestExprAnd is the logical AND of two expressions.
func (*TestExprAnd) Location ¶
func (*TestExprAnd) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a test expression.
func (*TestExprAnd) String ¶
func (e *TestExprAnd) String() string
String returns the two expressions with " -a " between them.
type TestExprBinaryTest ¶
type TestExprBinaryTest struct {
// Predicate is the test.
Predicate BinaryPredicate
// Left is the operand on the left.
Left string
// Right is the operand on the right.
Right string
}
TestExprBinaryTest is a test with two operands.
func (*TestExprBinaryTest) Location ¶
func (*TestExprBinaryTest) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a test expression.
func (*TestExprBinaryTest) String ¶
func (e *TestExprBinaryTest) String() string
String returns the predicate, the left operand and the right operand, in that order, as brush-parser does. The predicate comes first and not between the operands.
type TestExprFalse ¶
type TestExprFalse struct{}
TestExprFalse is always false.
func (*TestExprFalse) Location ¶
func (*TestExprFalse) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a test expression.
func (*TestExprFalse) String ¶
func (*TestExprFalse) String() string
String returns an empty string.
type TestExprLiteral ¶
type TestExprLiteral struct {
// Value is the string.
Value string
}
TestExprLiteral is a literal string.
func (*TestExprLiteral) Location ¶
func (*TestExprLiteral) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a test expression.
func (*TestExprLiteral) String ¶
func (e *TestExprLiteral) String() string
String returns the string.
type TestExprNot ¶
type TestExprNot struct {
// Expr is the expression to negate.
Expr TestExpr
}
TestExprNot is the logical NOT of an expression.
func (*TestExprNot) Location ¶
func (*TestExprNot) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a test expression.
func (*TestExprNot) String ¶
func (e *TestExprNot) String() string
String returns "! " and the expression.
type TestExprOr ¶
type TestExprOr struct {
// Left is the expression on the left.
Left TestExpr
// Right is the expression on the right.
Right TestExpr
}
TestExprOr is the logical OR of two expressions.
func (*TestExprOr) Location ¶
func (*TestExprOr) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a test expression.
func (*TestExprOr) String ¶
func (e *TestExprOr) String() string
String returns the two expressions with " -o " between them.
type TestExprParenthesized ¶
type TestExprParenthesized struct {
// Expr is the expression in the parentheses.
Expr TestExpr
}
TestExprParenthesized is an expression in parentheses.
func (*TestExprParenthesized) Location ¶
func (*TestExprParenthesized) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a test expression.
func (*TestExprParenthesized) String ¶
func (e *TestExprParenthesized) String() string
String returns the expression in "( " and " )".
type TestExprUnaryTest ¶
type TestExprUnaryTest struct {
// Predicate is the test.
Predicate UnaryPredicate
// Operand is the operand.
Operand string
}
TestExprUnaryTest is a test with one operand.
func (*TestExprUnaryTest) Location ¶
func (*TestExprUnaryTest) Location() (Span, bool)
Location returns false, because brush-parser does not track the location of a test expression.
func (*TestExprUnaryTest) String ¶
func (e *TestExprUnaryTest) String() string
String returns the predicate and the operand.
type TildeExpr ¶
type TildeExpr interface {
// contains filtered or unexported methods
}
TildeExpr is a tilde expression, such as ~ or ~user. Each kind of expression is a type of its own, whose name starts with TildeExpr.
type TildeExprHome ¶
type TildeExprHome struct{}
TildeExprHome is ~, the home directory of the user.
type TildeExprNthDirFromBottomOfDirStack ¶
type TildeExprNthDirFromBottomOfDirStack struct {
// N is the index in the directory stack. 0 is the bottom of the stack.
N int
}
TildeExprNthDirFromBottomOfDirStack is ~-N, the directory N of the directory stack, counted from the bottom.
type TildeExprNthDirFromTopOfDirStack ¶
type TildeExprNthDirFromTopOfDirStack struct {
// N is the index in the directory stack. 0 is the top of the stack.
N int
// PlusUsed tells whether the expression has the "+".
PlusUsed bool
}
TildeExprNthDirFromTopOfDirStack is ~+N or ~N, the directory N of the directory stack, counted from the top. The top of the stack holds the working directory.
type TildeExprOldWorkingDir ¶
type TildeExprOldWorkingDir struct{}
TildeExprOldWorkingDir is ~-, the previous working directory.
type TildeExprUserHome ¶
type TildeExprUserHome struct {
// User is the name of the user.
User string
}
TildeExprUserHome is ~user, the home directory of the user named User.
type TildeExprWorkingDir ¶
type TildeExprWorkingDir struct{}
TildeExprWorkingDir is ~+, the working directory.
type Token ¶
type Token interface {
// Str returns the text of the token.
Str() string
// Location returns the span of the token in the script.
Location() Span
// contains filtered or unexported methods
}
Token is a token of a shell script: an OperatorToken or a WordToken.
func TokenizeStr ¶
TokenizeStr breaks the shell script input into tokens, with the default options. The error is a TokenizerError.
func TokenizeStrWithOptions ¶
func TokenizeStrWithOptions(input string, options TokenizerOptions) ([]Token, error)
TokenizeStrWithOptions breaks the shell script input into tokens, with the options. The error is a TokenizerError.
brush keeps the last 64 results of this function in a cache. The port does not, so this function and UncachedTokenizeStr do the same thing.
func UncachedTokenizeStr ¶
func UncachedTokenizeStr(input string, options TokenizerOptions) ([]Token, error)
UncachedTokenizeStr breaks the shell script input into tokens, with the options, and keeps no cache. The error is a TokenizerError.
type TokenizerError ¶
type TokenizerError interface {
error
// IsIncomplete returns true if more input can possibly correct the
// error.
IsIncomplete() bool
// contains filtered or unexported methods
}
TokenizerError is an error that the tokenizer found. Each kind of error is a type of its own. The message of each one is the message of brush, because the shell prints it.
type TokenizerOptions ¶
type TokenizerOptions struct {
// EnableExtendedGlobbing enables the extended glob patterns (extglob).
EnableExtendedGlobbing bool
// PosixMode enables the POSIX mode.
PosixMode bool
// ShMode enables the emulation of sh.
ShMode bool
// Big5 reads the characters of Big5, as bash does in a Big5 locale,
// and not of UTF-8. The trail byte of a character of Big5 is never
// special. brush has no such option.
Big5 bool
}
TokenizerOptions holds the options of the tokenizer.
func DefaultTokenizerOptions ¶
func DefaultTokenizerOptions() TokenizerOptions
DefaultTokenizerOptions returns the options that brush uses when the caller gives none: extended glob patterns on, and the POSIX mode and the sh mode off.
type UnaryAssignmentOperator ¶
type UnaryAssignmentOperator int
UnaryAssignmentOperator is an arithmetic operator that increments or decrements a variable.
const ( // UnaryAssignmentOperatorPrefixIncrement increments before the value is // used (++x). UnaryAssignmentOperatorPrefixIncrement UnaryAssignmentOperator = iota // UnaryAssignmentOperatorPrefixDecrement decrements before the value is // used (--x). UnaryAssignmentOperatorPrefixDecrement // UnaryAssignmentOperatorPostfixIncrement increments after the value is // used (x++). UnaryAssignmentOperatorPostfixIncrement // UnaryAssignmentOperatorPostfixDecrement decrements after the value is // used (x--). UnaryAssignmentOperatorPostfixDecrement )
The increment and decrement operators.
func (UnaryAssignmentOperator) String ¶
func (o UnaryAssignmentOperator) String() string
String returns "++" or "--".
type UnaryOperator ¶
type UnaryOperator int
UnaryOperator is an arithmetic operator with one operand.
const ( // UnaryOperatorUnaryPlus is the unary plus (+x). UnaryOperatorUnaryPlus UnaryOperator = iota // UnaryOperatorUnaryMinus is the unary minus (-x). UnaryOperatorUnaryMinus // UnaryOperatorBitwiseNot is the bitwise NOT (~x). UnaryOperatorBitwiseNot // UnaryOperatorLogicalNot is the logical NOT (!x). UnaryOperatorLogicalNot )
The arithmetic operators with one operand.
func (UnaryOperator) String ¶
func (o UnaryOperator) String() string
String returns the operator, such as "~".
type UnaryPredicate ¶
type UnaryPredicate int
UnaryPredicate is a test with one operand, in a test or an extended test.
const ( // UnaryPredicateFileExists tests that the operand is the path of a file // that exists (-e). UnaryPredicateFileExists UnaryPredicate = iota // UnaryPredicateFileExistsAndIsBlockSpecialFile tests that the operand is // the path of a block device (-b). UnaryPredicateFileExistsAndIsBlockSpecialFile // UnaryPredicateFileExistsAndIsCharSpecialFile tests that the operand is // the path of a character device (-c). UnaryPredicateFileExistsAndIsCharSpecialFile // UnaryPredicateFileExistsAndIsDir tests that the operand is the path of // a directory (-d). UnaryPredicateFileExistsAndIsDir // UnaryPredicateFileExistsAndIsRegularFile tests that the operand is the // path of a regular file (-f). UnaryPredicateFileExistsAndIsRegularFile // UnaryPredicateFileExistsAndIsSetgid tests that the operand is the path // of a file with the setgid bit set (-g). UnaryPredicateFileExistsAndIsSetgid // UnaryPredicateFileExistsAndIsSymlink tests that the operand is the path // of a symbolic link (-h). UnaryPredicateFileExistsAndIsSymlink // UnaryPredicateFileExistsAndHasStickyBit tests that the operand is the // path of a file with the sticky bit set (-k). UnaryPredicateFileExistsAndHasStickyBit // UnaryPredicateFileExistsAndIsFifo tests that the operand is the path of // a FIFO (-p). UnaryPredicateFileExistsAndIsFifo // UnaryPredicateFileExistsAndIsReadable tests that the operand is the // path of a file that can be read (-r). UnaryPredicateFileExistsAndIsReadable // UnaryPredicateFileExistsAndIsNotZeroLength tests that the operand is // the path of a file that is not empty (-s). UnaryPredicateFileExistsAndIsNotZeroLength // UnaryPredicateFdIsOpenTerminal tests that the operand is a file // descriptor that is open on a terminal (-t). UnaryPredicateFdIsOpenTerminal // UnaryPredicateFileExistsAndIsSetuid tests that the operand is the path // of a file with the setuid bit set (-u). UnaryPredicateFileExistsAndIsSetuid // UnaryPredicateFileExistsAndIsWritable tests that the operand is the // path of a file that can be written (-w). UnaryPredicateFileExistsAndIsWritable // UnaryPredicateFileExistsAndIsExecutable tests that the operand is the // path of a file that can be run (-x). UnaryPredicateFileExistsAndIsExecutable // UnaryPredicateFileExistsAndOwnedByEffectiveGroupID tests that the // operand is the path of a file that the effective group ID owns (-G). UnaryPredicateFileExistsAndOwnedByEffectiveGroupID // UnaryPredicateFileExistsAndModifiedSinceLastRead tests that the operand // is the path of a file that changed after it was last read (-N). UnaryPredicateFileExistsAndModifiedSinceLastRead // UnaryPredicateFileExistsAndOwnedByEffectiveUserID tests that the // operand is the path of a file that the effective user ID owns (-O). UnaryPredicateFileExistsAndOwnedByEffectiveUserID // UnaryPredicateFileExistsAndIsSocket tests that the operand is the path // of a socket (-S). UnaryPredicateFileExistsAndIsSocket // UnaryPredicateShellOptionEnabled tests that the operand is an option of // set -o that is on (-o). UnaryPredicateShellOptionEnabled // UnaryPredicateShellVariableIsSetAndAssigned tests that the operand // names a shell variable that is set and has a value (-v). UnaryPredicateShellVariableIsSetAndAssigned // UnaryPredicateShellVariableIsSetAndNameRef tests that the operand names // a shell variable that is set and is a name reference (-R). UnaryPredicateShellVariableIsSetAndNameRef // UnaryPredicateStringHasZeroLength tests that the operand is an empty // string (-z). UnaryPredicateStringHasZeroLength // UnaryPredicateStringHasNonZeroLength tests that the operand is a string // that is not empty (-n). UnaryPredicateStringHasNonZeroLength )
The tests with one operand.
func (UnaryPredicate) String ¶
func (p UnaryPredicate) String() string
String returns the option of the test, such as "-f".
type UnexpandedArithmeticExpr ¶
type UnexpandedArithmeticExpr struct {
// Value is the text of the expression.
Value string
}
UnexpandedArithmeticExpr is the text of an arithmetic expression. It is not parsed.
func (*UnexpandedArithmeticExpr) String ¶
func (e *UnexpandedArithmeticExpr) String() string
String returns the text of the expression.
type WhileOrUntilClauseCommand ¶
type WhileOrUntilClauseCommand struct {
// Condition is the command whose result controls the loop.
Condition CompoundList
// Body is the command that runs on each pass.
Body DoGroupCommand
// Loc is the location of the loop.
Loc Span
}
WhileOrUntilClauseCommand is a while loop or an until loop. A condition controls the loop.
func (*WhileOrUntilClauseCommand) Location ¶
func (c *WhileOrUntilClauseCommand) Location() (Span, bool)
Location returns the location of the loop.
func (*WhileOrUntilClauseCommand) String ¶
func (c *WhileOrUntilClauseCommand) String() string
String returns the condition, "; " and the body. It does not write the while or until keyword.
type Word ¶
type Word struct {
// Value is the text of the word, as it is in the script.
Value string
// Loc is the location of the word. It is nil when it is not known.
Loc *Span
}
Word is a shell word.
func NewWordWithLocation ¶
NewWordWithLocation returns a word with the text s and the location loc.
type WordParseError ¶
type WordParseError interface {
error
// contains filtered or unexported methods
}
WordParseError is an error of the parser of words. Each kind of error is a type of its own: ErrParseArithmeticExpression, ErrParsePattern, ErrParsePrompt, ErrParseParameter, ErrParseBraceExpansion and ErrParseWord.
The text of an error does not hold its location, as in brush. The field Location of each type holds it.
type WordPiece ¶
type WordPiece interface {
// contains filtered or unexported methods
}
WordPiece is a piece of a word. Each kind of piece is a type of its own, whose name starts with WordPiece.
type WordPieceAnsiCQuotedText ¶
type WordPieceAnsiCQuotedText struct {
// Text is the text between the quotes.
Text string
}
WordPieceAnsiCQuotedText is text in ANSI-C quotes, as in $'a\tb'. Text does not include the quotes, and its escapes are not expanded.
type WordPieceArithmeticExpression ¶
type WordPieceArithmeticExpression struct {
// Expr is the expression.
Expr UnexpandedArithmeticExpr
}
WordPieceArithmeticExpression is an arithmetic expansion, $((expr)) or $[expr].
type WordPieceBackquotedCommandSubstitution ¶
type WordPieceBackquotedCommandSubstitution struct {
// Command is the text of the command. A backslash before "$", "`" or
// "\" is removed.
Command string
}
WordPieceBackquotedCommandSubstitution is a command substitution in backquotes, `command`.
type WordPieceBadSubstitution ¶
type WordPieceBadSubstitution struct {
// Text is the text of the expansion, with "${" and "}".
Text string
}
WordPieceBadSubstitution is a ${...} that bash cannot read, such as ${x!} or ${a b}. Text is all of it, from "${" to the "}" that closes it. bash reports a bad substitution when it expands such a word, and not when it reads it. brush-parser has no such piece. It reads the text as text, and the port departs from it here (W29).
type WordPieceCommandSubstitution ¶
type WordPieceCommandSubstitution struct {
// Command is the text of the command.
Command string
}
WordPieceCommandSubstitution is a command substitution, $(command).
type WordPieceDoubleQuotedSequence ¶
type WordPieceDoubleQuotedSequence struct {
// Pieces holds the pieces between the quotes.
Pieces []WordPieceWithSource
}
WordPieceDoubleQuotedSequence is the sequence of pieces in a pair of double quotes.
type WordPieceEscapeSequence ¶
type WordPieceEscapeSequence struct {
// Text is the backslash and the character.
Text string
}
WordPieceEscapeSequence is a backslash and the character that it escapes.
type WordPieceFunctionSubstitution ¶
type WordPieceFunctionSubstitution struct {
// Command is the text of the command, without "${", the "|" of
// ${| command; } and the "}" that ends it.
Command string
// Value is true for ${| command; }.
Value bool
}
WordPieceFunctionSubstitution is the command substitution of bash 5.3 that runs its command in the shell itself: ${ command; }, which expands to the output of the command, or ${| command; }, which expands to the value of REPLY after it. brush-parser has no such piece, and the port departs from it here (W42).
type WordPieceGettextDoubleQuotedSequence ¶
type WordPieceGettextDoubleQuotedSequence struct {
// Pieces holds the pieces between the quotes.
Pieces []WordPieceWithSource
}
WordPieceGettextDoubleQuotedSequence is the sequence of pieces in a pair of double quotes that starts with a dollar sign, as in $"text". The shell can translate the text.
type WordPieceParameterExpansion ¶
type WordPieceParameterExpansion struct {
// Expr is the parameter expression.
Expr ParameterExpr
}
WordPieceParameterExpansion is a parameter expansion, such as $x or ${x:-y}.
type WordPieceProcessSubstitution ¶
type WordPieceProcessSubstitution struct {
// Kind is the direction: <(command) or >(command).
Kind ProcessSubstitutionKind
// Command is the text of the command, without "<(" and ")".
Command string
}
WordPieceProcessSubstitution is a process substitution inside a word, such as the <(command) of x=<(command) or of a<(command)b. bash reads it as part of the word, and expands it to the name of a file, such as /dev/fd/63. A process substitution that is a whole word is a CommandPrefixOrSuffixItemProcessSubstitution, as in brush. brush-parser has no such piece. It splits the word there, and the port departs from it here.
type WordPieceSingleQuotedText ¶
type WordPieceSingleQuotedText struct {
// Text is the text between the quotes.
Text string
}
WordPieceSingleQuotedText is text in single quotes. Text does not include the quotes.
type WordPieceText ¶
type WordPieceText struct {
// Text is the text.
Text string
}
WordPieceText is text with no quotes and no escapes.
type WordPieceTildeExpansion ¶
type WordPieceTildeExpansion struct {
// Expr is the tilde expression.
Expr TildeExpr
}
WordPieceTildeExpansion is a tilde expansion, such as ~ or ~user.
type WordPieceWithSource ¶
type WordPieceWithSource struct {
// Piece is the piece.
Piece WordPiece
// StartIndex is the offset in bytes of the start of the piece.
StartIndex int
// EndIndex is the offset in bytes of the end of the piece. The piece does
// not include the byte at this offset.
EndIndex int
}
WordPieceWithSource is a piece of a word, and where it is in the text that was parsed.
func ParseDoubleQuotedText ¶
func ParseDoubleQuotedText(text string, kind DoubleQuotedTextKind, options ParserOptions) ([]WordPieceWithSource, error)
ParseDoubleQuotedText parses text that is read as if it were in double quotes, but that does not include the quotes. The text is the body of a here-document, a prompt, or the word of a parameter expansion in one of these or in double quotes. The kind tells how the backslashes and the quotes of the text are read.
The pieces are of the kinds that ParseWord finds between a pair of double quotes. The error is an ErrParseWord.
func ParseHeredoc ¶
func ParseHeredoc(word string, options ParserOptions) ([]WordPieceWithSource, error)
ParseHeredoc parses the body of a here-document. A double quote and a single quote are text in it. It is ParseDoubleQuotedText with the kind DoubleQuotedTextHereDoc. The error is an ErrParseWord.
func ParseWord ¶
func ParseWord(word string, options ParserOptions) ([]WordPieceWithSource, error)
ParseWord parses a word into its pieces. The error is an ErrParseWord.
type WordToken ¶
type WordToken struct {
// Text is the text of the word.
Text string
// Span is the span of the word in the script.
Span Span
}
WordToken is a word. Its text keeps the quotes and the expansions of the script.
Source Files
¶
- alias.go
- ansic.go
- ast.go
- ast_string.go
- ast_string_bash.go
- charreader.go
- charset.go
- complete.go
- doc.go
- errors.go
- extquote.go
- options.go
- parser.go
- parser_compound.go
- parser_cond.go
- parser_extended.go
- parser_peg.go
- parser_simple.go
- reader.go
- source.go
- subscript.go
- testexpr.go
- tokenizer.go
- tokenizer_error.go
- tokenizer_next.go
- tokenizer_read.go
- tokenizer_state.go
- word.go
- word_grammar.go
- word_grammar_assign.go
- word_grammar_brace.go
- word_grammar_param.go
- word_param.go