Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
new include
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Dec 13, 2019
1 parent 5497054 commit 6c1b23a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
31 changes: 31 additions & 0 deletions parser/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"go/token"
"os"
"path/filepath"

"github.com/markbates/pkger/here"
)

var _ Decl = IncludeDecl{}
Expand All @@ -15,6 +18,34 @@ type IncludeDecl struct {
value string
}

func NewInclude(her here.Info, inc string) (IncludeDecl, error) {
var id IncludeDecl
pt, err := her.Parse(inc)
if err != nil {
return id, err
}

if pt.Pkg != her.ImportPath {
her, err = here.Package(pt.Pkg)
if err != nil {
return id, err
}
}

abs := filepath.Join(her.Module.Dir, pt.Name)

f := &File{
Abs: abs,
Path: pt,
Here: her,
}

return IncludeDecl{
value: inc,
file: f,
}, nil
}

func (d IncludeDecl) String() string {
return fmt.Sprintf("pkger.Include(%q)", d.value)
}
Expand Down
22 changes: 2 additions & 20 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,30 +226,12 @@ func (p *Parser) parse() error {

func (p *Parser) parseIncludes() error {
for _, i := range p.includes {
pt, err := p.Info.Parse(i)
d, err := NewInclude(p.Info, i)
if err != nil {
return err
}

her := p.Info
if pt.Pkg != her.ImportPath {
her, err = here.Package(pt.Pkg)
if err != nil {
return err
}
}

abs := filepath.Join(her.Module.Dir, pt.Name)

f := &File{
Abs: abs,
Path: pt,
Here: her,
}
p.decls["Include"] = append(p.decls["Include"], IncludeDecl{
value: i,
file: f,
})
p.decls["Include"] = append(p.decls["Include"], d)
}
return nil
}

0 comments on commit 6c1b23a

Please sign in to comment.