parser

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Name    string
	Comment string
	Type    string
	Tags    []tags.Tag
}

Field represents a field in a struct It contains the name of the field, the type and the tags This information are extracted from the file and will be used to generate the variables files

type File

type File struct {
	Path    FilePath
	Package string
	Structs []Struct
}

File represents a project file It contains the path of the file, the package name and the structs This information are extracted from the file and will be used to generate the variables files

type FilePath

type FilePath string

type Option

type Option struct {
	Key   string
	Value string
}

Option is a simple key, value pair

type Parser

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

func NewParser

func NewParser() *Parser

NewParser creates a new Parser

func (*Parser) ParseDir

func (p *Parser) ParseDir(path string, recursive bool) (map[FilePath]*File, error)

ParseDir parses a directory and returns a map of parsed File It extracts the package name, the structs, the fields and the tags from the files It will be used to generate the variables files

func (*Parser) ParseFile

func (p *Parser) ParseFile(filename string) (*File, error)

ParseFile parses a file and returns a File It extracts the package name, the structs, the fields and the tags from the file It will be used to generate the variables files

type Preprocessor

type Preprocessor struct {

	// Include is a boolean that indicates if the struct should be included or not
	// The default value is true
	Include bool

	// IncludeTags is a list of tags that should be included
	// The default value is nil
	IncludeTags []string

	// Exclude is a boolean that indicates if the struct should be excluded or not
	// The default value is false
	Exclude bool

	// ExcludeTags is a list of tags that should be excluded
	// The default value is nil
	ExcludeTags []string
	// contains filtered or unexported fields
}

Preprocessor is the preprocessor

The preprocessor parse the string and extract the options This options will be used to know if a struct should be included or not and to know which tags to include

#tagsvar:all -> include the struct and all the fields with all the tags (equivalent to #tagsvar)
#tagsvar:include -> include the struct and all the fields (equivalent to #tagsvar)
#tagsvar:include:all -> include the struct and all the fields with all the tags (equivalent to #tagsvar)
#tagsvar:include:json -> include the struct and all the fields with the json tag
#tagsvar:include:json,xml -> include the struct and all the fields with the json and xml tags

#tagsvar:exclude -> exclude the struct and all the fields
#tagsvar:exclude:all -> exclude the struct and all the fields with all the tags (equivalent to #tagsvar:exclude)
#tagsvar:exclude:json -> only exclude the fields with the json tag
#tagsvar:exclude:json,xml" -> only exclude the fields with the json and xml tags

Exclude is the default behavior, so if the preprocessor is not found in the comment, the struct will be excluded If the preprocessor is found and contains the include and exclude keywords, the exclude keyword will have the priority

func NewPreprocessor

func NewPreprocessor() *Preprocessor

NewPreprocessor returns a new preprocessor

func (*Preprocessor) DoProcess

func (p *Preprocessor) DoProcess() bool

DoProcess returns true if the struct should be included and false if the struct should be excluded

func (*Preprocessor) Parse

func (p *Preprocessor) Parse(s string)

Parse parses the string and extract the options

func (*Preprocessor) ShouldProcess

func (p *Preprocessor) ShouldProcess(tag string) bool

ShouldProcess returns true if the tag should be included and false if the tag should be excluded

type Struct

type Struct struct {
	Name    string
	Comment string
	Fields  []Field
	TagKeys []string
}

Struct represents a struct in a project file It contains the name of the struct and the fields This information are extracted from the file and will be used to generate the variables files

func (*Struct) ContainsTag

func (s *Struct) ContainsTag(key string) bool

Jump to

Keyboard shortcuts

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