parser

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: MIT Imports: 13 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 FieldSearch added in v0.2.1

type FieldSearch struct {

	// The import of the field (used for the cache).
	Import string

	// The package name of the field.
	Package string

	// The name of the field.
	Name string

	// The actual typename of the field (i.e `DomainUser` in `User DomainUser`).
	Definition string

	// The parent of the field the FieldSearch will find.
	// In the context of the program, a top-level field with no parent is a TypeField.
	Parent *models.Field

	// The file that holds the type declaration for the field being searched.
	DecFile *ast.File

	// The options that pertain to a field (and its subfields).
	Options []Option

	// The current depth-level of the FieldSearch.
	Depth int

	// The maximum allowed depth-level of the FieldSearch.
	MaxDepth int
	// contains filtered or unexported fields
}

FieldSearch represents a search that uses Abstract Syntax Tree analysis to find the fields of a typefield.

type Locater added in v0.2.1

type Locater struct {
	SetupFile  *ast.File
	Package    string
	Definition string
}

Locater represents the parameters for locating a Type Declaration.

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 parser options contain options located in the entire setup file.
	Options OptionMap

	// The fileset of the parser.
	Fileset *token.FileSet

	// The setup file as an Abstract Syntax Tree.
	SetupFile *ast.File

	// The ast.Node of the `type Copygen Interface`.
	Copygen *ast.InterfaceType

	// The last package to be loaded by a Locater.
	LastLocated *packages.Package

	// The setup filepath.
	Setpath string

	// The option-comments parsed in the OptionMap.
	Comments []*ast.Comment
	// contains filtered or unexported fields
}

Parser represents a parser that parses Abstract Syntax Tree data into models.

func (*Parser) SearchForField added in v0.2.1

func (p *Parser) SearchForField(fs *FieldSearch) (*models.Field, error)

SearchForField executes a field search by locating a field's type declaration, then its subfields.

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.

type TypeDeclaration added in v0.2.1

type TypeDeclaration struct {
	// The package of the type declaration.
	Package *packages.Package

	// The file the type declaration is located in.
	File *ast.File

	// The *ast.TypeSpec of the type declaration.
	TypeSpec *ast.TypeSpec
}

TypeDeclaration represents the information related to a type's declaration.

Jump to

Keyboard shortcuts

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