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
|
module Ameba::AST
|
||||||
# A generic entity to represent a branchable Crystal node.
|
# A generic entity to represent a branchable Crystal node.
|
||||||
# For example, `Crystal::If`, `Crystal::Unless`, `Crystal::While`
|
# For example, `Crystal::If`, `Crystal::Unless`, `Crystal::While`
|
||||||
|
@ -11,6 +13,8 @@ module Ameba::AST
|
||||||
# end
|
# end
|
||||||
# ```
|
# ```
|
||||||
class Branchable
|
class Branchable
|
||||||
|
include Util
|
||||||
|
|
||||||
getter branches = [] of Crystal::ASTNode
|
getter branches = [] of Crystal::ASTNode
|
||||||
|
|
||||||
# The actual Crystal node.
|
# 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.
|
# Returns true if this node or one of the parent branchables is a loop, false otherwise.
|
||||||
def loop?
|
def loop?
|
||||||
return true if node.is_a? Crystal::While ||
|
return true if loop?(node)
|
||||||
node.is_a? Crystal::Until ||
|
|
||||||
((n = node) && n.is_a?(Crystal::Call) && n.name == "loop")
|
|
||||||
|
|
||||||
parent.try(&.loop?) || false
|
parent.try(&.loop?) || false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue