Documentation
¶
Overview ¶
Package parser parses a setup file's functions, types, and fields using an Abstract Syntax Tree.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FieldSearchInfo ¶
type FieldSearchInfo struct {
// The typespec of the searcher that initiated the field search.
SearcherTypeSpec *ast.TypeSpec
// The files discovered during the search.
Files []*ast.File
// The file that holds the type declaration for the searcher.
DecFile *ast.File
// The types info for the search.
Info types.Info
// The current depth-level of the fieldSearch.
Depth int
// The maximum allowed depth-level of the fieldSearch.
MaxDepth int
}
FieldSearchInfo represents the info for a field search.
type FieldSearcher ¶
type FieldSearcher struct {
// The options that pertain to a field (and its subfields).
Options []Option
// The field that initiates the search.
Field *models.Field
// The current search information for the field searcher.
SearchInfo FieldSearchInfo
// contains filtered or unexported fields
}
FieldSearcher represents a searcher that uses Abstract Syntax Tree analysis to find fields of a type.
func (*FieldSearcher) SearchForTypeField ¶
func (fs *FieldSearcher) SearchForTypeField(setupfile *ast.File, setimport, setpkg, setname string) (*models.Field, error)
SearchForTypeField searches for an *ast.Field which is parsed into a (type) field model.
The field search process involves a FieldSearcher that sets up and executes a field search in order to load field data. In the context of the program, a top-level field with no parents is a TypeField. The original setup file (i.e setup.go) is used to locate a field's actual import and package. Then, the files that compose this package are searched for the declaration of the field containing its data and sub-fields.
type Option ¶
type Option struct {
// The compiled regex the option uses for its arguments (map[position]regex).
Regex map[int]*regexp.Regexp
// The values to assign to a type (function or field) if the option applies.
Value interface{}
// The category the option falls under.
// There are currently five: convert, depth, deepcopy, map, custom
Category string
}
Option represents an option applied to functions and fields.
type Parser ¶
type Parser struct {
// The fileset of the parser.
Fileset *token.FileSet
// The setup file as an Abstract Syntax Tree.
SetupFile *ast.File
// The option-comments parsed in the OptionMap.
Comments []*ast.Comment
// The ast.Node of the `type Copygen Interface`.
Copygen *ast.InterfaceType
// The imports discovered in the set up file (map[packagevar]importpath).
// In the context of the parser, packagevar refers to the the variable used
// to reference the package (alias) rather the package's actual name.
Imports map[string]string
// The parser options contain options located in the entire setup file.
Options OptionMap
// The setup filepath.
Setpath string
}
Parser represents a parser that parses Abstract Syntax Tree data into models.