This repository has been archived by the owner on Jun 25, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getting a parser from files now works
- Loading branch information
Showing
15 changed files
with
134 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package q | ||
|
||
import "github.com/gobuffalo/packr" | ||
|
||
func init() { | ||
packr.New("tom", "petty") | ||
packr.NewBox("./heartbreakers") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package q | ||
|
||
import "github.com/gobuffalo/packr" | ||
|
||
func init() { | ||
packr.New("aretha", "franklin") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
func main() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package parser | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"strings" | ||
) | ||
|
||
type Box struct { | ||
Name string | ||
Path string | ||
Package string | ||
PWD string | ||
PackageDir string | ||
} | ||
|
||
func (b Box) String() string { | ||
x, _ := json.Marshal(b) | ||
return string(x) | ||
} | ||
|
||
func NewBox(name string, path string) *Box { | ||
if len(name) == 0 { | ||
name = path | ||
} | ||
name = strings.Replace(name, "\"", "", -1) | ||
pwd, _ := os.Getwd() | ||
box := &Box{ | ||
Name: name, | ||
Path: path, | ||
PWD: pwd, | ||
} | ||
return box | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package parser | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/karrick/godirwalk" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type Parser struct { | ||
Prospects []*File | ||
} | ||
|
||
func (p *Parser) Run() ([]*Box, error) { | ||
var boxes []*Box | ||
for _, pros := range p.Prospects { | ||
fmt.Println("Parser: parsing", pros.Name()) | ||
v := NewVisitor(pros) | ||
pbr, err := v.Run() | ||
if err != nil { | ||
return boxes, errors.WithStack(err) | ||
} | ||
for _, b := range pbr { | ||
boxes = append(boxes, b) | ||
} | ||
} | ||
return boxes, nil | ||
} | ||
|
||
func New(prospects ...*File) *Parser { | ||
return &Parser{ | ||
Prospects: prospects, | ||
} | ||
} | ||
|
||
func NewFromRoots(roots []string, ignore ...string) (*Parser, error) { | ||
p := New() | ||
callback := func(path string, de *godirwalk.Dirent) error { | ||
if !IsProspect(path, ignore...) || de.IsDir() { | ||
return nil | ||
} | ||
b, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return errors.WithStack(err) | ||
} | ||
p.Prospects = append(p.Prospects, NewFile(path, bytes.NewReader(b))) | ||
return nil | ||
} | ||
opts := &godirwalk.Options{ | ||
FollowSymbolicLinks: true, | ||
Callback: callback, | ||
} | ||
for _, root := range roots { | ||
err := godirwalk.Walk(root, opts) | ||
if err != nil { | ||
return p, errors.WithStack(err) | ||
} | ||
} | ||
return p, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.