class Prism::Compiler

A compiler is a visitor that returns the value of each node as it visits. This is as opposed to a visitor which will only walk the tree. This can be useful when you are trying to compile a tree into a different format.

For example, to build a representation of the tree as s-expressions, you could write:

class SExpressions < Prism::Compiler
  def visit_arguments_node(node) = [:arguments, super]
  def visit_call_node(node) = [:call, super]
  def visit_integer_node(node) = [:integer]
  def visit_program_node(node) = [:program, super]
end

Prism.parse("1 + 2").value.accept(SExpressions.new)
# => [:program, [[[:call, [[:integer], [:arguments, [[:integer]]]]]]]]

Public Instance Methods

visit(node) click to toggle source

Visit an individual node.

# File lib/prism/compiler.rb, line 29
def visit(node)
  node&.accept(self)
end
visit_alias_global_variable_node(node)

Compile a AliasGlobalVariableNode node

Alias for: visit_child_nodes
visit_alias_method_node(node)

Compile a AliasMethodNode node

Alias for: visit_child_nodes
visit_all(nodes) click to toggle source

Visit a list of nodes.

# File lib/prism/compiler.rb, line 34
def visit_all(nodes)
  nodes.map { |node| node&.accept(self) }
end
visit_alternation_pattern_node(node)

Compile a AlternationPatternNode node

Alias for: visit_child_nodes
visit_and_node(node)

Compile a AndNode node

Alias for: visit_child_nodes
visit_arguments_node(node)

Compile a ArgumentsNode node

Alias for: visit_child_nodes
visit_array_node(node)

Compile a ArrayNode node

Alias for: visit_child_nodes
visit_array_pattern_node(node)

Compile a ArrayPatternNode node

Alias for: visit_child_nodes
visit_assoc_node(node)

Compile a AssocNode node

Alias for: visit_child_nodes
visit_assoc_splat_node(node)

Compile a AssocSplatNode node

Alias for: visit_child_nodes
visit_back_reference_read_node(node)

Compile a BackReferenceReadNode node

Alias for: visit_child_nodes
visit_begin_node(node)

Compile a BeginNode node

Alias for: visit_child_nodes
visit_block_argument_node(node)

Compile a BlockArgumentNode node

Alias for: visit_child_nodes
visit_block_local_variable_node(node)

Compile a BlockLocalVariableNode node

Alias for: visit_child_nodes
visit_block_node(node)

Compile a BlockNode node

Alias for: visit_child_nodes
visit_block_parameter_node(node)

Compile a BlockParameterNode node

Alias for: visit_child_nodes
visit_block_parameters_node(node)

Compile a BlockParametersNode node

Alias for: visit_child_nodes
visit_break_node(node)

Compile a BreakNode node

Alias for: visit_child_nodes
visit_call_and_write_node(node)

Compile a CallAndWriteNode node

Alias for: visit_child_nodes
visit_call_node(node)

Compile a CallNode node

Alias for: visit_child_nodes
visit_call_operator_write_node(node)

Compile a CallOperatorWriteNode node

Alias for: visit_child_nodes
visit_call_or_write_node(node)

Compile a CallOrWriteNode node

Alias for: visit_child_nodes
visit_call_target_node(node)

Compile a CallTargetNode node

Alias for: visit_child_nodes
visit_capture_pattern_node(node)

Compile a CapturePatternNode node

Alias for: visit_child_nodes
visit_case_match_node(node)

Compile a CaseMatchNode node

Alias for: visit_child_nodes
visit_case_node(node)

Compile a CaseNode node

Alias for: visit_child_nodes
visit_child_nodes(node) click to toggle source

Visit the child nodes of the given node.

# File lib/prism/compiler.rb, line 39
def visit_child_nodes(node)
  node.compact_child_nodes.map { |node| node.accept(self) }
end
Also aliased as: 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_and_write_node, visit_class_variable_operator_write_node, visit_class_variable_or_write_node, visit_class_variable_read_node, visit_class_variable_target_node, visit_class_variable_write_node, visit_constant_and_write_node, visit_constant_operator_write_node, visit_constant_or_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_and_write_node, visit_global_variable_operator_write_node, visit_global_variable_or_write_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_and_write_node, visit_instance_variable_operator_write_node, visit_instance_variable_or_write_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_and_write_node, visit_local_variable_operator_write_node, visit_local_variable_or_write_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
visit_class_node(node)

Compile a ClassNode node

Alias for: visit_child_nodes
visit_class_variable_and_write_node(node)

Compile a ClassVariableAndWriteNode node

Alias for: visit_child_nodes
visit_class_variable_operator_write_node(node)
Alias for: visit_child_nodes
visit_class_variable_or_write_node(node)

Compile a ClassVariableOrWriteNode node

Alias for: visit_child_nodes
visit_class_variable_read_node(node)

Compile a ClassVariableReadNode node

Alias for: visit_child_nodes
visit_class_variable_target_node(node)

Compile a ClassVariableTargetNode node

Alias for: visit_child_nodes
visit_class_variable_write_node(node)

Compile a ClassVariableWriteNode node

Alias for: visit_child_nodes
visit_constant_and_write_node(node)

Compile a ConstantAndWriteNode node

Alias for: visit_child_nodes
visit_constant_operator_write_node(node)

Compile a ConstantOperatorWriteNode node

Alias for: visit_child_nodes
visit_constant_or_write_node(node)

Compile a ConstantOrWriteNode node

Alias for: visit_child_nodes
visit_constant_path_and_write_node(node)

Compile a ConstantPathAndWriteNode node

Alias for: visit_child_nodes
visit_constant_path_node(node)

Compile a ConstantPathNode node

Alias for: visit_child_nodes
visit_constant_path_operator_write_node(node)
Alias for: visit_child_nodes
visit_constant_path_or_write_node(node)

Compile a ConstantPathOrWriteNode node

Alias for: visit_child_nodes
visit_constant_path_target_node(node)

Compile a ConstantPathTargetNode node

Alias for: visit_child_nodes
visit_constant_path_write_node(node)

Compile a ConstantPathWriteNode node

Alias for: visit_child_nodes
visit_constant_read_node(node)

Compile a ConstantReadNode node

Alias for: visit_child_nodes
visit_constant_target_node(node)

Compile a ConstantTargetNode node

Alias for: visit_child_nodes
visit_constant_write_node(node)

Compile a ConstantWriteNode node

Alias for: visit_child_nodes
visit_def_node(node)

Compile a DefNode node

Alias for: visit_child_nodes
visit_defined_node(node)

Compile a DefinedNode node

Alias for: visit_child_nodes
visit_else_node(node)

Compile a ElseNode node

Alias for: visit_child_nodes
visit_embedded_statements_node(node)

Compile a EmbeddedStatementsNode node

Alias for: visit_child_nodes
visit_embedded_variable_node(node)

Compile a EmbeddedVariableNode node

Alias for: visit_child_nodes
visit_ensure_node(node)

Compile a EnsureNode node

Alias for: visit_child_nodes
visit_false_node(node)

Compile a FalseNode node

Alias for: visit_child_nodes
visit_find_pattern_node(node)

Compile a FindPatternNode node

Alias for: visit_child_nodes
visit_flip_flop_node(node)

Compile a FlipFlopNode node

Alias for: visit_child_nodes
visit_float_node(node)

Compile a FloatNode node

Alias for: visit_child_nodes
visit_for_node(node)

Compile a ForNode node

Alias for: visit_child_nodes
visit_forwarding_arguments_node(node)

Compile a ForwardingArgumentsNode node

Alias for: visit_child_nodes
visit_forwarding_parameter_node(node)

Compile a ForwardingParameterNode node

Alias for: visit_child_nodes
visit_forwarding_super_node(node)

Compile a ForwardingSuperNode node

Alias for: visit_child_nodes
visit_global_variable_and_write_node(node)
Alias for: visit_child_nodes
visit_global_variable_operator_write_node(node)
Alias for: visit_child_nodes
visit_global_variable_or_write_node(node)

Compile a GlobalVariableOrWriteNode node

Alias for: visit_child_nodes
visit_global_variable_read_node(node)

Compile a GlobalVariableReadNode node

Alias for: visit_child_nodes
visit_global_variable_target_node(node)

Compile a GlobalVariableTargetNode node

Alias for: visit_child_nodes
visit_global_variable_write_node(node)

Compile a GlobalVariableWriteNode node

Alias for: visit_child_nodes
visit_hash_node(node)

Compile a HashNode node

Alias for: visit_child_nodes
visit_hash_pattern_node(node)

Compile a HashPatternNode node

Alias for: visit_child_nodes
visit_if_node(node)

Compile a IfNode node

Alias for: visit_child_nodes
visit_imaginary_node(node)

Compile a ImaginaryNode node

Alias for: visit_child_nodes
visit_implicit_node(node)

Compile a ImplicitNode node

Alias for: visit_child_nodes
visit_implicit_rest_node(node)

Compile a ImplicitRestNode node

Alias for: visit_child_nodes
visit_in_node(node)

Compile a InNode node

Alias for: visit_child_nodes
visit_index_and_write_node(node)

Compile a IndexAndWriteNode node

Alias for: visit_child_nodes
visit_index_operator_write_node(node)

Compile a IndexOperatorWriteNode node

Alias for: visit_child_nodes
visit_index_or_write_node(node)

Compile a IndexOrWriteNode node

Alias for: visit_child_nodes
visit_index_target_node(node)

Compile a IndexTargetNode node

Alias for: visit_child_nodes
visit_instance_variable_and_write_node(node)
Alias for: visit_child_nodes
visit_instance_variable_operator_write_node(node)
Alias for: visit_child_nodes
visit_instance_variable_or_write_node(node)
Alias for: visit_child_nodes
visit_instance_variable_read_node(node)

Compile a InstanceVariableReadNode node

Alias for: visit_child_nodes
visit_instance_variable_target_node(node)
Alias for: visit_child_nodes
visit_instance_variable_write_node(node)

Compile a InstanceVariableWriteNode node

Alias for: visit_child_nodes
visit_integer_node(node)

Compile a IntegerNode node

Alias for: visit_child_nodes
visit_interpolated_match_last_line_node(node)
Alias for: visit_child_nodes
visit_interpolated_regular_expression_node(node)
Alias for: visit_child_nodes
visit_interpolated_string_node(node)

Compile a InterpolatedStringNode node

Alias for: visit_child_nodes
visit_interpolated_symbol_node(node)

Compile a InterpolatedSymbolNode node

Alias for: visit_child_nodes
visit_interpolated_x_string_node(node)

Compile a InterpolatedXStringNode node

Alias for: visit_child_nodes
visit_it_local_variable_read_node(node)

Compile a ItLocalVariableReadNode node

Alias for: visit_child_nodes
visit_it_parameters_node(node)

Compile a ItParametersNode node

Alias for: visit_child_nodes
visit_keyword_hash_node(node)

Compile a KeywordHashNode node

Alias for: visit_child_nodes
visit_keyword_rest_parameter_node(node)

Compile a KeywordRestParameterNode node

Alias for: visit_child_nodes
visit_lambda_node(node)

Compile a LambdaNode node

Alias for: visit_child_nodes
visit_local_variable_and_write_node(node)

Compile a LocalVariableAndWriteNode node

Alias for: visit_child_nodes
visit_local_variable_operator_write_node(node)
Alias for: visit_child_nodes
visit_local_variable_or_write_node(node)

Compile a LocalVariableOrWriteNode node

Alias for: visit_child_nodes
visit_local_variable_read_node(node)

Compile a LocalVariableReadNode node

Alias for: visit_child_nodes
visit_local_variable_target_node(node)

Compile a LocalVariableTargetNode node

Alias for: visit_child_nodes
visit_local_variable_write_node(node)

Compile a LocalVariableWriteNode node

Alias for: visit_child_nodes
visit_match_last_line_node(node)

Compile a MatchLastLineNode node

Alias for: visit_child_nodes
visit_match_predicate_node(node)

Compile a MatchPredicateNode node

Alias for: visit_child_nodes
visit_match_required_node(node)

Compile a MatchRequiredNode node

Alias for: visit_child_nodes
visit_match_write_node(node)

Compile a MatchWriteNode node

Alias for: visit_child_nodes
visit_missing_node(node)

Compile a MissingNode node

Alias for: visit_child_nodes
visit_module_node(node)

Compile a ModuleNode node

Alias for: visit_child_nodes
visit_multi_target_node(node)

Compile a MultiTargetNode node

Alias for: visit_child_nodes
visit_multi_write_node(node)

Compile a MultiWriteNode node

Alias for: visit_child_nodes
visit_next_node(node)

Compile a NextNode node

Alias for: visit_child_nodes
visit_nil_node(node)

Compile a NilNode node

Alias for: visit_child_nodes
visit_no_keywords_parameter_node(node)

Compile a NoKeywordsParameterNode node

Alias for: visit_child_nodes
visit_numbered_parameters_node(node)

Compile a NumberedParametersNode node

Alias for: visit_child_nodes
visit_numbered_reference_read_node(node)

Compile a NumberedReferenceReadNode node

Alias for: visit_child_nodes
visit_optional_keyword_parameter_node(node)
Alias for: visit_child_nodes
visit_optional_parameter_node(node)

Compile a OptionalParameterNode node

Alias for: visit_child_nodes
visit_or_node(node)

Compile a OrNode node

Alias for: visit_child_nodes
visit_parameters_node(node)

Compile a ParametersNode node

Alias for: visit_child_nodes
visit_parentheses_node(node)

Compile a ParenthesesNode node

Alias for: visit_child_nodes
visit_pinned_expression_node(node)

Compile a PinnedExpressionNode node

Alias for: visit_child_nodes
visit_pinned_variable_node(node)

Compile a PinnedVariableNode node

Alias for: visit_child_nodes
visit_post_execution_node(node)

Compile a PostExecutionNode node

Alias for: visit_child_nodes
visit_pre_execution_node(node)

Compile a PreExecutionNode node

Alias for: visit_child_nodes
visit_program_node(node)

Compile a ProgramNode node

Alias for: visit_child_nodes
visit_range_node(node)

Compile a RangeNode node

Alias for: visit_child_nodes
visit_rational_node(node)

Compile a RationalNode node

Alias for: visit_child_nodes
visit_redo_node(node)

Compile a RedoNode node

Alias for: visit_child_nodes
visit_regular_expression_node(node)

Compile a RegularExpressionNode node

Alias for: visit_child_nodes
visit_required_keyword_parameter_node(node)
Alias for: visit_child_nodes
visit_required_parameter_node(node)

Compile a RequiredParameterNode node

Alias for: visit_child_nodes
visit_rescue_modifier_node(node)

Compile a RescueModifierNode node

Alias for: visit_child_nodes
visit_rescue_node(node)

Compile a RescueNode node

Alias for: visit_child_nodes
visit_rest_parameter_node(node)

Compile a RestParameterNode node

Alias for: visit_child_nodes
visit_retry_node(node)

Compile a RetryNode node

Alias for: visit_child_nodes
visit_return_node(node)

Compile a ReturnNode node

Alias for: visit_child_nodes
visit_self_node(node)

Compile a SelfNode node

Alias for: visit_child_nodes
visit_shareable_constant_node(node)

Compile a ShareableConstantNode node

Alias for: visit_child_nodes
visit_singleton_class_node(node)

Compile a SingletonClassNode node

Alias for: visit_child_nodes
visit_source_encoding_node(node)

Compile a SourceEncodingNode node

Alias for: visit_child_nodes
visit_source_file_node(node)

Compile a SourceFileNode node

Alias for: visit_child_nodes
visit_source_line_node(node)

Compile a SourceLineNode node

Alias for: visit_child_nodes
visit_splat_node(node)

Compile a SplatNode node

Alias for: visit_child_nodes
visit_statements_node(node)

Compile a StatementsNode node

Alias for: visit_child_nodes
visit_string_node(node)

Compile a StringNode node

Alias for: visit_child_nodes
visit_super_node(node)

Compile a SuperNode node

Alias for: visit_child_nodes
visit_symbol_node(node)

Compile a SymbolNode node

Alias for: visit_child_nodes
visit_true_node(node)

Compile a TrueNode node

Alias for: visit_child_nodes
visit_undef_node(node)

Compile a UndefNode node

Alias for: visit_child_nodes
visit_unless_node(node)

Compile a UnlessNode node

Alias for: visit_child_nodes
visit_until_node(node)

Compile a UntilNode node

Alias for: visit_child_nodes
visit_when_node(node)

Compile a WhenNode node

Alias for: visit_child_nodes
visit_while_node(node)

Compile a WhileNode node

Alias for: visit_child_nodes
visit_x_string_node(node)

Compile a XStringNode node

Alias for: visit_child_nodes
visit_yield_node(node)

Compile a YieldNode node

Alias for: visit_child_nodes