parse

package
v0.0.0-...-13c19bd Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFormat = FormatOptions{
	IntegerBase:      10,
	FloatFormat:      'g',
	FloatPrecision:   -1,
	ComplexFormat:    'g',
	ComplexPrecision: -1,
}

DefaultFormat contains the default formatting options for a Return value formatted as a string.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Name string
	Ref  []Reference
	Type string
}

Argument represents an individual argument variable in the list of argument variables of an individual function definition.

func NewArgument

func NewArgument(field *ast.Field) *Argument

NewArgument creates a new Argument by inspecting the parsed AST field.

func (*Argument) Declaration

func (arg *Argument) Declaration() string

Declaration returns a representation of the type of this argument that can be attached to a local variable identifier.

func (*Argument) Expression

func (arg *Argument) Expression() string

Expression returns a string representation of the receiver arg suitable for passing on as argument in a function call.

func (*Argument) IsListRef

func (arg *Argument) IsListRef(ri int) bool

IsListRef returns whether or not the reference at index ri is one of the list types (array or ellipses).

func (*Argument) Parse

func (arg *Argument) Parse(expr ast.Expr) *Argument

Parse constructs an Argument by traversing the AST construction.

func (*Argument) Parser

func (arg *Argument) Parser(aName, pName, iName string, argPos, numArgs, reqArgs int) []string

Parser returns a slice of Go source code lines defining an anonymous function that will parse a string into a variable whose type is identified by the receiver arg's Type.

func (*Argument) ProtoGo

func (arg *Argument) ProtoGo() string

ProtoGo returns the signature used for this Argument value for the Go interface.

func (*Argument) ProtoSh

func (arg *Argument) ProtoSh() string

ProtoSh returns the signature used for this Argument value for the shell interface.

func (*Argument) Prototype

func (arg *Argument) Prototype(sh bool) string

Prototype returns the signature used for this Argument value for either the shell interface or the Go interface.

func (*Argument) String

func (arg *Argument) String() string

type FormatOptions

type FormatOptions struct {
	IntegerBase      int
	FloatFormat      byte
	FloatPrecision   int
	ComplexFormat    byte
	ComplexPrecision int
}

FormatOptions stores the various formatting options used to format a Return value as a string.

type Function

type Function struct {
	Name string
	Arg  []*Argument
	Ret  []*Return
}

Function represents the signature or definition of an individual function.

func (*Function) Elements

func (fun *Function) Elements(sh bool, pkg string) (name string, args, rets []string)

Elements returns the primary components of a prototype formatted for either the Go (sh == false) or the shell (sh == true) interface.

func (*Function) FullName

func (fun *Function) FullName(pkg string) string

FullName returns the fully-qualified name of the receiver fun, escaped for use as either Go function or shell command.

func (*Function) ImportedName

func (fun *Function) ImportedName(pkg string) string

ImportedName returns the import-qualified name of the receiver fun.

func (*Function) MinArgs

func (fun *Function) MinArgs() int

MinArgs returns the minimum number of arguments required to invoke this function.

func (*Function) Parse

func (fun *Function) Parse(decl *ast.FuncDecl) *Function

Parse constructs an individual function signature using a node in the AST parsed from a given Go package. Returns affirmation function is supported, i.e., has a signature we currently support.

func (*Function) ProtoGo

func (fun *Function) ProtoGo(pkg string) string

ProtoGo returns the signature of this function for the Go interface.

func (*Function) ProtoSh

func (fun *Function) ProtoSh(pkg string) string

ProtoSh returns the signature of this function for the shell interface.

func (*Function) Prototype

func (fun *Function) Prototype(sh bool, pkg string) string

Prototype returns the signature of this function for either the Go or the shell interface.

type Package

type Package struct {
	Func []*Function
	// contains filtered or unexported fields
}

Package represents the list of function signatures exported from a given Go package.

func (*Package) SetAllowedArgument

func (pkg *Package) SetAllowedArgument(arg ...string)

SetAllowedArgument defines the base type of arguments we want to keep. If an argument type identifier encountered does not exist in this list, then the entire corresponding function is ignored.

func (*Package) SetAllowedReturn

func (pkg *Package) SetAllowedReturn(ret ...string)

SetAllowedReturn defines the base type of returns we want to keep. If a return type identifier encountered does not exist in this list, then the entire corresponding function is ignored.

func (*Package) Visit

func (pkg *Package) Visit(n ast.Node) ast.Visitor

Visit will traverse a given Go package AST and construct a list of function signatures uniquely describing all of its available (exported) functions.

type Reference

type Reference int

Reference represents a reference to a subtype in either the argument list or the return list of a function definition.

const (
	RefNone Reference = iota
	RefArray
	RefEllipses
	RefPointer
)

Constant values for the enumerated type Reference.

func (Reference) String

func (ref Reference) String() string

String returns a human-readable description of ref.

func (Reference) Symbol

func (ref Reference) Symbol() string

Symbol returns the string used in Go syntax to express ref.

type Return

type Return struct {
	Name string
	Ref  []Reference
	Type string
}

Return represents an individual return variable in the list of return variables of an individual function definition.

func NewReturn

func NewReturn(field *ast.Field) *Return

NewReturn creates a new Return by inspecting the parsed AST field.

func (*Return) Declaration

func (ret *Return) Declaration() string

Declaration returns a representation of the type of this return variable that can be attached to a local variable identifier.

func (*Return) Formatter

func (ret *Return) Formatter(rName, qName string, retPos, numRets int, format FormatOptions) []string

Formatter returns a slice of Go source code lines defining an anonymous function that will convert a variable whose type is identified by the receiver ret's Type into a string.

func (*Return) IsListRef

func (ret *Return) IsListRef(ri int) bool

IsListRef returns whether or not the reference at index ri is one of the list types (array or ellipses).

func (*Return) Parse

func (ret *Return) Parse(expr ast.Expr) *Return

Parse constructs an Return by traversing the AST construction.

func (*Return) ProtoGo

func (ret *Return) ProtoGo() string

ProtoGo returns the signature used for this Return value for the Go interface.

func (*Return) ProtoSh

func (ret *Return) ProtoSh() string

ProtoSh returns the signature used for this Return value for the shell interface.

func (*Return) Prototype

func (ret *Return) Prototype(sh bool) string

Prototype returns the signature used for this Return value for either the shell interface or the Go interface.

func (*Return) String

func (ret *Return) String() string

Jump to

Keyboard shortcuts

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