parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 14 Imported by: 2

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

func Parse

func Parse(gen *models.Generator) error

Parse parses a generator's setup file.

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 OptionMap

type OptionMap map[string]Option

OptionMap represents a map of comment-option relations (map[comment]Option).

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.

func (*Parser) Traverse

func (p *Parser) Traverse(gen *models.Generator) error

Traverse parses the generator setup file's Abstract Syntax Tree into function and field data. Assigns values to the parser's convert options.

Jump to

Keyboard shortcuts

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