mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Use utility method to check if node is a loop
This commit is contained in:
parent
0fd5890738
commit
ad2c6bad0e
1 changed files with 5 additions and 4 deletions
|
@ -1,3 +1,5 @@
|
|||
require "./util"
|
||||
|
||||
module Ameba::AST
|
||||
# A generic entity to represent a branchable Crystal node.
|
||||
# For example, `Crystal::If`, `Crystal::Unless`, `Crystal::While`
|
||||
|
@ -11,6 +13,8 @@ module Ameba::AST
|
|||
# end
|
||||
# ```
|
||||
class Branchable
|
||||
include Util
|
||||
|
||||
getter branches = [] of Crystal::ASTNode
|
||||
|
||||
# The actual Crystal node.
|
||||
|
@ -32,10 +36,7 @@ module Ameba::AST
|
|||
|
||||
# Returns true if this node or one of the parent branchables is a loop, false otherwise.
|
||||
def loop?
|
||||
return true if node.is_a? Crystal::While ||
|
||||
node.is_a? Crystal::Until ||
|
||||
((n = node) && n.is_a?(Crystal::Call) && n.name == "loop")
|
||||
|
||||
return true if loop?(node)
|
||||
parent.try(&.loop?) || false
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue