marker

package module
v0.2.0-dev Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: MIT Imports: 12 Imported by: 2

README

marker

Documentation

Index

Constants

View Source
const (
	// TypeLevel indicates that a marker is associated with any type.
	TypeLevel = StructTypeLevel | InterfaceTypeLevel
	// MethodLevel indicates that a marker is associated with a struct method or an interface method.
	MethodLevel = StructMethodLevel | InterfaceMethodLevel
)

Combined levels

View Source
const (
	EOF = -(iota + 1)
	Identifier
	Integer
	String
)
View Source
const (
	ImportMarkerName = "import"
)

Reserved markers

View Source
const (
	ValueArgument = "Value"
)

Argument names

View Source
const Whitespace = 1<<'\t' | 1<<'\r' | 1<<' '

Variables

This section is empty.

Functions

func EachFile

func EachFile(collector *Collector, pkgs []*Package, callback FileCallback)

func GoModDir

func GoModDir() (string, error)

GoModDir returns the directory of go.mod file.

func IsDecimal

func IsDecimal(character rune) bool

func IsIdentifier

func IsIdentifier(character rune, index int) bool

func LowerCamelCase

func LowerCamelCase(str string) string

func NewError

func NewError(err error, fileName string, position Position) error

func NewErrorList

func NewErrorList(errors []error) error

Types

type AliasMap

type AliasMap map[string]string

type AnonymousStructType

type AnonymousStructType struct {
	Markers MarkerValues
	Fields  []Field
}

func (AnonymousStructType) Kind

func (typ AnonymousStructType) Kind() Kind

type AnyKindType

type AnyKindType struct {
}

func (AnyKindType) Kind

func (typ AnyKindType) Kind() Kind

type Argument

type Argument struct {
	Name           string
	TypeInfo       ArgumentTypeInfo
	Pointer        bool
	Required       bool
	SyntaxFree     bool
	UseValueSyntax bool
}

func ExtractArgument

func ExtractArgument(structField reflect.StructField) (Argument, error)

type ArgumentType

type ArgumentType int
const (
	InvalidType ArgumentType = iota
	RawType
	AnyType
	BoolType
	IntegerType
	StringType
	SliceType
	MapType
)

func (ArgumentType) String

func (argumentType ArgumentType) String() string

type ArgumentTypeInfo

type ArgumentTypeInfo struct {
	ActualType ArgumentType
	ItemType   *ArgumentTypeInfo
}

func GetArgumentTypeInfo

func GetArgumentTypeInfo(typ reflect.Type) (ArgumentTypeInfo, error)

func (ArgumentTypeInfo) Parse

func (typeInfo ArgumentTypeInfo) Parse(scanner *Scanner, out reflect.Value) error

type ArrayType

type ArrayType struct {
	ItemType Type
}

func (ArrayType) Kind

func (typ ArrayType) Kind() Kind

type ChanDirection

type ChanDirection int
const (
	SEND ChanDirection = 1 << iota
	RECEIVE
)

type ChanType

type ChanType struct {
	Typ       Type
	Direction ChanDirection
}

func (ChanType) Kind

func (typ ChanType) Kind() Kind

type Collector

type Collector struct {
	*Registry
}

func NewCollector

func NewCollector(registry *Registry) *Collector

func (*Collector) Collect

func (collector *Collector) Collect(pkg *Package) (map[ast.Node]MarkerValues, error)

type Definition

type Definition struct {
	Name   string
	Level  TargetLevel
	Output Output
	PkgId  string
}

func MakeDefinition

func MakeDefinition(name string, pkgId string, level TargetLevel, output interface{}) (*Definition, error)

func (*Definition) Parse

func (definition *Definition) Parse(marker string) (interface{}, error)

type DictionaryType

type DictionaryType struct {
	KeyType   Type
	ValueType Type
}

func (DictionaryType) Kind

func (typ DictionaryType) Kind() Kind

type Error

type Error struct {
	FileName string
	Position Position
	// contains filtered or unexported fields
}

type ErrorList

type ErrorList []error

func (ErrorList) Error

func (errorList ErrorList) Error() string

type Field

type Field struct {
	Name     string
	Position Position
	Markers  MarkerValues
	Type     Type
	RawFile  *ast.File
	RawField *ast.Field
}

type File

type File struct {
	Name          string
	FullPath      string
	Package       PackageInfo
	Imports       []Import
	Markers       MarkerValues
	ImportMarkers []MarkerValues

	FunctionTypes    []FunctionType
	StructTypes      []StructType
	InterfaceTypes   []InterfaceType
	UserDefinedTypes []UserDefinedType
	RawFile          *ast.File
}

type FileCallback

type FileCallback func(file *File, err error)

type FunctionType

type FunctionType struct {
	Name         string
	Position     Position
	Markers      MarkerValues
	Parameters   []TypeInfo
	ReturnValues []TypeInfo
	File         *File
	RawFile      *ast.File
	RawFuncDecl  *ast.FuncDecl
	RawFuncType  *ast.FuncType
}

func (FunctionType) Kind

func (function FunctionType) Kind() Kind

type Import

type Import struct {
	Name          string
	Path          string
	Position      Position
	RawImportSpec *ast.ImportSpec
}

type ImportError

type ImportError struct {
	Marker string
}

func (ImportError) Error

func (err ImportError) Error() string

type ImportMarker

type ImportMarker struct {
	Value string `marker:"Value,useValueSyntax"`
	Alias string `marker:"Alias,optional"`
	Pkg   string `marker:"Pkg"`
}

func (ImportMarker) GetCommand

func (m ImportMarker) GetCommand() string

func (ImportMarker) GetPkgId

func (m ImportMarker) GetPkgId() string

func (ImportMarker) GetPkgVersion

func (m ImportMarker) GetPkgVersion() string

func (ImportMarker) Validate

func (m ImportMarker) Validate() error

type InterfaceType

type InterfaceType struct {
	Name        string
	Position    Position
	Markers     MarkerValues
	Methods     []Method
	File        *File
	RawFile     *ast.File
	RawGenDecl  *ast.GenDecl
	RawTypeSpec *ast.TypeSpec
}

func (InterfaceType) Kind

func (typ InterfaceType) Kind() Kind

type Kind

type Kind int
const (
	AnyKind Kind = iota
	Object
	Array
	Chan
	Map
	Ptr
	Variadic
	Function
	Interface
	Struct
	UserDefined
)

type Marker

type Marker interface {
	Validate() error
}

type MarkerValues

type MarkerValues map[string][]interface{}

func (MarkerValues) Get

func (markerValues MarkerValues) Get(name string) interface{}

type Method

type Method struct {
	Name         string
	Position     Position
	Markers      MarkerValues
	Receiver     *TypeInfo
	Parameters   []TypeInfo
	ReturnValues []TypeInfo
	File         *File
	RawFile      *ast.File
	RawField     *ast.Field
	RawFuncDecl  *ast.FuncDecl
	RawFuncType  *ast.FuncType
}

type ModuleInfo

type ModuleInfo struct {
	Path      string
	Version   string
	Main      bool
	Indirect  bool
	Dir       string
	GoMod     string
	GoVersion string
	RawModule *packages.Module
}

type ObjectType

type ObjectType struct {
	ImportName string
	Name       string
}

func (ObjectType) Kind

func (typ ObjectType) Kind() Kind

type Output

type Output struct {
	Type              reflect.Type
	IsAnonymous       bool
	SyntaxFree        bool
	UseValueSyntax    bool
	AnonymousTypeInfo ArgumentTypeInfo
	Fields            map[string]Argument
	FieldNames        map[string]string
}

type Package

type Package struct {
	*packages.Package
	// contains filtered or unexported fields
}

func LoadPackages

func LoadPackages(patterns ...string) ([]*Package, error)

LoadPackages loads and returns the Go packages by the given patterns.

func LoadPackagesWithConfig

func LoadPackagesWithConfig(config *packages.Config, patterns ...string) ([]*Package, error)

LoadPackagesWithConfig functions like LoadPackages. Except that it allows passing a custom config.

type PackageInfo

type PackageInfo struct {
	Id         string
	Name       string
	Path       string
	ModuleInfo *ModuleInfo
	RawPackage *packages.Package
}

type ParserError

type ParserError struct {
	FileName string
	Position Position
	// contains filtered or unexported fields
}

type PointerType

type PointerType struct {
	Typ Type
}

func (PointerType) Kind

func (typ PointerType) Kind() Kind

type Position

type Position struct {
	Line   int
	Column int
}

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry keeps the registered marker definitions.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns a new registry to register the markers.

func (*Registry) Lookup

func (registry *Registry) Lookup(name string, pkgId string) *Definition

Lookup fetches the definition corresponding to the given name and pkgId.

func (*Registry) Register

func (registry *Registry) Register(name string, pkgId string, level TargetLevel, output interface{}, useValueSyntax ...bool) error

Register registers a new marker with the given name, target level, and output type.

func (*Registry) RegisterWithDefinition

func (registry *Registry) RegisterWithDefinition(definition *Definition) error

RegisterWithDefinition registers a new marker with the given definition.

type Scanner

type Scanner struct {
	ErrorCallback func(scanner *Scanner, message string)
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(source string) *Scanner

func (*Scanner) AddError

func (scanner *Scanner) AddError(message string)

func (*Scanner) ErrorCount

func (scanner *Scanner) ErrorCount() int

func (*Scanner) Expect

func (scanner *Scanner) Expect(expected rune, description string) bool

func (*Scanner) Next

func (scanner *Scanner) Next() rune

func (*Scanner) Peek

func (scanner *Scanner) Peek() rune

func (*Scanner) Reset

func (scanner *Scanner) Reset()

func (*Scanner) Scan

func (scanner *Scanner) Scan() rune

func (*Scanner) ScanIdentifier

func (scanner *Scanner) ScanIdentifier() rune

func (*Scanner) ScanNumber

func (scanner *Scanner) ScanNumber() rune

func (*Scanner) ScanString

func (scanner *Scanner) ScanString(quote rune) (len int)

func (*Scanner) SearchIndex

func (scanner *Scanner) SearchIndex() int

func (*Scanner) SetSearchIndex

func (scanner *Scanner) SetSearchIndex(searchIndex int)

func (*Scanner) SkipWhitespaces

func (scanner *Scanner) SkipWhitespaces() rune

func (*Scanner) SourceLength

func (scanner *Scanner) SourceLength() int

func (*Scanner) Token

func (scanner *Scanner) Token() string

type ScannerError

type ScannerError struct {
	Message string
}

func (ScannerError) Error

func (err ScannerError) Error() string

type StructType

type StructType struct {
	Name        string
	Position    Position
	Markers     MarkerValues
	Fields      []Field
	Methods     []Method
	File        *File
	RawFile     *ast.File
	RawGenDecl  *ast.GenDecl
	RawTypeSpec *ast.TypeSpec
}

func (StructType) Kind

func (typ StructType) Kind() Kind

type TargetLevel

type TargetLevel int

TargetLevel describes which kind of nodes a given marker are associated with.

const (
	// PackageLevel indicates that a marker is associated with a package.
	PackageLevel TargetLevel = 1 << iota
	// ImportLevel indicates that a marker is associated with an import block.
	ImportLevel
	// StructTypeLevel indicates that a marker is associated with a struct type.
	StructTypeLevel
	// InterfaceTypeLevel indicates that a marker is associated with an interface type.
	InterfaceTypeLevel
	// FieldLevel indicates that a marker is associated with a struct field.
	FieldLevel
	// FunctionLevel indicates that a marker is associated with a function.
	FunctionLevel
	// StructMethodLevel indicates that a marker is associated with a struct method.
	StructMethodLevel
	// InterfaceMethodLevel indicates that a marker is associated with an interface method.
	InterfaceMethodLevel
)

type Type

type Type interface {
	Kind() Kind
}

type TypeInfo

type TypeInfo struct {
	Name     string
	Type     Type
	Markers  MarkerValues
	RawField *ast.Field
}

type UserDefinedType

type UserDefinedType struct {
	Name        string
	ActualType  Type
	Position    Position
	Markers     MarkerValues
	Methods     []Method
	File        *File
	RawFile     *ast.File
	RawGenDecl  *ast.GenDecl
	RawTypeSpec *ast.TypeSpec
}

func (UserDefinedType) Kind

func (typ UserDefinedType) Kind() Kind

type VariadicType

type VariadicType struct {
	ItemType Type
}

func (VariadicType) Kind

func (typ VariadicType) Kind() Kind

Directories

Path Synopsis
cmd
test
package1
This is a go document comment +marker:package-level This is a go document comment
This is a go document comment +marker:package-level This is a go document comment

Jump to

Keyboard shortcuts

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