package module
Version: v0.2.8-dev Latest Latest

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

Go to latest
Published: Sep 12, 2022 License: MIT Imports: 10 Imported by: 0






View Source
const (
	ImportMarkerName     = "import"
	DeprecatedMarkerName = "deprecated"
	OverrideMarkerName   = "override"

Reserved markers

View Source
const (
	EOF = -(iota + 1)
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
	AllLevels   = PackageLevel | TypeLevel | MethodLevel | FieldLevel | FunctionLevel

Combined levels

View Source
const (
	ValueArgument = "Value"

Argument names

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


This section is empty.


func IsDecimal

func IsDecimal(character rune) bool

func IsIdentifier

func IsIdentifier(character rune, index int) bool

func IsLower

func IsLower(s string) bool

func IsReservedMarker

func IsReservedMarker(marker string) bool

func IsUpper

func IsUpper(s string) 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

func UpperCamelCase

func UpperCamelCase(str string) string


type AliasMap

type AliasMap map[string]ImportMarker

type Argument

type Argument struct {
	Name       string
	TypeInfo   ArgumentTypeInfo
	Required   bool
	Deprecated bool
	Default    any

func ExtractArgument

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

type ArgumentType

type ArgumentType int
const (
	InvalidType ArgumentType = iota

func (ArgumentType) String

func (argumentType ArgumentType) String() string

type ArgumentTypeInfo

type ArgumentTypeInfo struct {
	ActualType ArgumentType
	IsPointer  bool
	ItemType   *ArgumentTypeInfo
	Enum       map[string]any

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 {

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
	Package     string
	TargetLevel TargetLevel
	Repeatable  bool
	Deprecated  bool
	Output      Output

func MakeDefinition

func MakeDefinition(name, pkg string, level TargetLevel, output any) (*Definition, error)

func (*Definition) Parse

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

TODO fix parse method implementation

type DefinitionMap

type DefinitionMap map[string]*Definition

type DeprecatedMarker

type DeprecatedMarker struct {
	Value string `parameter:"Value"`

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 `parameter:"Value" required:"true"`
	Alias string `parameter:"Alias" required:"false"`
	Pkg   string `parameter:"Pkg" required:"true"`

func (ImportMarker) PkgId

func (m ImportMarker) PkgId() string

func (ImportMarker) PkgVersion

func (m ImportMarker) PkgVersion() string

func (ImportMarker) Validate

func (m ImportMarker) Validate() error

type Marker

type Marker struct {
	Value       string `parameter:"Value" required:"true"`
	Description string `parameter:"Description" required:"true"`
	Repeatable  bool   `parameter:"Repeatable" required:"false"`
	SyntaxFree  bool   `parameter:"SyntaxFree" required:"false"`

type MarkerValues

type MarkerValues map[string][]any

func (MarkerValues) AllMarkers

func (markerValues MarkerValues) AllMarkers(name string) []any

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

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 OverrideMarker

type OverrideMarker struct {
	Value string `parameter:"Value"`

type Parameter

type Parameter struct {
	Value       string `parameter:"Value" required:"true"`
	Description string `parameter:"Description" required:"true"`
	Required    bool   `parameter:"Required" required:"false"`
	Deprecated  bool   `parameter:"Deprecated" required:"false"`
	Default     any    `parameter:"Default" required:"false"`

type ParameterEnum

type ParameterEnum struct {
	Value string `parameter:"Value" required:"true"`
	Name  string `parameter:"Name" required:"true"`

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, pkg string, targetLevel TargetLevel) (*Definition, bool)

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

func (*Registry) Register

func (registry *Registry) Register(name, pkg string, level TargetLevel, output any) 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.
	// InterfaceTypeLevel indicates that a marker is associated with an interface type.
	// FieldLevel indicates that a marker is associated with a struct field.
	// FunctionLevel indicates that a marker is associated with a function.
	// StructMethodLevel indicates that a marker is associated with a struct method.
	// InterfaceMethodLevel indicates that a marker is associated with an interface method.

func FindTargetLevelFromNode

func FindTargetLevelFromNode(node ast.Node) TargetLevel

type Validate

type Validate interface {
	Validate() error


Path Synopsis

Jump to

Keyboard shortcuts

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