Class: Prism::DesugarCompiler

Inherits:
MutationCompiler show all
Defined in:
lib/prism/desugar_compiler.rb

Overview

DesugarCompiler is a compiler that desugars Ruby code into a more primitive form. This is useful for consumers that want to deal with fewer node types.

Instance Method Summary collapse

Methods inherited from MutationCompiler

#visit_alias_global_variable_node, #visit_alias_method_node, #visit_alternation_pattern_node, #visit_and_node, #visit_arguments_node, #visit_array_node, #visit_array_pattern_node, #visit_assoc_node, #visit_assoc_splat_node, #visit_back_reference_read_node, #visit_begin_node, #visit_block_argument_node, #visit_block_local_variable_node, #visit_block_node, #visit_block_parameter_node, #visit_block_parameters_node, #visit_break_node, #visit_call_and_write_node, #visit_call_node, #visit_call_operator_write_node, #visit_call_or_write_node, #visit_call_target_node, #visit_capture_pattern_node, #visit_case_match_node, #visit_case_node, #visit_class_node, #visit_class_variable_read_node, #visit_class_variable_target_node, #visit_class_variable_write_node, #visit_constant_path_and_write_node, #visit_constant_path_node, #visit_constant_path_operator_write_node, #visit_constant_path_or_write_node, #visit_constant_path_target_node, #visit_constant_path_write_node, #visit_constant_read_node, #visit_constant_target_node, #visit_constant_write_node, #visit_def_node, #visit_defined_node, #visit_else_node, #visit_embedded_statements_node, #visit_embedded_variable_node, #visit_ensure_node, #visit_false_node, #visit_find_pattern_node, #visit_flip_flop_node, #visit_float_node, #visit_for_node, #visit_forwarding_arguments_node, #visit_forwarding_parameter_node, #visit_forwarding_super_node, #visit_global_variable_read_node, #visit_global_variable_target_node, #visit_global_variable_write_node, #visit_hash_node, #visit_hash_pattern_node, #visit_if_node, #visit_imaginary_node, #visit_implicit_node, #visit_implicit_rest_node, #visit_in_node, #visit_index_and_write_node, #visit_index_operator_write_node, #visit_index_or_write_node, #visit_index_target_node, #visit_instance_variable_read_node, #visit_instance_variable_target_node, #visit_instance_variable_write_node, #visit_integer_node, #visit_interpolated_match_last_line_node, #visit_interpolated_regular_expression_node, #visit_interpolated_string_node, #visit_interpolated_symbol_node, #visit_interpolated_x_string_node, #visit_it_local_variable_read_node, #visit_it_parameters_node, #visit_keyword_hash_node, #visit_keyword_rest_parameter_node, #visit_lambda_node, #visit_local_variable_read_node, #visit_local_variable_target_node, #visit_local_variable_write_node, #visit_match_last_line_node, #visit_match_predicate_node, #visit_match_required_node, #visit_match_write_node, #visit_missing_node, #visit_module_node, #visit_multi_target_node, #visit_multi_write_node, #visit_next_node, #visit_nil_node, #visit_no_keywords_parameter_node, #visit_numbered_parameters_node, #visit_numbered_reference_read_node, #visit_optional_keyword_parameter_node, #visit_optional_parameter_node, #visit_or_node, #visit_parameters_node, #visit_parentheses_node, #visit_pinned_expression_node, #visit_pinned_variable_node, #visit_post_execution_node, #visit_pre_execution_node, #visit_program_node, #visit_range_node, #visit_rational_node, #visit_redo_node, #visit_regular_expression_node, #visit_required_keyword_parameter_node, #visit_required_parameter_node, #visit_rescue_modifier_node, #visit_rescue_node, #visit_rest_parameter_node, #visit_retry_node, #visit_return_node, #visit_self_node, #visit_shareable_constant_node, #visit_singleton_class_node, #visit_source_encoding_node, #visit_source_file_node, #visit_source_line_node, #visit_splat_node, #visit_statements_node, #visit_string_node, #visit_super_node, #visit_symbol_node, #visit_true_node, #visit_undef_node, #visit_unless_node, #visit_until_node, #visit_when_node, #visit_while_node, #visit_x_string_node, #visit_yield_node

Methods inherited from BasicVisitor

#visit, #visit_all, #visit_child_nodes

Instance Method Details

#visit_class_variable_and_write_node(node) ⇒ Object

@@foo &&= bar

becomes

@@foo && @@foo = bar



261
262
263
# File 'lib/prism/desugar_compiler.rb', line 261

def visit_class_variable_and_write_node(node)
  node.desugar
end

#visit_class_variable_operator_write_node(node) ⇒ Object

@@foo += bar

becomes

@@foo = @@foo + bar



279
280
281
# File 'lib/prism/desugar_compiler.rb', line 279

def visit_class_variable_operator_write_node(node)
  node.desugar
end

#visit_class_variable_or_write_node(node) ⇒ Object

@@foo ||= bar

becomes

defined?(@@foo) ? @@foo : @@foo = bar



270
271
272
# File 'lib/prism/desugar_compiler.rb', line 270

def visit_class_variable_or_write_node(node)
  node.desugar
end

#visit_constant_and_write_node(node) ⇒ Object

Foo &&= bar

becomes

Foo && Foo = bar



288
289
290
# File 'lib/prism/desugar_compiler.rb', line 288

def visit_constant_and_write_node(node)
  node.desugar
end

#visit_constant_operator_write_node(node) ⇒ Object

Foo += bar

becomes

Foo = Foo + bar



306
307
308
# File 'lib/prism/desugar_compiler.rb', line 306

def visit_constant_operator_write_node(node)
  node.desugar
end

#visit_constant_or_write_node(node) ⇒ Object

Foo ||= bar

becomes

defined?(Foo) ? Foo : Foo = bar



297
298
299
# File 'lib/prism/desugar_compiler.rb', line 297

def visit_constant_or_write_node(node)
  node.desugar
end

#visit_global_variable_and_write_node(node) ⇒ Object

$foo &&= bar

becomes

$foo && $foo = bar



315
316
317
# File 'lib/prism/desugar_compiler.rb', line 315

def visit_global_variable_and_write_node(node)
  node.desugar
end

#visit_global_variable_operator_write_node(node) ⇒ Object

$foo += bar

becomes

$foo = $foo + bar



333
334
335
# File 'lib/prism/desugar_compiler.rb', line 333

def visit_global_variable_operator_write_node(node)
  node.desugar
end

#visit_global_variable_or_write_node(node) ⇒ Object

$foo ||= bar

becomes

defined?($foo) ? $foo : $foo = bar



324
325
326
# File 'lib/prism/desugar_compiler.rb', line 324

def visit_global_variable_or_write_node(node)
  node.desugar
end

#visit_instance_variable_and_write_node(node) ⇒ Object

becomes



342
343
344
# File 'lib/prism/desugar_compiler.rb', line 342

def visit_instance_variable_and_write_node(node)
  node.desugar
end

#visit_instance_variable_operator_write_node(node) ⇒ Object

becomes



360
361
362
# File 'lib/prism/desugar_compiler.rb', line 360

def visit_instance_variable_operator_write_node(node)
  node.desugar
end

#visit_instance_variable_or_write_node(node) ⇒ Object

becomes



351
352
353
# File 'lib/prism/desugar_compiler.rb', line 351

def visit_instance_variable_or_write_node(node)
  node.desugar
end

#visit_local_variable_and_write_node(node) ⇒ Object

foo &&= bar

becomes

foo && foo = bar



369
370
371
# File 'lib/prism/desugar_compiler.rb', line 369

def visit_local_variable_and_write_node(node)
  node.desugar
end

#visit_local_variable_operator_write_node(node) ⇒ Object

foo += bar

becomes

foo = foo + bar



387
388
389
# File 'lib/prism/desugar_compiler.rb', line 387

def visit_local_variable_operator_write_node(node)
  node.desugar
end

#visit_local_variable_or_write_node(node) ⇒ Object

foo ||= bar

becomes

foo || foo = bar



378
379
380
# File 'lib/prism/desugar_compiler.rb', line 378

def visit_local_variable_or_write_node(node)
  node.desugar
end