Source File
format_bash.go
Belonging Package
github.com/carapace-sh/carapace-shlex/v2
package shleximport// bashFormat implements Format for POSIX/bash lexing.// This is the default format. The Classifier reads COMP_WORDBREAKS from// the environment at call time.type bashFormat struct{}func (bashFormat) () tokenClassifier {:= newBaseClassifier(escapeRunes):= BASH_WORDBREAKSif := os.Getenv("COMP_WORDBREAKS"); != "" {=}.addWordbreaks()return}func (bashFormat) ( string) WordbreakType {return bashWordbreakType()}func (bashFormat) () map[string]WordbreakType { return nil }func (bashFormat) () bool { return false }func (bashFormat) () bool { return false }func (bashFormat) () bool { return true }func (bashFormat) () bool { return false }func (bashFormat) () map[rune]bool {return map[rune]bool{'\\': true,'`': true,'$': true,'"': true,'\n': true,}}func (bashFormat) ( string) string { return bashQuoteWord() }func (bashFormat) () bool { return false }func (bashFormat) () bool { return false }// IsLineContinuation implements lineContinuationEscaper. In POSIX shells,// backslash followed by \n or \r is a line continuation — both the backslash// and the newline are consumed (removed from the token value).func (bashFormat) ( rune) bool {return == '\n' || == '\r'}// PostProcess reclassifies ( and ) as substitution delimiters and merges// $ + ( into a single opener token for POSIX command substitution.func (bashFormat) ( TokenSlice) TokenSlice {return posixSubstitutionPostProcess()}// Variable implements variableExpander. Bash expands `$name` and// `${name`; `$` is literal inside single quotes and when escaped.func (bashFormat) ( Token) (Variable, bool) {return posixVariableRef()}// NaiveSplitWord implements naiveWordSplitter. Bash's COMP_WORDS interface// splits naively on wordbreak characters, quotes included, so the shell// replaces only the raw text after the last such character.func ( bashFormat) ( string) string {return naiveSplitWord(.Classifier(), )}func (bashFormat) ( string) bool {return bareWordRe.MatchString()}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |