Merge pull request #2150 from davesisson/trees

Fix issue with tree finding when the underlying slice needs to be resized.
This commit is contained in:
Terence Parr 2017-12-07 09:54:52 -08:00 committed by GitHub
commit 5987936a86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -103,11 +103,11 @@ func TreesfindAllRuleNodes(t ParseTree, ruleIndex int) []ParseTree {
func TreesfindAllNodes(t ParseTree, index int, findTokens bool) []ParseTree {
nodes := make([]ParseTree, 0)
TreesFindAllNodes(t, index, findTokens, nodes)
treesFindAllNodes(t, index, findTokens, &nodes)
return nodes
}
func TreesFindAllNodes(t ParseTree, index int, findTokens bool, nodes []ParseTree) {
func treesFindAllNodes(t ParseTree, index int, findTokens bool, nodes *[]ParseTree) {
// check this node (the root) first
t2, ok := t.(TerminalNode)
@ -115,16 +115,16 @@ func TreesFindAllNodes(t ParseTree, index int, findTokens bool, nodes []ParseTre
if findTokens && ok {
if t2.GetSymbol().GetTokenType() == index {
nodes = append(nodes, t2)
*nodes = append(*nodes, t2)
}
} else if !findTokens && ok2 {
if t3.GetRuleIndex() == index {
nodes = append(nodes, t3)
*nodes = append(*nodes, t3)
}
}
// check children
for i := 0; i < t.GetChildCount(); i++ {
TreesFindAllNodes(t.GetChild(i).(ParseTree), index, findTokens, nodes)
treesFindAllNodes(t.GetChild(i).(ParseTree), index, findTokens, nodes)
}
}