mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Add Scope#yields?
				
					
				
			This commit is contained in:
		
							parent
							
								
									4b1378aa33
								
							
						
					
					
						commit
						6ffb635dcc
					
				
					 2 changed files with 16 additions and 0 deletions
				
			
		| 
						 | 
					@ -4,6 +4,9 @@ module Ameba::AST
 | 
				
			||||||
  # Represents a context of the local variable visibility.
 | 
					  # Represents a context of the local variable visibility.
 | 
				
			||||||
  # This is where the local variables belong to.
 | 
					  # This is where the local variables belong to.
 | 
				
			||||||
  class Scope
 | 
					  class Scope
 | 
				
			||||||
 | 
					    # Whether the scope yields.
 | 
				
			||||||
 | 
					    setter yields = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Link to local variables
 | 
					    # Link to local variables
 | 
				
			||||||
    getter variables = [] of Variable
 | 
					    getter variables = [] of Variable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -143,6 +146,14 @@ module Ameba::AST
 | 
				
			||||||
      end || variable.used_in_macro?
 | 
					      end || variable.used_in_macro?
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Returns `true` if current scope (or any of inner scopes) yields,
 | 
				
			||||||
 | 
					    # `false` otherwise.
 | 
				
			||||||
 | 
					    def yields?(check_inner_scopes = true)
 | 
				
			||||||
 | 
					      return true if @yields
 | 
				
			||||||
 | 
					      return inner_scopes.any?(&.yields?) if check_inner_scopes
 | 
				
			||||||
 | 
					      false
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Returns `true` if current scope is a def, `false` otherwise.
 | 
					    # Returns `true` if current scope is a def, `false` otherwise.
 | 
				
			||||||
    def def?
 | 
					    def def?
 | 
				
			||||||
      node.is_a?(Crystal::Def)
 | 
					      node.is_a?(Crystal::Def)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,6 +64,11 @@ module Ameba::AST
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    {% end %}
 | 
					    {% end %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # :nodoc:
 | 
				
			||||||
 | 
					    def visit(node : Crystal::Yield)
 | 
				
			||||||
 | 
					      @current_scope.yields = true
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # :nodoc:
 | 
					    # :nodoc:
 | 
				
			||||||
    def visit(node : Crystal::Def)
 | 
					    def visit(node : Crystal::Def)
 | 
				
			||||||
      node.name == "->" || on_scope_enter(node)
 | 
					      node.name == "->" || on_scope_enter(node)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue