genlang

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package genlang provides parsing for godoc comment annotations

Index

Constants

View Source
const (
	// ArgsRequired requires a keyword to have an accompanying argument.
	ArgsRequired keywordFlag = 1 << iota
	// DualArgsRequired requires a keyword to have two comma-separated arguments.
	DualArgsRequired
	// NoArgs requires a keyword to be called without arguments.
	NoArgs
	// StrictSingleArgs limits the number of comma-separated arguments to one
	StrictSingleArgs
	// Exclusive limits the keyword to a single use per instance of field or struct.
	Exclusive
)

If a flag's requirement is violated the scanner will return an error.

View Source
const (
	ScanStruct scanMode = iota
	ScanField
	ScanNamedType
)

Scanning modes configure the scanner for different generation/parser types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Args

type Args struct {
	Arg1 string
	Arg2 *string
}

Args contains the raw string data for an argument, and possibly a second argument separated by a comma.

type KeywordOpts

type KeywordOpts map[scanMode]keywordFlag

KeywordOpts is used to configure the flags for keywords based on the scan mode (field or struct).

type MultiMap

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

MultiMap maps a singular key (string) to multiple values ([]Args), with convenience methods for accessing the values.

func (MultiMap) Get

func (m MultiMap) Get(s string) []Args

Get returns the slice of Args for a given key.

func (MultiMap) GetDualArgs

func (m MultiMap) GetDualArgs(s string) iter.Seq2[string, *string]

GetDualArgs returns an iterator over the first and second argument in each instance of Args for a given key.

func (MultiMap) GetOne

func (m MultiMap) GetOne(s string) Args

GetOne returns the first instance of Args for a given key. The caller should check that Args *do* exist for the given key before calling.

func (MultiMap) GetSingleArgs

func (m MultiMap) GetSingleArgs(s string) iter.Seq[string]

GetSingleArgs returns an iterator over the first argument in each instance of Args for a given key.

func (MultiMap) Has

func (m MultiMap) Has(s string) bool

Has returns true if the MultiMap contains one or more Args instances for a given key.

func (MultiMap) Iter added in v0.4.0

func (m MultiMap) Iter(s string) iter.Seq[Args]

Iter returns an iterator over the Args for a given key.

func (MultiMap) Keys

func (m MultiMap) Keys() iter.Seq[string]

Keys returns an iterator over all of the keys in the MultiMap.

type NamedTypeResults added in v0.2.3

type NamedTypeResults struct {
	Named MultiMap
}

NamedTypeResults holds the MultiMap of keywords and arguments for a parser.NamedType

type Scanner

type Scanner interface {
	ScanStruct(*parser.Struct) (StructResults, error)
	ScanNamedType(*parser.NamedType) (NamedTypeResults, error)
}

Scanner provides methods for parsing godoc annotations on various types from the generation/parser package.

func NewScanner

func NewScanner(keywords map[string]KeywordOpts) Scanner

NewScanner constructs a Scanner with the given keywords and keyword options.

type StructResults added in v0.2.3

type StructResults struct {
	Struct MultiMap
	Fields []MultiMap
}

StructResults holds the MultiMaps of keywords and arguments for a parser.Struct and each of its fields.

Jump to

Keyboard shortcuts

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