class Ameba::AST::ElseIfAwareNodeVisitor

Overview

A class that utilizes a logic inherited from NodeVisitor to traverse AST nodes and fire a source test callback with the Crystal::If node and an array containing all elsif branches (first branch is an if node) in case at least one elsif branch is reached, and nil otherwise.

In Crystal, consecutive elsif branches are transformed into if branches attached to the else branch of an adjacent if branch.

For example:

if foo
  do_foo
elsif bar
  do_bar
elsif baz
  do_baz
else
  do_something_else
end

is transformed into:

if foo
  do_foo
else
  if bar
    do_bar
  else
    if baz
      do_baz
    else
      do_something_else
    end
  end
end

Included Modules

Defined in:

ameba/ast/visitors/elseif_aware_node_visitor.cr

Constructors

Instance Method Summary

Instance methods inherited from module Ameba::AST::Util

abort?(node) abort?, control_exp_code(node : Crystal::ControlExpression, code_lines) control_exp_code, dynamic_literal?(node) : Bool dynamic_literal?, each_inline_directive(source, &block : Crystal::Token, String, Array(String) -> _) each_inline_directive, exit?(node) exit?, flow_command?(node, in_loop) flow_command?, flow_expression?(node, in_loop = false) flow_expression?, has_arguments?(node) : Bool has_arguments?, has_block?(node) : Bool has_block?, has_short_block?(node, code_lines) has_short_block?, heredoc?(node : Crystal::ASTNode, source : Source) heredoc?, literal?(node) : Bool literal?, loop?(node) loop?, name_end_location(node) name_end_location, name_location(node) name_location, name_location_or(token : Crystal::Token, name, *, adjust_location_column_number = nil)
name_location_or(node : Crystal::ASTNode, *, adjust_location_column_number = nil)
name_location_or
, name_size(node) name_size, node_source(node, code_lines) node_source, nodoc?(node) nodoc?, operator_method?(node) operator_method?, operator_method_name?(name : String) operator_method_name?, path_name(node : Crystal::Path, *, include_global = true) : String path_name, path_named?(node, *names : String) : Bool path_named?, raise?(node) raise?, setter_method?(node) setter_method?, setter_method_name?(name : String) setter_method_name?, short_block?(node, code_lines) short_block?, source_between(loc, end_loc, code_lines) : String | Nil source_between, static_literal?(node) : Bool static_literal?, suffix?(node) suffix?, takes_arguments?(node) : Bool takes_arguments?

Instance methods inherited from class Ameba::AST::NodeVisitor

visit(node : Crystal::VisibilityModifier)
visit(node : Crystal::Alias)
visit(node : Crystal::ArrayLiteral)
visit(node : Crystal::Assign)
visit(node : Crystal::Block)
visit(node : Crystal::Call)
visit(node : Crystal::Case)
visit(node : Crystal::ClassDef)
visit(node : Crystal::ClassVar)
visit(node : Crystal::ControlExpression)
visit(node : Crystal::Def)
visit(node : Crystal::EnumDef)
visit(node : Crystal::ExceptionHandler)
visit(node : Crystal::Expressions)
visit(node : Crystal::HashLiteral)
visit(node : Crystal::If)
visit(node : Crystal::InstanceVar)
visit(node : Crystal::IsA)
visit(node : Crystal::LibDef)
visit(node : Crystal::MacroExpression)
visit(node : Crystal::ModuleDef)
visit(node : Crystal::MultiAssign)
visit(node : Crystal::NilLiteral)
visit(node : Crystal::ProcLiteral)
visit(node : Crystal::Rescue)
visit(node : Crystal::Select)
visit(node : Crystal::StringInterpolation)
visit(node : Crystal::StringLiteral)
visit(node : Crystal::Union)
visit(node : Crystal::Unless)
visit(node : Crystal::Until)
visit(node : Crystal::Var)
visit(node : Crystal::When)
visit(node : Crystal::While)
visit(node)
visit

Constructor methods inherited from class Ameba::AST::NodeVisitor

new(rule, source, *, skip : Category)
new(rule, source, *, skip : Array | Nil = nil)
new

Class methods inherited from class Ameba::AST::NodeVisitor

category_to_node_classes(category : Category) category_to_node_classes

Instance methods inherited from class Ameba::AST::BaseVisitor

visit(node : Crystal::ASTNode) visit

Constructor methods inherited from class Ameba::AST::BaseVisitor

new(rule : Ameba::Rule::Base, source : Ameba::Source) new

Constructor Detail

def self.new(rule, source, *, skip : Array | Category | Nil = nil, exclude_ternary : Bool = true, exclude_suffix : Bool = true) #

Instance Method Detail

def exclude_suffix? : Bool #

def exclude_ternary? : Bool #

def visit(node : Crystal::If) #
Description copied from class Ameba::AST::NodeVisitor

A visit callback for Crystal::If node.

Returns true if the child nodes should be traversed as well, false otherwise.