shlex

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

carapace-shlex

PkgGoDev GoReportCard Coverage Status

Fork of go-shlex aimed to enable completion of complex commands passed as single argument with Split in carapace.

asciicast

Documentation

Index

Constants

View Source
const BASH_WORDBREAKS = " \t\r\n" + `"'><=;|&(:`

Variables

This section is empty.

Functions

func Join added in v0.1.2

func Join(s []string) string

Join concatenates words to create a single string. It quotes and escapes where appropriate. TODO experimental

Types

type LexerState

type LexerState int

the internal state used by the lexer state machine

const (
	START_STATE            LexerState = iota // no runes have been seen
	IN_WORD_STATE                            // processing regular runes in a word
	ESCAPING_STATE                           // we have just consumed an escape rune; the next rune is literal
	ESCAPING_QUOTED_STATE                    // we have just consumed an escape rune within a quoted string
	QUOTING_ESCAPING_STATE                   // we are within a quoted string that supports escaping ("...")
	QUOTING_STATE                            // we are within a string that does not support escaping ('...')
	COMMENT_STATE                            // we are within a comment (everything following an unquoted or unescaped #
	WORDBREAK_STATE                          // we have just consumed a wordbreak rune
)

Lexer state machine states

func (LexerState) MarshalJSON

func (l LexerState) MarshalJSON() ([]byte, error)

type Token

type Token struct {
	Type           TokenType
	Value          string
	RawValue       string
	Index          int
	State          LexerState
	WordbreakType  WordbreakType `json:",omitempty"`
	WordbreakIndex int           // index of last opening quote in Value (only correct when in quoting state)
}

Token is a (type, value) pair representing a lexographical token.

func (*Token) Equal

func (t *Token) Equal(other *Token) bool

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.

type TokenSlice added in v0.0.3

type TokenSlice []Token

func Split

func Split(s string) (TokenSlice, error)

Split partitions of a string into tokens.

func (TokenSlice) CurrentPipeline added in v0.0.3

func (t TokenSlice) CurrentPipeline() TokenSlice

func (TokenSlice) CurrentToken added in v0.0.3

func (t TokenSlice) CurrentToken() (token Token)

func (TokenSlice) FilterRedirects added in v0.0.3

func (t TokenSlice) FilterRedirects() TokenSlice

func (TokenSlice) Pipelines added in v0.0.3

func (t TokenSlice) Pipelines() []TokenSlice

func (TokenSlice) Strings added in v0.0.3

func (t TokenSlice) Strings() []string

func (TokenSlice) WordbreakPrefix added in v0.0.4

func (t TokenSlice) WordbreakPrefix() string

func (TokenSlice) Words added in v0.0.3

func (t TokenSlice) Words() TokenSlice

type TokenType

type TokenType int

TokenType is a top-level token classification: A word, space, comment, unknown.

const (
	UNKNOWN_TOKEN TokenType = iota
	WORD_TOKEN
	SPACE_TOKEN
	COMMENT_TOKEN
	WORDBREAK_TOKEN
)

Classes of lexographic token

func (TokenType) MarshalJSON

func (t TokenType) MarshalJSON() ([]byte, error)

type WordbreakType added in v0.0.3

type WordbreakType int
const (
	WORDBREAK_UNKNOWN WordbreakType = iota
	// https://www.gnu.org/software/bash/manual/html_node/Redirections.html
	WORDBREAK_REDIRECT_INPUT
	WORDBREAK_REDIRECT_OUTPUT
	WORDBREAK_REDIRECT_OUTPUT_APPEND
	WORDBREAK_REDIRECT_OUTPUT_BOTH
	WORDBREAK_REDIRECT_OUTPUT_BOTH_APPEND
	WORDBREAK_REDIRECT_INPUT_STRING
	WORDBREAK_REDIRECT_INPUT_DUPLICATE
	WORDBREAK_REDIRECT_INPUT_OUTPUT
	// https://www.gnu.org/software/bash/manual/html_node/Pipelines.html
	WORDBREAK_PIPE
	WORDBREAK_PIPE_WITH_STDERR
	// https://www.gnu.org/software/bash/manual/html_node/Lists.html)
	WORDBREAK_LIST_ASYNC
	WORDBREAK_LIST_SEQUENTIAL
	WORDBREAK_LIST_AND
	WORDBREAK_LIST_OR
	// COMP_WORDBREAKS
	WORDBREAK_CUSTOM
)

func (WordbreakType) IsPipelineDelimiter added in v0.0.3

func (w WordbreakType) IsPipelineDelimiter() bool

func (WordbreakType) IsRedirect added in v0.0.3

func (w WordbreakType) IsRedirect() bool

func (WordbreakType) MarshalJSON added in v0.0.3

func (w WordbreakType) MarshalJSON() ([]byte, error)

Directories

Path Synopsis
cmd module

Jump to

Keyboard shortcuts

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