mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add ability to skip some of the nodes in AST::ScopeVisitor
This commit is contained in:
parent
ad5d56b313
commit
3f7ade573a
1 changed files with 8 additions and 1 deletions
|
@ -8,14 +8,17 @@ module Ameba::AST
|
|||
|
||||
@scope_queue = [] of Scope
|
||||
@current_scope : Scope
|
||||
@skip : Array(Crystal::ASTNode.class)?
|
||||
|
||||
def initialize(@rule, @source)
|
||||
def initialize(@rule, @source, skip = nil)
|
||||
@skip = skip.try &.map(&.as(Crystal::ASTNode.class))
|
||||
@current_scope = Scope.new(@source.ast) # top level scope
|
||||
@source.ast.accept self
|
||||
@scope_queue.each { |scope| @rule.test @source, scope.node, scope }
|
||||
end
|
||||
|
||||
private def on_scope_enter(node)
|
||||
return if skip?(node)
|
||||
@current_scope = Scope.new(node, @current_scope)
|
||||
end
|
||||
|
||||
|
@ -182,5 +185,9 @@ module Ameba::AST
|
|||
private def record_macro?(node)
|
||||
node.name == RECORD_NODE_NAME && node.args.first?.is_a?(Crystal::Path)
|
||||
end
|
||||
|
||||
private def skip?(node)
|
||||
!!@skip.try(&.includes?(node.class))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue