Skip to content

Commit

Permalink
Merge branch 'master' of github.com:awalterschulze/gographviz
Browse files Browse the repository at this point in the history
  • Loading branch information
awalterschulze committed May 22, 2019
2 parents ea3b73d + 9c36406 commit fa59802
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ script:
language: go

go:
- 1.8
- 1.x
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ go get github.com/awalterschulze/gographviz
- [gorgonia](https://github.com/chewxy/gorgonia) - A Library that helps facilitate machine learning in Go
- [imagemonkey](https://imagemonkey.io/graph?editor=true) - Let's create our own image dataset
- [depviz](https://github.com/moul/depviz) - GitHub dependency visualizer (auto-roadmap)
- [kustomize-graph](https://github.com/jpreese/kustomize-graph) - A tool to visualize Kustomize dependencies

### Mentions ###

Expand Down
25 changes: 18 additions & 7 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import (
"math/rand"
"sort"
"strings"
"sync"

"github.com/awalterschulze/gographviz/internal/token"
)

var (
r = rand.New(rand.NewSource(1234))
r = rand.New(rand.NewSource(1234))
randLock sync.Mutex
)

type Visitor interface {
Expand Down Expand Up @@ -183,19 +185,28 @@ type SubGraph struct {
StmtList StmtList
}

func NewSubGraph(id, l Attrib) (*SubGraph, error) {
g := &SubGraph{ID: ID(fmt.Sprintf("anon%d", r.Int63()))}
if id != nil {
if len(id.(ID)) > 0 {
g.ID = id.(ID)
}
func NewSubGraph(maybeId, l Attrib) (*SubGraph, error) {
g := &SubGraph{}
if id, ok := maybeId.(ID); maybeId == nil || (ok && len(id) == 0) {
g.ID = ID(fmt.Sprintf("anon%d", randInt63()))
} else if ok && (len(id) > 0) {
g.ID = id
} else {
return nil, fmt.Errorf("expected maybeId.(ID) got=%v", maybeId)
}
if l != nil {
g.StmtList = l.(StmtList)
}
return g, nil
}

func randInt63() int64 {
randLock.Lock()
result := r.Int63()
randLock.Unlock()
return result
}

func (this *SubGraph) GetID() ID {
return this.ID
}
Expand Down

0 comments on commit fa59802

Please sign in to comment.