shparse

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	CompTypeCommandMeta = "command-meta"
	CompTypeCommand     = "command"
	CompTypeArg         = "command-arg"
	CompTypeInvalid     = "invalid"
	CompTypeVar         = "var"
	CompTypeAssignment  = "assignment"
	CompTypeBasic       = "basic"
	CompTypeFile        = "file"
	CompTypeDir         = "dir"
)
View Source
const (
	WordTypeRaw       = "raw"
	WordTypeLit       = "lit"  // (can-extend)
	WordTypeOp        = "op"   // single: & ; | ( ) < > \n  multi(2): && || ;; << >> <& >& <> >| ((  multi(3): <<-    ('((' requires special processing)
	WordTypeKey       = "key"  // if then else elif fi do done case esac while until for in { } ! (( [[
	WordTypeGroup     = "grp"  // contains other words e.g. "hello"foo'bar'$x (has-subs) (can-extend)
	WordTypeSimpleVar = "svar" // simplevar $ (can-extend)

	WordTypeDQ       = "dq"   // "    (quote-context) (can-extend) (has-subs)
	WordTypeDDQ      = "ddq"  // $"   (can-extend) (has-subs) (for quotecontext, uses WordTypeDQ)
	WordTypeVarBrace = "varb" // ${   (quote-context) (can-extend) (internals not parsed)
	WordTypeDP       = "dp"   // $(   (quote-context) (has-subs)
	WordTypeBQ       = "bq"   // `    (quote-context) (has-subs)

	WordTypeSQ  = "sq"  // '     (can-extend)
	WordTypeDSQ = "dsq" // $'    (can-extend)
	WordTypeDPP = "dpp" // $((   (internals not parsed)
	WordTypePP  = "pp"  // ((    (internals not parsed)
	WordTypeDB  = "db"  // $[    (internals not parsed)
)

can-extend: WordTypeLit, WordTypeSimpleVar, WordTypeVarBrace, WordTypeDQ, WordTypeDDQ, WordTypeSQ, WordTypeDSQ

View Source
const (
	CmdTypeNone   = "none"   // holds control structures: '(' ')' 'for' 'while' etc.
	CmdTypeSimple = "simple" // holds real commands
)
View Source
const MaxExpandLen = 64 * 1024

Variables

This section is empty.

Functions

func Extend

func Extend(word *WordType, wordPos int, extStr string, complete bool) utilfn.StrWithPos

lit, grp, svar, dq, ddq, varb, sq, dsq

func ResetWordOffsets

func ResetWordOffsets(words []*WordType, startIdx int)

func SimpleVarNamePrefix

func SimpleVarNamePrefix(ectx ExpandContext, word *WordType, pos int) (string, bool)

returns varname (no '$') and ok (whether this is a valid varname expansion)

Types

type CmdType

type CmdType struct {
	Type            string
	AssignmentWords []*WordType
	Words           []*WordType
	NoneComplete    bool // set to true when last-word is a "separator"
}

func ParseCommands

func ParseCommands(words []*WordType) []*CmdType

type CompletionPos

type CompletionPos struct {
	RawPos      int // the raw position of cursor
	SuperOffset int // adjust all offsets in Cmd and CmdWord by SuperOffset

	CompType string   // see CompType* constants
	Cmd      *CmdType // nil if between commands or a special completion (otherwise will be a SimpleCommand)
	// index into cmd.Words (only set when Cmd is not nil, otherwise we look at CompCommand)
	//   0 means command-word
	//   negative means assignment-words.
	//   can be past the end of Words (means start new word).
	CmdWordPos     int
	CompWord       *WordType // set to the word we are completing (nil if we are starting a new word)
	CompWordOffset int       // offset into compword (only if CmdWord is not nil)
}

func FindCompletionPos

func FindCompletionPos(cmds []*CmdType, pos int) CompletionPos

func (CompletionPos) Extend

func (cpos CompletionPos) Extend(origStr utilfn.StrWithPos, extensionStr string, extensionComplete bool) utilfn.StrWithPos

type ExpandContext

type ExpandContext struct {
	HomeDir string
}

type ExpandInfo

type ExpandInfo struct {
	HasTilde   bool // only ~ as the first character when SimpleExpandContext.HomeDir is set
	HasVar     bool // $x, $$, ${...}
	HasGlob    bool // *, ?, [, {
	HasExtGlob bool // ?(...) ... ?*+@!
	HasHistory bool // ! (anywhere)
	HasSpecial bool // subshell, arith
}

func SimpleExpand

func SimpleExpand(ectx ExpandContext, word *WordType) (string, ExpandInfo)

func SimpleExpandPrefix

func SimpleExpandPrefix(ectx ExpandContext, word *WordType, pos int) (string, ExpandInfo)

type QuoteContext

type QuoteContext []string

type WordType

type WordType struct {
	Type     string
	Offset   int
	QC       QuoteContext
	Raw      []rune
	Complete bool
	Prefix   []rune
	Subs     []*WordType
}

func CommandsToWords

func CommandsToWords(cmds []*CmdType) []*WordType

func MakeEmptyWord

func MakeEmptyWord(wtype string, qc QuoteContext, offset int, complete bool) *WordType

func Tokenize

func Tokenize(cmd string) []*WordType

func (*WordType) String

func (w *WordType) String() string

Jump to

Keyboard shortcuts

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