parser

package
v2.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultIgnoredFolders = []string{".", "_", "vendor", "node_modules", "_fixtures", "testdata"}

Functions

func FromArgs

func FromArgs(args []string, fn func(Boxes) error) error

FromArgs is useful when writing packr store-cmd binaries.

package main

import (
	"log"
	"os"

	"github.com/gobuffalo/packr/v2/jam/parser"
	"github.com/markbates/s3packr/s3packr"
)

func main() {
	err := parser.FromArgs(os.Args[1:], func(boxes parser.Boxes) error {
		for _, box := range boxes {
			s3 := s3packr.New(box)
			if err := s3.Pack(box); err != nil {
				return err
			}
		}
		return nil
	})

	if err != nil {
		log.Fatal(err)
	}
}

func IsProspect

func IsProspect(path string, ignore ...string) (status bool)

Types

type Box

type Box struct {
	Name       string // name of the box
	Path       string // relative path of folder NewBox("./templates")
	AbsPath    string // absolute path of Path
	Package    string // the package name the box was found in
	PWD        string // the PWD when the parser was run
	PackageDir string // the absolute path of the package where the box was found
}

Box found while parsing a file

func NewBox

func NewBox(name string, path string) *Box

NewBox stub from the name and the path provided

func (Box) String

func (b Box) String() string

String - json returned

type Boxes

type Boxes []*Box

type File

type File struct {
	io.Reader
	Path    string
	AbsPath string
}

File that is to be parsed

func NewFile

func NewFile(path string, r io.Reader) *File

NewFile takes the name of the file you want to write to and a reader to reader from

func (File) Name

func (f File) Name() string

Name of the file "app.go"

func (*File) String

func (f *File) String() string

String returns the contents of the reader

func (*File) Write

func (s *File) Write(p []byte) (int, error)

type ParsedFile

type ParsedFile struct {
	File    packd.SimpleFile
	FileSet *token.FileSet
	Ast     *ast.File
	Lines   []string
}

ParsedFile ...

func ParseFile

func ParseFile(gf packd.SimpleFile) (ParsedFile, error)

ParseFile ...

func ParseFileMode

func ParseFileMode(gf packd.SimpleFile, mode parser.Mode) (ParsedFile, error)

ParseFileMode ...

type Parser

type Parser struct {
	Prospects     []*File // a list of files to check for boxes
	IgnoreImports bool
}

Parser to find boxes

func New

func New(prospects ...*File) *Parser

New Parser from a list of File

func NewFromRoots

func NewFromRoots(roots []string, opts *RootsOptions) (*Parser, error)

NewFromRoots scans the file roots provided and returns a new Parser containing the prospects

func (*Parser) Run

func (p *Parser) Run() (Boxes, error)

Run the parser and run any boxes found

type RootsOptions

type RootsOptions struct {
	IgnoreImports bool
	Ignores       []string
}

func (RootsOptions) String

func (r RootsOptions) String() string

type Visitor

type Visitor struct {
	File    packd.SimpleFile
	Package string
	// contains filtered or unexported fields
}

func NewVisitor

func NewVisitor(f *File) *Visitor

func (*Visitor) Run

func (v *Visitor) Run() (Boxes, error)

func (*Visitor) Visit

func (v *Visitor) Visit(node ast.Node) ast.Visitor

Directories

Path Synopsis
_fixtures

Jump to

Keyboard shortcuts

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