codeparser

package
v0.0.0-...-25bcbb4 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FuncTypeText        = "Text"
	FuncTypeBlock       = "Block"
	FuncTypePlural      = "Plural"
	FuncTypePluralBlock = "PluralBlock"
)

Variables

View Source
var (
	ErrSource          = errors.New("source code contains errors")
	ErrSourceTextEmpty = errors.New("text empty")
	ErrSourceArgType   = errors.New(
		"non-literal argument (only string literals and constants are supported)",
	)
	ErrMissingPluralForm     = errors.New("missing required plural form")
	ErrUnsupportedPluralForm = errors.New(
		"plural form not supported by source language",
	)
	ErrMissingQuantityPlaceholder = errors.New(
		"missing quantity placeholder \"%d\" in template",
	)
	ErrTooManyQuantityPlaceholders = errors.New(
		"plural template strings are expected to " +
			`have only one quantity placeholder "%d"`,
	)
	ErrWrongQuantityArgType = errors.New(
		"passing wrong type to quantity argument",
	)
	ErrWrongPlaceholderVerb = errors.New(
		"wrong placeholder verb, use a numeric placeholder",
	)
	ErrUnsupportedLocale = errors.New("unsupported locale")
)
View Source
var ErrSyntax = errors.New("syntax error")

Functions

func MsgFromGettextMessage

func MsgFromGettextMessage(
	pluralForms cldr.PluralForms, msg Msg, meta MsgMeta,
) gettext.Message

func Parse

func Parse(
	pathPattern, bundlePkg string,
	locale language.Tag, trimpath, quiet, verbose bool,
) (
	collection *Collection, bundle *Bundle, stats *Statistics,
	srcErrs []ErrorSrc, err error,
)

Types

type Bundle

type Bundle struct {
	Catalogs map[language.Tag]POFile
}

func ParseBundle

func ParseBundle(pkg *packages.Package, collection *Collection) (*Bundle, error)

type Collection

type Collection struct {
	GeneratorVersion int
	Locale           language.Tag
	// TODO: consider turning this into map[string]MsgWithMeta for faster hash lookups
	// such that no new map needs to be created and copied over during catalog updates.
	Messages map[Msg]MsgMeta
}

Collection is a collection of messages gathered from the

func (*Collection) MakePO

func (c *Collection) MakePO(headTxt []string) gettext.FilePO

func (*Collection) Ordered

func (c *Collection) Ordered() iter.Seq2[Msg, MsgMeta]

Ordered returns an iterator over all messages ordered by hash.

type ErrorSrc

type ErrorSrc struct {
	token.Position
	Err error
}

type Msg

type Msg struct {
	Hash        string
	Description string
	Zero        string
	One         string
	Two         string
	Few         string
	Many        string
	Other       string
	FuncType    string
}

type MsgMeta

type MsgMeta struct {
	Pos []token.Position
}

type POFile

type POFile struct {
	Path string
	gettext.FilePO
}

type Statistics

type Statistics struct {
	TextTotal        atomic.Int64
	BlockTotal       atomic.Int64
	PluralTotal      atomic.Int64
	PluralBlockTotal atomic.Int64
	Merges           atomic.Int64
	FilesTraversed   atomic.Int64
}

Jump to

Keyboard shortcuts

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