Class: Yadriggy::Rescue
- Includes:
- AstHelper
- Defined in:
- lib/yadriggy/ast.rb
Overview
begin-rescue-ensure.
raise is parsed as a method call (or a command).
Instance Attribute Summary collapse
-
#body ⇒ ASTnode|nil
readonly
The body of the rescue clause.
-
#else ⇒ ASTnode|nil
readonly
The else clause.
-
#ensure ⇒ ASTnode|nil
readonly
The ensure clause.
-
#nested_rescue ⇒ Rescue|nil
readonly
The rest of rescue clauses.
-
#parameter ⇒ ASTnode|nil
readonly
The rescue parameter.
-
#types ⇒ Array<ASTnode>
readonly
The exception types.
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
-
#has_else? ⇒ Boolean
True if the else clause is included.
-
#has_ensure? ⇒ Boolean
True if the ensure clause is included.
-
#has_rescue? ⇒ Boolean
True if the rescue clause is included.
-
#initialize(rescue_expr, else_expr = nil, ensure_expr = nil) ⇒ Rescue
constructor
A new instance of Rescue.
Methods included from AstHelper
#has_tag?, #to_node, #to_nodes
Methods inherited from ASTnode
#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class
Constructor Details
#initialize(rescue_expr, else_expr = nil, ensure_expr = nil) ⇒ Rescue
Returns a new instance of Rescue.
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 |
# File 'lib/yadriggy/ast.rb', line 1455 def initialize(rescue_expr, else_expr=nil, ensure_expr=nil) if rescue_expr.nil? @types = [] @parameter = nil @body = nil @nested_rescue = nil else expr = has_tag?(rescue_expr, :rescue) rescue_clause = expr[1] if rescue_clause.nil? @types = [] elsif rescue_clause[0] == :mrhs_new_from_args types1 = to_nodes(rescue_clause[1]) @types = types1 << to_node(rescue_clause[2]) else @types = to_nodes(rescue_clause) end if expr[2].nil? @parameter = nil else @parameter = to_node(has_tag?(has_tag?(expr[2], :var_field)[1], :@ident)) end @body = Exprs.make(expr[3]) @nested_rescue = to_node(expr[4]) add_children(@types) add_child(@parameter) add_child(@body) add_child(@nested_rescue) end if else_expr.nil? @else = nil else elsexpr = has_tag?(else_expr, :else) @else = Exprs.make(elsexpr[1]) add_child(@else) end if ensure_expr.nil? @ensure = nil else ensexpr = has_tag?(ensure_expr, :ensure) @ensure = Exprs.make(ensexpr[1]) add_child(@ensure) end end |
Instance Attribute Details
#body ⇒ ASTnode|nil (readonly)
Returns the body of the rescue clause.
1436 1437 1438 |
# File 'lib/yadriggy/ast.rb', line 1436 def body @body end |
#else ⇒ ASTnode|nil (readonly)
Returns the else clause.
1441 1442 1443 |
# File 'lib/yadriggy/ast.rb', line 1441 def else @else end |
#ensure ⇒ ASTnode|nil (readonly)
Returns the ensure clause.
1443 1444 1445 |
# File 'lib/yadriggy/ast.rb', line 1443 def ensure @ensure end |
#nested_rescue ⇒ Rescue|nil (readonly)
1439 1440 1441 |
# File 'lib/yadriggy/ast.rb', line 1439 def nested_rescue @nested_rescue end |
#parameter ⇒ ASTnode|nil (readonly)
Returns the rescue parameter.
1434 1435 1436 |
# File 'lib/yadriggy/ast.rb', line 1434 def parameter @parameter end |
#types ⇒ Array<ASTnode> (readonly)
Returns the exception types. It may be empty.
1432 1433 1434 |
# File 'lib/yadriggy/ast.rb', line 1432 def types @types end |
Class Method Details
.make(rescue_expr, else_expr, ensure_expr) ⇒ Object
1447 1448 1449 1450 1451 1452 1453 |
# File 'lib/yadriggy/ast.rb', line 1447 def self.make(rescue_expr, else_expr, ensure_expr) if rescue_expr.nil? && else_expr.nil? && ensure_expr.nil? nil else Rescue.new(rescue_expr, else_expr, ensure_expr) end end |
.tag ⇒ Object
1445 |
# File 'lib/yadriggy/ast.rb', line 1445 def self.tag() :rescue end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
1508 1509 1510 |
# File 'lib/yadriggy/ast.rb', line 1508 def accept(evaluator) evaluator.rescue_end(self) end |
#has_else? ⇒ Boolean
Returns true if the else clause is included.
1518 1519 1520 |
# File 'lib/yadriggy/ast.rb', line 1518 def has_else? !@else.nil? end |
#has_ensure? ⇒ Boolean
Returns true if the ensure clause is included.
1523 1524 1525 |
# File 'lib/yadriggy/ast.rb', line 1523 def has_ensure? !@ensure.nil? end |
#has_rescue? ⇒ Boolean
Returns true if the rescue clause is included.
1513 1514 1515 |
# File 'lib/yadriggy/ast.rb', line 1513 def has_rescue? !@body.nil? end |