package shlex
Import Path
github.com/carapace-sh/carapace-shlex/v2 (on go.dev)
Dependency Relation
imports 9 packages, and imported by 15 packages
Involved Source Files
completion.go
format.go
format_bash.go
format_cmd.go
format_elvish.go
format_fish.go
format_hilbish.go
format_lua.go
format_nushell.go
format_oil.go
format_powershell.go
format_tcsh.go
format_xonsh.go
format_zsh.go
quote.go
shlex.go
substitution.go
substitution_posix.go
tokenslice.go
variable.go
wordbreak.go
Package-Level Type Names (total 9)
CompletionContext describes the completion state at the end of the input.
It is the primary API for completion callers, replacing the manual
tokens.CurrentPipeline().FilterRedirects().Words().currentToken() chains.
CurrentWord is the word at the cursor position (dequoted Value).
InLambdaParams is true when the cursor is inside a lambda parameter
list (e.g. after "{|" in elvish). The completion caller should
complete parameter names, not commands or arguments.
IsRedirect is true when the cursor is completing a redirect target
(e.g. after >, >>, <, etc.).
Prefix is the wordbreak prefix up to the cursor.
QuotingState is the lexer state of the current word.
IN_WORD_STATE, QUOTING_STATE, QUOTING_ESCAPING_STATE, QUOTING_TRIPLE_STATE,
QUOTING_TRIPLE_ESCAPING_STATE, or ESCAPING_STATE.
RawCurrentWord is the raw source of the current word (including quotes).
Use this to detect quotation state when QuotingState alone is insufficient.
Span is the rune span of the current word in the input. Offsets
refer to the full input, also when the context describes the
innermost substitution's command.
SubstitutionDepth is the number of unclosed substitution scopes
at the cursor position. 0 = cursor at top level. When > 0, the
derived fields (Words, CurrentWord, etc.) describe the innermost
substitution's command; Span and Tokens still refer to the full
input.
Tokens is the raw token slice of the whole input — what Split
returns for the same line. Escape hatch for edge cases not covered
by the fields above.
Variable describes a variable reference ending the current word,
detected lexically on the lexer's final word. Nil when the word does
not end in a variable reference, or when the format does not
implement variableExpander.
Words are the dequoted word values in the current pipeline
(redirects filtered). When the cursor is inside a substitution
scope (e.g. $(...), these are the inner command's words.
Quote returns value quoted for insertion at the cursor position
described by the context: an open quote is closed with the format's
own escape rules and a bareword is quoted as a complete word, so the
result can replace the whole raw current word. value is a full
completion candidate matching the current word's typed prefix. Values meant to be
inserted without a trailing space (nospace completions) may be passed
as-is by the caller when quoting is not wanted.
func Complete(s string, format Format) *CompletionContext
Format identifies a shell's lexical rules. It is the name of one of the
supported shells; the lexing behavior itself is internal. Unknown names
are rejected by Split, yield an empty context in Complete, and fall
back to the default format in Join.
the internal state used by the lexer state machine
( LexerState) MarshalJSON() ([]byte, error)
LexerState : github.com/goccy/go-json.Marshaler
LexerState : encoding/json/v2.Marshaler
const BLOCK_COMMENT_STATE
const COMMENT_STATE
const ESCAPING_QUOTED_STATE
const ESCAPING_STATE
const IN_WORD_STATE
const QUOTING_ESCAPING_STATE
const QUOTING_STATE
const QUOTING_TRIPLE_ESCAPING_STATE
const QUOTING_TRIPLE_STATE
const START_STATE
const STOP_PARSING_STATE
const WORDBREAK_STATE
Span represents a rune-offset range in the input string.
// rune offset after the last character
// rune offset of the first character
func Variable.Span() Span
Token is a (type, value) pair representing a lexicographic token.
RawValue string
Span Span
State LexerState
Type TokenType
Value string
// index of last opening quote in Value (only correct when in quoting state)
WordbreakType WordbreakType
Equal reports whether tokens a, and b, are equal.
Two tokens are equal if both their types and values are equal. A nil token can
never be equal to another token.
func (*Token).Equal(other *Token) bool
( TokenSlice) CurrentPipeline() TokenSlice
( TokenSlice) FilterRedirects() TokenSlice
( TokenSlice) Strings() []string
( TokenSlice) WordbreakPrefix() string
( TokenSlice) Words() TokenSlice
func Split(s string, format Format) (TokenSlice, error)
func TokenSlice.CurrentPipeline() TokenSlice
func TokenSlice.FilterRedirects() TokenSlice
func TokenSlice.Words() TokenSlice
TokenType is a top-level token classification: A word, space, comment, unknown.
( TokenType) MarshalJSON() ([]byte, error)
TokenType : github.com/goccy/go-json.Marshaler
TokenType : encoding/json/v2.Marshaler
const COMMENT_TOKEN
const SPACE_TOKEN
const UNKNOWN_TOKEN
const WORD_TOKEN
const WORDBREAK_TOKEN
Variable describes a variable reference ending the current word.
Name is the variable name typed so far. Empty when the cursor is
directly after the sigil.
( Variable) Insert(completed string) string
Insert returns the replacement word with the completed variable
reference in place, preserving the reference's form (`$HOME` or
`${HOME}`). Consumers prefix it with everything before the replaced
region.
Span returns the rune span of the replaced region in the input — the
text Insert replaces (the whole raw word, or its naive suffix for
formats with a naive word interface).
( WordbreakType) IsPipelineDelimiter() bool
( WordbreakType) IsRedirect() bool
( WordbreakType) MarshalJSON() ([]byte, error)
WordbreakType : github.com/goccy/go-json.Marshaler
WordbreakType : encoding/json/v2.Marshaler
const WORDBREAK_BRACKET
const WORDBREAK_CUSTOM
const WORDBREAK_LAMBDA_PIPE
const WORDBREAK_LIST_AND
const WORDBREAK_LIST_ASYNC
const WORDBREAK_LIST_ASYNC_ERRCHECK
const WORDBREAK_LIST_CASE_NEXT
const WORDBREAK_LIST_FALLTHROUGH
const WORDBREAK_LIST_FALLTHROUGH_RETRY
const WORDBREAK_LIST_OR
const WORDBREAK_LIST_SEQUENTIAL
const WORDBREAK_LIST_SEQUENTIAL_DOUBLE
const WORDBREAK_OUTPUT_CAPTURE
const WORDBREAK_PIPE
const WORDBREAK_PIPE_WITH_STDERR
const WORDBREAK_REDIRECT_HERE_DOC
const WORDBREAK_REDIRECT_INPUT
const WORDBREAK_REDIRECT_INPUT_DUPLICATE
const WORDBREAK_REDIRECT_INPUT_OUTPUT
const WORDBREAK_REDIRECT_INPUT_STRING
const WORDBREAK_REDIRECT_OUTPUT
const WORDBREAK_REDIRECT_OUTPUT_APPEND
const WORDBREAK_REDIRECT_OUTPUT_APPEND_FORCE
const WORDBREAK_REDIRECT_OUTPUT_BOTH
const WORDBREAK_REDIRECT_OUTPUT_BOTH_APPEND
const WORDBREAK_REDIRECT_OUTPUT_FORCE
const WORDBREAK_SUBSTITUTION_CLOSE
const WORDBREAK_SUBSTITUTION_OPEN
const WORDBREAK_UNKNOWN
Package-Level Functions (total 6)
Complete parses s and returns a CompletionContext describing
the completion state at the end of the string, using the given format.
An empty or whitespace-terminated line yields an empty current word:
the cursor starts a new word.
When the cursor is inside an unclosed substitution scope (e.g. inside
$(...), the context describes the innermost substitution's command,
not the outer command.
Escape returns the word's content escaped for embedding inside
string literals whose surrounding quote characters the caller supplies,
e.g. when a generated template already carries the quotes. It is the
interior variant of Quote. Unknown format names fall back to the default
format. Formats without a dedicated string-interior rule (cmd, tcsh,
and others) also fall back; the result may not be valid for those
formats' own string literals (e.g. a newline close/reopen sequence is a
syntax error in tcsh). The bash/zsh/oil result is meant to be
embedded in double quotes by the caller: newlines are represented by a
quote close/reopen sequence instead of backslash-newline. The nushell
result is meant to be embedded in double quotes: it uses only escape
sequences from nushell's own set, as unrecognized escapes are parse
errors there.
IsBareWord reports whether the given word is a bareword for the format:
it stands as a single inert token in unquoted position. Identifier
validity is not implied. Empty words are not barewords. Unknown formats
fall back to the default format, like in Quote.
Join concatenates words using the given format's quoting rules.
Unknown format names fall back to the default format.
Quote returns the given word quoted according to the format's quoting
rules, so that it parses back into a single token when split with the same
format. Unknown format names fall back to the default format.
Split partitions a string into tokens using the given format.
Unknown format names are rejected.
Package-Level Constants (total 63)
Supported formats.
const BASH_WORDBREAKS = " \t\r\n\"'@><=;|&():"
Lexer state machine states
Supported formats.
Lexer state machine states
Classes of lexographic token
Default is the empty format name, resolving to Bash. Spec macros
and callers that omit the shell use this.
Supported formats.
Lexer state machine states
Lexer state machine states
Supported formats.
Supported formats.
HILBISH_WORDBREAKS are the wordbreak characters for hilbish: the sh
metacharacters handled by its interpreter, without bash's COMP_WORDBREAKS
customization (@ = : are not word breaks for hilbish).
Lexer state machine states
Supported formats.
Lua has no redirections or pipelines; the structural punctuation is
only needed for word separation. Comments (--) or long strings
([[ ... ]]) are not lexed.
Supported formats.
Supported formats.
Supported formats.
Lexer state machine states
Lexer state machine states
Lexer state machine states
Lexer state machine states
Classes of lexographic token
Lexer state machine states
Lexer state machine states
Supported formats.
TCSH_WORDBREAKS are the wordbreak characters for tcsh, derived from the
_META character class in tcsh's _cmap table (sh.char.c).
Unlike bash, tcsh does not include = or @ as wordbreak characters.
! is NOT a wordbreak: it is _PUN (punctuation) in tcsh's lexer, not _META.
The >! and >>! noclobber operators are recognized at the parser level.
Classes of lexographic token
Classes of lexographic token
Elvish-specific: list literal / indexing delimiters [ and ]
COMP_WORDBREAKS
Elvish lambda parameter delimiter: | inside {|params| ...}
const WORDBREAK_LIST_AND WordbreakType = 17 const WORDBREAK_LIST_ASYNC_ERRCHECK WordbreakType = 23 // &| (zsh background with error check) const WORDBREAK_LIST_CASE_NEXT WordbreakType = 22 // ;;& (case next pattern) const WORDBREAK_LIST_FALLTHROUGH WordbreakType = 20 // ;& (case fall-through) const WORDBREAK_LIST_FALLTHROUGH_RETRY WordbreakType = 21 // ;| (zsh case fall-through with retry) const WORDBREAK_LIST_OR WordbreakType = 18 const WORDBREAK_LIST_SEQUENTIAL WordbreakType = 16 const WORDBREAK_LIST_SEQUENTIAL_DOUBLE WordbreakType = 19 // ;; (case terminator)
Elvish-specific: output capture delimiters ( and )
const WORDBREAK_PIPE_WITH_STDERR WordbreakType = 13 const WORDBREAK_REDIRECT_HERE_DOC WordbreakType = 9 // << (here-document) const WORDBREAK_REDIRECT_INPUT_DUPLICATE WordbreakType = 10 const WORDBREAK_REDIRECT_INPUT_OUTPUT WordbreakType = 11 const WORDBREAK_REDIRECT_INPUT_STRING WordbreakType = 8 const WORDBREAK_REDIRECT_OUTPUT WordbreakType = 2 const WORDBREAK_REDIRECT_OUTPUT_APPEND_FORCE WordbreakType = 5 // >>| (noclobber override for append) const WORDBREAK_REDIRECT_OUTPUT_BOTH WordbreakType = 6 const WORDBREAK_REDIRECT_OUTPUT_FORCE WordbreakType = 4 // >| (noclobber override)
Lexer state machine states
const WORDBREAK_SUBSTITUTION_CLOSE WordbreakType = 28
Substitution delimiters: ( and ) that open/close command/arithmetic
substitution scopes ($(...), `...`, (...), $((...)) , <(...), >(...))
Classes of lexographic token
const WORDBREAK_UNKNOWN WordbreakType = 0
Supported formats.
Supported formats.
![]() |
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. |