marker

package module
v0.2.6-dev Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 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 (
	ImportMarkerName     = "import"
	DeprecatedMarkerName = "deprecated"
)

Reserved markers

View Source
const (
	EOF = -(iota + 1)
	Identifier
	IntegerValue
	StringValue
)
View Source
const (
	ValueArgument = "Value"
)

Argument names

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

Variables

This section is empty.

Functions

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]ImportMarker

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 Collector

type Collector struct {
	*Registry
}

func NewCollector

func NewCollector(registry *Registry) *Collector

func (*Collector) Collect

func (collector *Collector) Collect(pkg *packages.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 DeprecatedMarker

type DeprecatedMarker struct {
	Value string `marker:"Value,syntaxFree"`
}

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 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 Marker

type Marker interface {
	Validate() error
}

type MarkerValues

type MarkerValues map[string][]interface{}

func (MarkerValues) AllMarkers

func (markerValues MarkerValues) AllMarkers(name string) []interface{}

func (MarkerValues) Count

func (markerValues MarkerValues) Count() int

func (MarkerValues) CountByName

func (markerValues MarkerValues) CountByName(name string) int

func (MarkerValues) First

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

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 ParserError

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

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 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
	// 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
)

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