Skip to content

Commit

Permalink
Improve rule index pretty printing
Browse files Browse the repository at this point in the history
Signed-off-by: Torin Sandall <[email protected]>
  • Loading branch information
tsandall committed Jun 26, 2018
1 parent fc8e145 commit f27bf24
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions ast/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,38 @@ type trieNode struct {
rules []*ruleNode
}

func (node *trieNode) String() string {
var flags []string
flags = append(flags, fmt.Sprintf("self:%p", node))
if len(node.ref) > 0 {
flags = append(flags, node.ref.String())
}
if node.next != nil {
flags = append(flags, fmt.Sprintf("next:%p", node.next))
}
if node.any != nil {
flags = append(flags, fmt.Sprintf("any:%p", node.any))
}
if node.undefined != nil {
flags = append(flags, fmt.Sprintf("undefined:%p", node.undefined))
}
if node.array != nil {
flags = append(flags, fmt.Sprintf("array:%p", node.array))
}
if len(node.scalars) > 0 {
buf := []string{}
for k, v := range node.scalars {
buf = append(buf, fmt.Sprintf("scalar(%v):%p", k, v))
}
sort.Strings(buf)
flags = append(flags, strings.Join(buf, " "))
}
if len(node.rules) > 0 {
flags = append(flags, fmt.Sprintf("%d rule(s)", len(node.rules)))
}
return strings.Join(flags, " ")
}

type ruleNode struct {
prio [2]int
rule *Rule
Expand All @@ -322,10 +354,6 @@ func (node *trieNode) Do(walker trieWalker) {
if next == nil {
return
}
if node.next != nil {
node.next.Do(next)
return
}
if node.any != nil {
node.any.Do(next)
}
Expand All @@ -338,6 +366,9 @@ func (node *trieNode) Do(walker trieWalker) {
if node.array != nil {
node.array.Do(next)
}
if node.next != nil {
node.next.Do(next)
}
}

func (node *trieNode) Insert(ref Ref, value Value) *trieNode {
Expand Down

0 comments on commit f27bf24

Please sign in to comment.