Skip to content

Commit

Permalink
fix(python): update analyzer (#1589)
Browse files Browse the repository at this point in the history
* fix(python): update analyzer

* Update internal/languages/python/analyzer/analyzer.go

Co-authored-by: David Roe <dave.roe@bearer.sh>

* Update internal/languages/python/analyzer/analyzer.go

Co-authored-by: David Roe <dave.roe@bearer.sh>

---------

Co-authored-by: David Roe <dave.roe@bearer.sh>
  • Loading branch information
elsapet and didroe authored May 13, 2024
1 parent 4faf675 commit bd3a9d9
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions internal/languages/python/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ func (analyzer *analyzer) Analyze(node *sitter.Node, visitChildren func() error)
return analyzer.analyzeSubscript(node, visitChildren)
case "call":
return analyzer.analyzeCall(node, visitChildren)
case "argument_list":
return analyzer.analyzeGenericOperation(node, visitChildren)
case "expression_statement":
case "argument_list", "expression_statement", "list", "tuple":
return analyzer.analyzeGenericOperation(node, visitChildren)
case "parenthesized_expression":
return analyzer.analyzeGenericConstruct(node, visitChildren)
case "keyword_argument":
return analyzer.analyzeKeywordArgument(node, visitChildren)
case "while_statement", "try_statement", "if_statement": // statements don't have results
return visitChildren()
case "conditional_expression":
Expand Down Expand Up @@ -148,6 +150,27 @@ func (analyzer *analyzer) analyzeBoolean(node *sitter.Node, visitChildren func()
return visitChildren()
}

func (analyzer *analyzer) analyzeKeywordArgument(node *sitter.Node, visitChildren func() error) error {
value := node.ChildByFieldName("value")

analyzer.builder.Alias(node, value)
analyzer.lookupVariable(value)

return visitChildren()
}

// default analysis, where the children are assumed to be aliases
func (analyzer *analyzer) analyzeGenericConstruct(node *sitter.Node, visitChildren func() error) error {
children := analyzer.builder.ChildrenFor(node)
analyzer.builder.Alias(node, children...)

for _, child := range children {
analyzer.lookupVariable(child)
}

return visitChildren()
}

// default analysis, where the children are assumed to be data sources
func (analyzer *analyzer) analyzeGenericOperation(node *sitter.Node, visitChildren func() error) error {
children := analyzer.builder.ChildrenFor(node)
Expand Down

0 comments on commit bd3a9d9

Please sign in to comment.