Documentation
¶
Index ¶
- Variables
- func Flags(arg ...*Argument) map[string]*Argument
- func JoinErr(a, b error) error
- func LoadStringsProcs(interp *Interp)
- func ParseArgsLazy(namedProto []*Token, posProto []*Token, args []*Token) (parsedArgs map[string]*Token, err error)
- func ParseProto(proto *Token) (namedProto []*Token, posProto []*Token, err error)
- func TestNamespaceTokenization_ExtremeNames(t *testing.T)
- func TestNamespace_IntrospectionFlatNested(t *testing.T)
- func TestPlanes_NoCollisions(t *testing.T)
- func TokenJoin(toks []*Token, joinStr string) string
- type ArgGroup
- type ArgSet
- func (as *ArgSet) ArgGroup(ags ...*ArgGroup)
- func (as *ArgSet) Arities() (arr []Arity)
- func (as *ArgSet) BindArgs(interp *Interp, args []*Token) (boundArgs map[string]*Token, err error)
- func (as *ArgSet) BindPosOnly(interp *Interp, args []*Token) (boundArgs map[string]*Token, err error)
- func (as *ArgSet) GetArgGroup(arr Arity) *ArgGroup
- func (as *ArgSet) HelpText() string
- func (as *ArgSet) ParseProto(proto *Token) error
- func (as *ArgSet) ShowUsage(w io.Writer)
- func (as *ArgSet) Signature() string
- func (as *ArgSet) Validate() error
- type Argument
- func Arg(name string) *Argument
- func ArgDefault(name string, def *Token) *Argument
- func ArgDefaultCoerce(name string, def, coerce *Token) *Argument
- func ArgDefaultHelp(name string, def *Token, help string) *Argument
- func ArgHelp(name, help string) *Argument
- func ParseProtoArg(arg *Token) (parg *Argument, err error)
- type Arity
- type Command
- type Deleter
- type Equivalence
- type Error
- type Errors
- type Float
- type Floater
- type Frame
- type Getter
- type Integer
- type Interfacer
- type Interp
- func (interp *Interp) AbsoluteProc(qualPath string) Proc
- func (interp *Interp) CallDepth() int
- func (interp *Interp) DelVar(name string) (*Token, error)
- func (interp *Interp) Exec(cmd Command) (tok *Token, err error)
- func (interp *Interp) ExecBytes(rawScript []byte) (*Token, error)
- func (interp *Interp) ExecLiteral(cmd Command) (tok *Token, err error)
- func (interp *Interp) ExecScript(script Script) (ret *Token, err error)
- func (interp *Interp) ExecString(str string) (*Token, error)
- func (interp *Interp) ExecToken(tok *Token) (*Token, error)
- func (interp *Interp) GetVar(name string) (v *Token, err error)
- func (interp *Interp) LoadProcs(ns string, procset map[string]Proc)
- func (interp *Interp) Pop()
- func (interp *Interp) Printf(format string, args ...any)
- func (interp *Interp) Proc(name string, proc Proc) (err error)
- func (interp *Interp) Push(frame *Frame)
- func (interp *Interp) ResolveIdentifier(id string, create bool) (*Namespace, string, error)
- func (interp *Interp) ResolveProc(name string) (Proc, error)
- func (interp *Interp) SetVar(name string, val *Token) (*Token, error)
- func (interp *Interp) Subst(tok *Token) (*Token, error)
- type List
- type Map
- type Monotonic
- type Namespace
- type NilReader
- type Number
- type PlaneCase
- type Proc
- type Procer
- type Ref
- type Runable
- type Script
- type Setter
- type Signal
- type Token
- func LexStringToList(str string) ([]*Token, error)
- func NewList(s []*Token) *Token
- func NewToken(v any) *Token
- func NewTokenBytes(str []byte) *Token
- func NewTokenCat(toks ...*Token) *Token
- func NewTokenInt(i int) *Token
- func NewTokenListString(strs []string) (list []*Token)
- func NewTokenString(str string) *Token
- func ParseArgs(args []*Token) (namedArgs map[string]*Token, posArgs []*Token, err error)
- func ProcAnd(interp *Interp, args []*Token) (*Token, error)
- func ProcBool(interp *Interp, args []*Token) (*Token, error)
- func ProcBreak(interp *Interp, args []*Token) (*Token, error)
- func ProcCatch(interp *Interp, args []*Token) (*Token, error)
- func ProcConcat(interp *Interp, args []*Token) (*Token, error)
- func ProcContinue(interp *Interp, args []*Token) (*Token, error)
- func ProcDel(interp *Interp, args []*Token) (*Token, error)
- func ProcDiff(interp *Interp, args []*Token) (*Token, error)
- func ProcDiv(interp *Interp, args []*Token) (*Token, error)
- func ProcDoWhile(interp *Interp, args []*Token) (*Token, error)
- func ProcEq(interp *Interp, args []*Token) (*Token, error)
- func ProcEval(interp *Interp, args []*Token) (*Token, error)
- func ProcFalse(interp *Interp, args []*Token) (*Token, error)
- func ProcFloat(interp *Interp, args []*Token) (*Token, error)
- func ProcFor(interp *Interp, args []*Token) (*Token, error)
- func ProcForEach(interp *Interp, args []*Token) (ret *Token, err error)
- func ProcGoType(interp *Interp, args []*Token) (*Token, error)
- func ProcIdx(interp *Interp, args []*Token) (*Token, error)
- func ProcIf(interp *Interp, args []*Token) (*Token, error)
- func ProcImport(interp *Interp, args []*Token) (*Token, error)
- func ProcIncr(interp *Interp, args []*Token) (*Token, error)
- func ProcInt(interp *Interp, args []*Token) (*Token, error)
- func ProcLen(interp *Interp, args []*Token) (*Token, error)
- func ProcList(interp *Interp, args []*Token) (*Token, error)
- func ProcListAppend(interp *Interp, args []*Token) (*Token, error)
- func ProcListContains(interp *Interp, args []*Token) (*Token, error)
- func ProcListFind(interp *Interp, args []*Token) (*Token, error)
- func ProcListMap(interp *Interp, args []*Token) (*Token, error)
- func ProcListReverse(interp *Interp, args []*Token) (*Token, error)
- func ProcListSet(interp *Interp, args []*Token) (*Token, error)
- func ProcListSplit(interp *Interp, args []*Token) (*Token, error)
- func ProcListUniq(interp *Interp, args []*Token) (*Token, error)
- func ProcMacro(interp *Interp, args []*Token) (*Token, error)
- func ProcMul(interp *Interp, args []*Token) (*Token, error)
- func ProcNamespace(interp *Interp, args []*Token) (*Token, error)
- func ProcNeq(interp *Interp, args []*Token) (*Token, error)
- func ProcNot(interp *Interp, args []*Token) (*Token, error)
- func ProcOr(interp *Interp, args []*Token) (*Token, error)
- func ProcPipeline(interp *Interp, args []*Token) (*Token, error)
- func ProcPrint(interp *Interp, args []*Token) (*Token, error)
- func ProcProc(interp *Interp, args []*Token) (*Token, error)
- func ProcReturn(interp *Interp, args []*Token) (*Token, error)
- func ProcSet(interp *Interp, args []*Token) (*Token, error)
- func ProcSlice(interp *Interp, args []*Token) (*Token, error)
- func ProcSort(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsCompare(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsContains(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsContainsAny(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsContainsRune(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsCount(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsEqualFold(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsFields(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsFieldsFunc(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsFormat(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsHasPrefix(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsHasSuffix(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsIndex(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsIndexAny(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsIndexRune(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsJoin(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsLastIndex(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsLastIndexAny(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsMap(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsRepeat(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsReplace(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsReplaceAll(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsSplit(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsSplitAfter(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsSplitAfterN(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsSplitN(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsToLower(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsToTitle(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsToUpper(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsTrim(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsTrimLeft(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsTrimPrefix(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsTrimRight(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsTrimSpace(interp *Interp, args []*Token) (*Token, error)
- func ProcStringsTrimSuffix(interp *Interp, args []*Token) (*Token, error)
- func ProcSubst(interp *Interp, args []*Token) (*Token, error)
- func ProcSum(interp *Interp, args []*Token) (*Token, error)
- func ProcTailcall(interp *Interp, args []*Token) (*Token, error)
- func ProcThrow(interp *Interp, args []*Token) (*Token, error)
- func ProcTrue(interp *Interp, args []*Token) (*Token, error)
- func ProcTuple(interp *Interp, args []*Token) (*Token, error)
- func ProcUnicodeIsLetter(interp *Interp, args []*Token) (*Token, error)
- func ProcVar(interp *Interp, args []*Token) (*Token, error)
- func ProcWhile(interp *Interp, args []*Token) (*Token, error)
- func Wrap(v any) *Token
- func (tok *Token) Append(elements ...*Token) *Token
- func (tok *Token) AsBool() (bool, error)
- func (tok *Token) AsCommand() (Command, error)
- func (tok *Token) AsFloat() (float64, error)
- func (tok *Token) AsInt() (int, error)
- func (tok *Token) AsList() (list []*Token, err error)
- func (tok *Token) AsMap() (Map, error)
- func (tok *Token) AsProc(interp *Interp) (Proc, error)
- func (tok *Token) AsScript() (Script, error)
- func (tok *Token) AsTuple(list []*Token) (*Token, error)
- func (tok *Token) Equal(c *Token) bool
- func (tok *Token) Error() string
- func (tok *Token) Index(idx int) *Token
- func (tok *Token) IndexSet(idx int, value *Token) (*Token, error)
- func (tok *Token) IsTrue() bool
- func (tok *Token) Len() int
- func (tok *Token) ListOfOne() bool
- func (tok *Token) Literal() string
- func (tok *Token) Quoted() string
- func (tok *Token) Slice(start, end int) *Token
- func (tok *Token) Summary() string
- type TokenMarshaler
- type TokenUnmarshaler
- type UsageError
Constants ¶
This section is empty.
Variables ¶
var ( ErrFlowControl = flowControl("") ErrReturn = flowControl("return") ErrBreak = flowControl("break") ErrContinue = flowControl("continue") ErrTailcall = flowControl("tailcall") ErrMaxCallDepthExceeded = flowControl("max call depth exceeded") )
var ( ErrCommandNotFound = Error(errCommandNotFound) ErrSyntax = Error(errSyntax) ErrExpectedMore = Error(errExpectedMore) ErrSyntaxExpected = Error(errSyntaxExpected) ErrEvalCond = Error(errEvalCond) ErrEvalBody = Error(errEvalBody) ErrCondNotBool = Error(errCondNotBool) ErrNoVar = Error(errNoVar) ErrNoNamespace = Error(errNoNamespace) ErrArgCount = Error(errArgCount) ErrArgMinimum = Error(errArgMinimum) ErrArgMissing = Error(errArgMissing) ErrArgExtra = Error(errArgExtra) ErrExpectedArgType = Error(errExpectedArgType) ErrExpectedBool = Error(errExpectedBool) ErrExpectedInt = Error(errExpectedInt) ErrExpectedList = Error(errExpectedList) ErrNamedArgMissingValue = Error(errNamedArgMissingValue) ErrCommand = Error(errCommand) ErrLine = Error(errLine) ErrNotImplemented = Error(errNotImplemented) ErrGoPanic = Error(errGoPanic) )
var ( EmptyToken = &Token{} EmptyList = List{} )
var ( TrueToken = &Token{String: "true", Data: true} FalseToken = &Token{String: "false", Data: false} )
var ListLib = map[string]Proc{}
var StdLib = make(map[string]Proc)
var StringsProcs = map[string]Proc{ "format": ProcStringsFormat, "contains": ProcStringsContains, "containsany": ProcStringsContainsAny, "containsrune": ProcStringsContainsRune, "equalfold": ProcStringsEqualFold, "hasprefix": ProcStringsHasPrefix, "hassuffix": ProcStringsHasSuffix, "count": ProcStringsCount, "index": ProcStringsIndex, "lastindex": ProcStringsLastIndex, "indexany": ProcStringsIndexAny, "lastindexany": ProcStringsLastIndexAny, "indexrune": ProcStringsIndexRune, "split": ProcStringsSplit, "splitn": ProcStringsSplitN, "splitafter": ProcStringsSplitAfter, "splitaftern": ProcStringsSplitAfterN, "join": ProcStringsJoin, "replace": ProcStringsReplace, "replaceall": ProcStringsReplaceAll, "repeat": ProcStringsRepeat, "tolower": ProcStringsToLower, "toupper": ProcStringsToUpper, "totitle": ProcStringsToTitle, "trim": ProcStringsTrim, "trimleft": ProcStringsTrimLeft, "trimright": ProcStringsTrimRight, "trimspace": ProcStringsTrimSpace, "trimprefix": ProcStringsTrimPrefix, "trimsuffix": ProcStringsTrimSuffix, "compare": ProcStringsCompare, "map": ProcStringsMap, "fields": ProcStringsFields, "fieldsfunc": ProcStringsFieldsFunc, }
var WrapDecider = func(t reflect.Type, v reflect.Value) bool { if !v.IsValid() { return false } tokenT := reflect.TypeOf((*Token)(nil)).Elem() if t == tokenT || t == reflect.PointerTo(tokenT) { return false } base := t for base.Kind() == reflect.Pointer { base = base.Elem() } switch base.Kind() { case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64, reflect.String: return false } if hasExportedMethod(v) { return true } if v.CanAddr() && hasExportedMethod(v.Addr()) { return true } return false }
WrapDecider lets callers override auto-wrap behavior. Return true to wrap, false to leave as a plain NewToken.
Functions ¶
func ParseArgsLazy ¶
func ParseProto ¶
ParseProto parses a proc argument prototype, returning the list of named args and the list of positional args.
func TestPlanes_NoCollisions ¶
Types ¶
type ArgGroup ¶
func NewArgGroup ¶
type ArgSet ¶
func NewArgSet ¶
NewArgSet returns an ArgSet with Cmd initialzed with name. If args are supplied, they are added to an ArgGroup and the the ArgGroup is added to ArgSet.
func (*ArgSet) BindArgs ¶
BindArgs uses the defined ArgSet to bind arguments passed in args to a map[string]*Token. This map[string]*Token is suitable for passing to interp.Push() as done when invoking a Proc.
func (*ArgSet) BindPosOnly ¶
func (as *ArgSet) BindPosOnly(interp *Interp, args []*Token) (boundArgs map[string]*Token, err error)
BindPosOnly works the same as BindArgs, but it acts as though the first argument after the assumed command is "--" so all args are treated as positional arguments.
func (*ArgSet) GetArgGroup ¶
func (*ArgSet) ParseProto ¶
ParseProto parses a proc prototype (an *adz.Token) into an ArgSet. PasreProto is for generating an ArgSet from a prototype passed from adz. Procs written in go should just build out ArgSet within go.
type Argument ¶
func ArgDefault ¶
func ArgDefaultCoerce ¶
func ParseProtoArg ¶
type Deleter ¶
Deleter works slightly differently it is not called in place of the regular delete function, but call first and then the regular delete is performed.
type Equivalence ¶
type Float ¶
type Float float64
Float and it's single method Float() is a helper to easily pass float64s to things expecting a Floater interface.
type Floater ¶
type Floater interface {
Float() float64
}
Floater is an interface so an otherwise opaque object can signal it is a a float value.
type Getter ¶
Getter hooks getting a variable. If the token's .Data field implements Getter, Get() is called in lieu of returning varMap["name"]. src is the token that owns the .Data field.
type Interfacer ¶
type Interfacer interface {
Interface() any
}
Interfacer is an interface that allows a Token to be overloaded with type infomation. For example, if a third party object is wrapped so that it can implement Getter/Setter/TokenMarshler etc, but still want to be able to retrieve and pass the wrapped value around, have the object implement Interfacer.
type ExternalType struct {}
type WrappedType struct {
ExternalType
}
func(wt *WrappedType) Interfacer() any {
return wt.ExternalType
}
type Interp ¶
type Interp struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
Namespaces map[string]*Namespace
Stack []*Frame
Frame *Frame
Monotonic Monotonic
MaxCallDepth int
*sync.Mutex
// contains filtered or unexported fields
}
func (*Interp) AbsoluteProc ¶
AbsoluteProc exclusively takes a fully qualified path and returns the matching proc if found. Otherwise it returns nil.
func (*Interp) ExecLiteral ¶
ExecLiteral executes cmd without first doing a substitution pass.
func (*Interp) ResolveIdentifier ¶
type List ¶
type List []*Token
func LexBytesToList ¶
func ListOfLists ¶
not sure if this is useful anywhere else... just leave it here for now
type Namespace ¶
func NewNamespace ¶
type Number ¶
type Number interface {
constraints.Integer | constraints.Float
}
type Procer ¶
Procer (would you pronounce that like "procker" or "pro-sir"?) is an interface that allows an object, especially one referenced by the Data field of a token, to be callable as a Proc; the differs from storing a Proc in the Data field of token, such that it can implement other interfaces as well.
type Ref ¶
Ref is a Getter, Setter, and Deleter that implements cross-frame and cross-namespace references, and is used by ProcImport.
type Script ¶
type Script []Command
Script is a set of a commands and a set of commands are a set of tokens
type Setter ¶
Setter hooks setting a variable. If the token's .Data field implements Setter, Set() is called in lieu of setting varMap["name"]. src is the token with the .Data field that implements Setter. val is the token that was passed to set command. Typically set returns the value it was set to, but the Setter interface allows you to diverge from this behavior.
type Signal ¶
type Signal int
Signals are akin to unix signals (but not the same thing!) Interpreters will keep running until they run out of commands or if they get a signal. Signals are implemented via go channels.
type Token ¶
func LexStringToList ¶
func NewTokenBytes ¶
func NewTokenCat ¶
NewTokenCat makes a new token by concatenating the supplied tokens together
func NewTokenInt ¶
func NewTokenListString ¶
func NewTokenString ¶
func ParseArgs ¶
ParseArgs takes a slice of adz *Tokens and parses them per this rule set:
- The first argument is skipped; this is assumed to be the command.
- An argument starting with a dash is a named argument.
- The token after a named arguement is the value.
- It is an error to have a named argument without a following value argument.
- If the argument does not start with a dash, it is a positional argument.
- After an argument of -- is passed, all subsequent arguments including those that start with a dash will be treated as positional arguments.
- Single or zero character arguments are always positional.
func ProcConcat ¶
ProcConcat returns its arguments concatenated
func ProcForEach ¶
ProcForEach
func ProcGoType ¶
ProcGoType implements gotype, a coercer proc that ensures the underlying type of Data is the the go type specified. gotype *gopackage.SomeType $token
func ProcImport ¶
ProcImport implements the import proc. With one arg, import climbs the stack, looking for a variable with the same name and puts it into the localvars. With two vars, the first must be a fully qualified name. This var is linked as the
Globs only for fully qualified identifiers. import -proc ::list::* ;# import all procs in ::list namespace import ::ns::* ;# import all variables from ::ns name space
combined:
import -proc {::list::idx ::list::someVar} -proc ::list::len import -proc {::list::idx ::list::len}
func ProcList ¶
ProcList returns a well-formed list. The list is pre-parsed as a list and will be readily accessible for use as a list.
func ProcListSplit ¶
TODO: split on multiple substrs. TODO: Check args
func ProcMacro ¶
do we want to have macros support arguments? if we do that then it's perhaps too similar to a proc? It's just a proc that doesn't isolate its vars
func ProcPipeline ¶
With 1 argument, chain executes it as a script. After each command in the script, the output of the command is saved into the special variable $|. This can then be used in the next command as input. With two arguments the final output of the chain is stored in a variable of that name.
Example:
pipeline result {
curl wobpage.net/data
lindex $| 0
field $| key.value.*
touch $|
}
func ProcStringsContainsAny ¶
func ProcStringsContainsRune ¶
func ProcStringsEqualFold ¶
func ProcStringsFields ¶
strings.Fields: split on runs of space (no callback needed)
func ProcStringsFieldsFunc ¶
strings.FieldsFunc: predicate proc gets one rune; truthy => split
func ProcStringsHasPrefix ¶
func ProcStringsHasSuffix ¶
func ProcStringsIndexRune ¶
func ProcStringsLastIndex ¶
func ProcStringsLastIndexAny ¶
func ProcStringsMap ¶
strings.Map: map each rune via a proc: mapper :: r -> string (or empty to drop)
func ProcStringsReplaceAll ¶
func ProcStringsSplitAfter ¶
func ProcStringsSplitAfterN ¶
func ProcStringsTrimPrefix ¶
func ProcStringsTrimRight ¶
func ProcStringsTrimSpace ¶
func ProcStringsTrimSuffix ¶
func ProcUnicodeIsLetter ¶
Bonus: quick Unicode helpers if you want them exposed too
func ProcVar ¶
var varname - returns true/false if varname exists or doesn't exist var varname {val} sets varname to val var varname cmd <args> does a variable subcommand like... var varname idx n ;# treat varname as a list and return the nth index of varname; var varname idx {n1 n2 n3...} ;# treat varname as a list and return the n3-th index of the n2-th index of the n1-th index of varname; var varname idx n val;# treat varname as a list and set the nth index of varname to val var varname len ;# treat varname as a list and return its length var varname append ;# append
func Wrap ¶
Wrap takes any value v and returns a *Token that prints like v and is invocable as a Proc: [$obj <Method> arg ...]. Method is validated via ArgSet using a tuple coercer that lists all valid methods.
func (*Token) AsCommand ¶
AsCommand is similar to AsList, but doesn't overwrite the underlaying Data type so anonymous procs are preserved.
func (*Token) AsTuple ¶
AsTuple ensures that tok is equal to one of the values in list or an error is thrown.
func (*Token) Index ¶
Index treats tok as a list and returns the idx'th element of tok. A negative index is treated as backwards (so -1 is the last element). Non existent elements return an EmptyToken.
func (*Token) ListOfOne ¶
ListOfOne returns true when interpreting token as a List, it has a Length of 1 or zero.
func (*Token) Literal ¶
Literal is the converse of Quoted. It returns the token string stripped of any quoting brackets.
type TokenMarshaler ¶
type TokenUnmarshaler ¶
type UsageError ¶
type UsageError struct {
// contains filtered or unexported fields
}
func (*UsageError) Error ¶
func (ue *UsageError) Error() string