parse

package
v2.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: MIT Imports: 13 Imported by: 0

README

Parse

structure

Documentation

Overview

Package goparse provides tools to parse and process Go source files, extracting translations and handling various configurations.

Index

Constants

View Source
const (
	DefaultPackageName = "gotext"
	// WantedImport specifies the import path of the "gotext" library
	// that the parser is looking for in the Go files.
	WantedImport = `"github.com/leonelquinteros/gotext"`
)

Constants.

Variables

This section is empty.

Functions

func FromBytes

func FromBytes(b []byte, name string, opts ...Option) (*po.File, error)

func FromFile

func FromFile(f *os.File, opts ...Option) (*po.File, error)

func FromFiles

func FromFiles(files []*os.File, opts ...Option) (*po.File, error)

func FromPath

func FromPath(path string, opts ...Option) (*po.File, error)

func FromPaths

func FromPaths(paths []string, opts ...Option) (*po.File, error)

func FromReader

func FromReader(r io.Reader, name string, opts ...Option) (*po.File, error)

func FromString

func FromString(s, name string, opts ...Option) (*po.File, error)

Types

type Config

type Config struct {
	Exclude         []string
	ExtractAll      bool
	NoHeader        bool
	HeaderConfig    *po.HeaderConfig
	CustomHeader    *po.Header
	Logger          *log.Logger
	Verbose         bool
	CleanDuplicates bool
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig(opts ...Option) Config

func (*Config) ApplyOptions

func (c *Config) ApplyOptions(opts ...Option)

Overwrite the configuration with the options provided, saving the previous state so that it can be restored later with Config.RestoreLastCfg if desired.

func (*Config) RestoreLastCfg

func (c *Config) RestoreLastCfg()

Restores the configuration state prior to the last Config.ApplyOptions if it exists, otherwise it does nothing.

type File

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

File represents the parser of an individual go file, I do it this way to keep track of the location and name of each file.

It does not generate Header, it only extracts the entries according to the configuration.

func NewFile

func NewFile(b io.Reader, name string, config *Config) (*File, error)

NewFile creates a new File instance from raw byte data.

func NewFileFromBytes

func NewFileFromBytes(b []byte, name string, config *Config) (*File, error)

func NewFileFromPath

func NewFileFromPath(path string, config *Config) (*File, error)

NewFileFromPath creates a new File instance by reading content from a file on disk.

func (*File) Entries

func (f *File) Entries() po.Entries

Entries returns all translations found in the file.

func (*File) Error

func (f *File) Error() error

func (*File) Errors

func (f *File) Errors() []error

func (*File) Reset

func (f *File) Reset(d io.Reader, name string, config *Config) error

type Option

type Option func(c *Config)

func WithCleanDuplicates

func WithCleanDuplicates(cl bool) Option

func WithConfig

func WithConfig(cfg Config) Option

func WithCustomHeader added in v2.6.0

func WithCustomHeader(h *po.Header) Option

func WithExclude

func WithExclude(exclude ...string) Option

func WithExtractAll

func WithExtractAll(e bool) Option

func WithHeaderConfig

func WithHeaderConfig(h *po.HeaderConfig) Option

func WithLogger

func WithLogger(l *log.Logger) Option

func WithNoHeader

func WithNoHeader(h bool) Option

func WithVerbose

func WithVerbose(v bool) Option

type Parser

type Parser struct {
	Config Config // Configuration settings for parsing.
	// contains filtered or unexported fields
}

func NewParser

func NewParser(path string, options ...Option) (*Parser, error)

NewParser initializes a new Parser for a given directory path and configuration.

func NewParserFromBytes

func NewParserFromBytes(
	b []byte,
	name string,
	options ...Option,
) (*Parser, error)

NewParserFromBytes creates a Parser from raw byte data after validating the configuration.

func NewParserFromFile

func NewParserFromFile(file *os.File, options ...Option) (*Parser, error)

NewParserFromFile creates a Parser from an os.File instance.

func NewParserFromFiles

func NewParserFromFiles(files []*os.File, options ...Option) (*Parser, error)

func NewParserFromPaths

func NewParserFromPaths(files []string, options ...Option) (*Parser, error)

NewParserFromPaths initializes a Parser from a list of file paths.

func NewParserFromReader

func NewParserFromReader(
	r io.Reader,
	name string,
	options ...Option,
) (*Parser, error)

NewParserFromReader creates a Parser from an io.Reader, such as a file or memory buffer.

func NewParserFromString

func NewParserFromString(
	s string,
	name string,
	options ...Option,
) (*Parser, error)

func (Parser) Error

func (p Parser) Error() error

func (Parser) Errors

func (p Parser) Errors() []error

func (Parser) Files

func (p Parser) Files() []*File

Files returns the list of files associated with the Parser.

func (*Parser) Parse

func (p *Parser) Parse() (file *po.File)

Parse processes all files associated with the Parser and extracts translations.

func (*Parser) ParseWithOptions

func (p *Parser) ParseWithOptions(options ...Option) *po.File

Jump to

Keyboard shortcuts

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