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.
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 |
# File 'lib/yadriggy/ast.rb', line 1399 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.
1380 1381 1382 |
# File 'lib/yadriggy/ast.rb', line 1380 def body @body end |
#else ⇒ ASTnode|nil (readonly)
Returns the else clause.
1385 1386 1387 |
# File 'lib/yadriggy/ast.rb', line 1385 def else @else end |
#ensure ⇒ ASTnode|nil (readonly)
Returns the ensure clause.
1387 1388 1389 |
# File 'lib/yadriggy/ast.rb', line 1387 def ensure @ensure end |
#nested_rescue ⇒ Rescue|nil (readonly)
1383 1384 1385 |
# File 'lib/yadriggy/ast.rb', line 1383 def nested_rescue @nested_rescue end |
#parameter ⇒ ASTnode|nil (readonly)
Returns the rescue parameter.
1378 1379 1380 |
# File 'lib/yadriggy/ast.rb', line 1378 def parameter @parameter end |
#types ⇒ Array<ASTnode> (readonly)
Returns the exception types. It may be empty.
1376 1377 1378 |
# File 'lib/yadriggy/ast.rb', line 1376 def types @types end |
Class Method Details
.make(rescue_expr, else_expr, ensure_expr) ⇒ Object
1391 1392 1393 1394 1395 1396 1397 |
# File 'lib/yadriggy/ast.rb', line 1391 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
1389 |
# File 'lib/yadriggy/ast.rb', line 1389 def self.tag() :rescue end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
1452 1453 1454 |
# File 'lib/yadriggy/ast.rb', line 1452 def accept(evaluator) evaluator.rescue_end(self) end |
#has_else? ⇒ Boolean
Returns true if the else clause is included.
1462 1463 1464 |
# File 'lib/yadriggy/ast.rb', line 1462 def has_else? !@else.nil? end |
#has_ensure? ⇒ Boolean
Returns true if the ensure clause is included.
1467 1468 1469 |
# File 'lib/yadriggy/ast.rb', line 1467 def has_ensure? !@ensure.nil? end |
#has_rescue? ⇒ Boolean
Returns true if the rescue clause is included.
1457 1458 1459 |
# File 'lib/yadriggy/ast.rb', line 1457 def has_rescue? !@body.nil? end |