123456789_123456789_123456789_123456789_123456789_

Class: Prism::Translation::Ripper::SexpBuilder

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Prism::Translation::Ripper
Defined in: lib/prism/translation/ripper/sexp.rb

Overview

This class mirrors the ::Ripper::SexpBuilder subclass of Ripper that returns the arrays of [type, *children].

Constant Summary

::Prism::Translation::Ripper - Inherited

BINARY_OPERATORS, EVENTS, KEYWORDS, PARSER_EVENTS, PARSER_EVENT_TABLE, SCANNER_EVENTS, SCANNER_EVENT_TABLE

Class Method Summary

::Prism::Translation::Ripper - Inherited

.lex

Tokenizes the Ruby program and returns an array of an array, which is formatted like [[lineno, column], type, token, state].

.new

Create a new ::Prism::Translation::Ripper object with the given source.

.parse

Parses the given Ruby program read from src.

.sexp

Parses src and create S-exp tree.

.sexp_raw

Parses src and create S-exp tree.

Instance Attribute Summary

::Prism::Translation::Ripper - Inherited

#column

The current column number of the parser.

#error?

True if the parser encountered an error during parsing.

#filename

The filename of the source being parsed.

#lineno

The current line number of the parser.

#source

The source that is being parsed.

Instance Method Summary

::Prism::Translation::Ripper - Inherited

#parse

Parse the source and return the result.

#visit_alias_global_variable_node

alias $foo $bar ^^^^^^^^^^^^^^^.

#visit_alias_method_node

alias foo bar ^^^^^^^^^^^^^.

#visit_alternation_pattern_node

foo => bar | baz.

#visit_and_node

a and b ^^^^^^^.

#visit_arguments_node

foo(bar).

#visit_array_node

^^.

#visit_array_pattern_node

foo => [bar].

#visit_assoc_node

{ a: 1 }

#visit_assoc_splat_node

def foo(**); bar(**); end.

#visit_back_reference_read_node

$+ ^^.

#visit_begin_node

begin end ^^^^^^^^^.

#visit_block_argument_node

foo(&bar).

#visit_block_local_variable_node

foo { |; bar| }

#visit_block_node

Visit a BlockNode.

#visit_block_parameter_node

def foo(&bar); end.

#visit_block_parameters_node

A block’s parameters.

#visit_break_node

break ^^^^^.

#visit_call_and_write_node

foo.bar &&= baz ^^^^^^^^^^^^^^^.

#visit_call_node

foo ^^^.

#visit_call_operator_write_node

foo.bar += baz ^^^^^^^^^^^^^^^.

#visit_call_or_write_node

foo.bar ||= baz ^^^^^^^^^^^^^^^.

#visit_call_target_node

foo.bar, = 1 ^^^^^^^.

#visit_capture_pattern_node

foo => bar => baz.

#visit_case_match_node

case foo; in bar; end ^^^^^^^^^^^^^^^^^^^^^.

#visit_case_node

case foo; when bar; end ^^^^^^^^^^^^^^^^^^^^^^^.

#visit_class_node

class Foo; end ^^^^^^^^^^^^^^.

#visit_class_variable_and_write_node

@@foo &&= bar ^^^^^^^^^^^^^.

#visit_class_variable_operator_write_node

@@foo += bar ^^^^^^^^^^^^.

#visit_class_variable_or_write_node

@@foo ||= bar ^^^^^^^^^^^^^.

#visit_class_variable_read_node

@@foo ^^^^^.

#visit_class_variable_target_node

@@foo, = bar ^^^^^.

#visit_class_variable_write_node

@@foo = 1 ^^^^^^^^^.

#visit_constant_and_write_node

Foo &&= bar ^^^^^^^^^^^^.

#visit_constant_operator_write_node

Foo += bar ^^^^^^^^^^^.

#visit_constant_or_write_node

Foo ||= bar ^^^^^^^^^^^^.

#visit_constant_path_and_write_node

Foo::Bar &&= baz ^^^^^^^^^^^^^^^^.

#visit_constant_path_node

Foo::Bar ^^^^^^^^.

#visit_constant_path_operator_write_node

Foo::Bar += baz ^^^^^^^^^^^^^^^.

#visit_constant_path_or_write_node

Foo::Bar ||= baz ^^^^^^^^^^^^^^^^.

#visit_constant_path_target_node

Foo::Bar, = baz ^^^^^^^^.

#visit_constant_path_write_node

Foo::Bar = 1 ^^^^^^^^^^^^.

#visit_constant_read_node

Foo ^^^.

#visit_constant_target_node

Foo, = bar ^^^.

#visit_constant_write_node

Foo = 1 ^^^^^^^.

#visit_def_node

def foo; end ^^^^^^^^^^^^.

#visit_defined_node

defined? a ^^^^^^^^^^.

#visit_else_node

if foo then bar else baz end.

#visit_embedded_statements_node

“foo #bar”.

#visit_embedded_variable_node

“foo #@bar”.

#visit_ensure_node

Visit an EnsureNode node.

#visit_false_node

false ^^^^^.

#visit_find_pattern_node

foo => [*, bar, *].

#visit_flip_flop_node

if foo ..

#visit_float_node

1.0 ^^^.

#visit_for_node

for foo in bar do end ^^^^^^^^^^^^^^^^^^^^^.

#visit_forwarding_arguments_node

def foo(…); bar(…); end.

#visit_forwarding_parameter_node

def foo(…); end.

#visit_forwarding_super_node

super ^^^^^.

#visit_global_variable_and_write_node

$foo &&= bar ^^^^^^^^^^^^.

#visit_global_variable_operator_write_node

$foo += bar ^^^^^^^^^^^.

#visit_global_variable_or_write_node

$foo ||= bar ^^^^^^^^^^^^.

#visit_global_variable_read_node

$foo ^^^^.

#visit_global_variable_target_node

$foo, = bar ^^^^.

#visit_global_variable_write_node

$foo = 1 ^^^^^^^^.

#visit_hash_node

{} ^^.

#visit_hash_pattern_node

foo => {}

#visit_if_node

if foo then bar end ^^^^^^^^^^^^^^^^^^^.

#visit_imaginary_node

1i ^^.

#visit_implicit_node

{ foo: }

#visit_implicit_rest_node

foo { |bar,| }

#visit_in_node

case foo; in bar; end ^^^^^^^^^^^^^^^^^^^^^.

#visit_index_and_write_node

foo &&= baz ^^^^^^^^^^^^^^^^.

#visit_index_operator_write_node

foo += baz ^^^^^^^^^^^^^^^.

#visit_index_or_write_node

foo ||= baz ^^^^^^^^^^^^^^^^.

#visit_index_target_node

foo, = 1 ^^^^^^^^.

#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

@foo, = bar ^^^^.

#visit_instance_variable_write_node

^^^^^^^^.

#visit_integer_node

1 ^.

#visit_interpolated_match_last_line_node

if /foo #bar/ then end.

#visit_interpolated_regular_expression_node

/foo #bar/ ^^^^^^^^^^^^.

#visit_interpolated_string_node

“foo #bar” ^^^^^^^^^^^^.

#visit_interpolated_symbol_node

:“foo #bar” ^^^^^^^^^^^^^.

#visit_interpolated_x_string_node

foo #{bar} ^^^^^^^^^^^^.

#visit_it_local_variable_read_node

-> { it }

#visit_it_parameters_node

-> { it } ^^^^^^^^^.

#visit_keyword_hash_node

foo(bar: baz).

#visit_keyword_rest_parameter_node

def foo(**bar); end.

#visit_lambda_node

-> {}

#visit_local_variable_and_write_node

foo &&= bar ^^^^^^^^^^^.

#visit_local_variable_operator_write_node

foo += bar ^^^^^^^^^^.

#visit_local_variable_or_write_node

foo ||= bar ^^^^^^^^^^^.

#visit_local_variable_read_node

foo ^^^.

#visit_local_variable_target_node

foo, = bar ^^^.

#visit_local_variable_write_node

foo = 1 ^^^^^^^.

#visit_match_last_line_node

if /foo/ then end.

#visit_match_predicate_node

foo in bar ^^^^^^^^^^.

#visit_match_required_node

foo => bar ^^^^^^^^^^.

#visit_match_write_node

/(?<foo>foo)/ =~ bar ^^^^^^^^^^^^^^^^^^^^.

#visit_missing_node

A node that is missing from the syntax tree.

#visit_module_node

module Foo; end ^^^^^^^^^^^^^^^.

#visit_multi_target_node

(foo, bar), bar = qux ^^^^^^^^^^.

#visit_multi_write_node

foo, bar = baz ^^^^^^^^^^^^^^.

#visit_next_node

next ^^^^.

#visit_nil_node

nil ^^^.

#visit_no_keywords_parameter_node

def foo(**nil); end.

#visit_numbered_parameters_node

-> { _1 + _2 } ^^^^^^^^^^^^^^.

#visit_numbered_reference_read_node

$1 ^^.

#visit_optional_keyword_parameter_node

def foo(bar: baz); end.

#visit_optional_parameter_node

def foo(bar = 1); end.

#visit_or_node

a or b ^^^^^^.

#visit_parameters_node

def foo(bar, *baz); end.

#visit_parentheses_node

() ^^.

#visit_pinned_expression_node

foo => ^(bar).

#visit_pinned_variable_node

foo = 1 and bar => ^foo.

#visit_post_execution_node

END {} ^^^^^^.

#visit_pre_execution_node

BEGIN {} ^^^^^^^^.

#visit_program_node

The top-level program node.

#visit_range_node

0..5 ^^^^.

#visit_rational_node

1r ^^.

#visit_redo_node

redo ^^^^.

#visit_regular_expression_node

/foo/ ^^^^^.

#visit_required_keyword_parameter_node

def foo(bar:); end.

#visit_required_parameter_node

def foo(bar); end.

#visit_rescue_modifier_node

foo rescue bar ^^^^^^^^^^^^^^.

#visit_rescue_node

begin; rescue; end.

#visit_rest_parameter_node

def foo(*bar); end.

#visit_retry_node

retry ^^^^^.

#visit_return_node

return ^^^^^^.

#visit_self_node

self ^^^^.

#visit_shareable_constant_node

A shareable constant.

#visit_singleton_class_node

class << self; end ^^^^^^^^^^^^^^^^^^.

#visit_source_encoding_node

__ENCODING__ ^^^^^^^^^^^^.

#visit_source_file_node

__FILE__ ^^^^^^^^.

#visit_source_line_node

__LINE__ ^^^^^^^^.

#visit_splat_node

foo(*bar).

#visit_statements_node

A list of statements.

#visit_string_node

“foo” ^^^^^.

#visit_super_node

super(foo) ^^^^^^^^^^.

#visit_symbol_node

:foo ^^^^.

#visit_true_node

true ^^^^.

#visit_undef_node

undef foo ^^^^^^^^^.

#visit_unless_node

unless foo; bar end ^^^^^^^^^^^^^^^^^^^.

#visit_until_node

until foo; bar end ^^^^^^^^^^^^^^^^^.

#visit_when_node

case foo; when bar; end.

#visit_while_node

while foo; bar end ^^^^^^^^^^^^^^^^^^.

#visit_x_string_node

foo ^^^^^.

#visit_yield_node

yield ^^^^^.

#bounds

This method is responsible for updating lineno and column information to reflect the current node.

#command?

Returns true if the given node is a command node.

#compile_error

This method is called when the parser found syntax error.

#dedent_string

This method is provided by the ::Prism::Translation::Ripper C extension.

#result

Lazily initialize the parse result.

#trailing_comma?

Returns true if there is a comma between the two locations.

#visit_alias_global_variable_node_value

Visit one side of an alias global variable node.

#visit_arguments

Visit a list of elements, like the elements of an array or arguments.

#visit_begin_node_clauses

Visit the clauses of a begin node to form an on_bodystmt call.

#visit_body_node

Visit the body of a structure that can have either a set of statements or statements wrapped in rescue/else/ensure.

#visit_call_node_arguments

Visit the arguments and block of a call node and return the arguments and block as they should be used.

#visit_constant_path_write_node_target

Visit a constant path that is part of a write node.

#visit_destructured_parameter_node

Visit a destructured positional parameter node.

#visit_heredoc_node

Visit a string that is expressed using a <<~ heredoc.

#visit_heredoc_node_whitespace

::Prism::Translation::Ripper gives back the escaped string content but strips out the common leading whitespace.

#visit_heredoc_string_node

Visit a heredoc node that is representing a string.

#visit_heredoc_x_string_node

Visit a heredoc node that is representing an xstring.

#visit_multi_target_node_targets

Visit the targets of a multi-target node.

#visit_number_node

Visit a node that represents a number.

#visit_pattern_node

Visit a pattern within a pattern match.

#visit_statements_node_body

Visit the list of statements of a statements node.

#visit_string_content

Visit an individual part of a string-like node.

#visit_token

Visit the string content of a particular node.

#visit_words_sep

Dispatch a words_sep event that contains the space between the elements of list literals.

#visit_write_value

Visit a node that represents a write value.

#void_stmt?

Returns true if there is a semicolon between the two locations.

#warn

This method is called when weak warning is produced by the parser.

#warning

This method is called when strong warning is produced by the parser.

#_dispatch_0, #_dispatch_1, #_dispatch_2, #_dispatch_3, #_dispatch_4, #_dispatch_5, #_dispatch_7

Constructor Details

This class inherits a constructor from Prism::Translation::Ripper

Instance Attribute Details

#error (readonly)

[ GitHub ]

  
# File 'lib/prism/translation/ripper/sexp.rb', line 13

attr_reader :error

Instance Method Details

#compile_error(mesg) (private)

Alias for #on_error.

[ GitHub ]

  
# File 'lib/prism/translation/ripper/sexp.rb', line 66

alias compile_error on_error

#dedent_element(e, width) (private)

[ GitHub ]

  
# File 'lib/prism/translation/ripper/sexp.rb', line 17

def dedent_element(e, width)
  if (n = dedent_string(e[1], width)) > 0
    e[2][1] += n
  end
  e
end

#on_error(mesg) (private) Also known as: #on_parse_error, #compile_error

[ GitHub ]

  
# File 'lib/prism/translation/ripper/sexp.rb', line 61

def on_error(mesg)
  @error = mesg
end

#on_heredoc_dedent(val, width) (private)

[ GitHub ]

  
# File 'lib/prism/translation/ripper/sexp.rb', line 24

def on_heredoc_dedent(val, width)
  sub = proc do |cont|
    cont.map! do |e|
      if Array === e
        case e[0]
        when :@tstring_content
          e = dedent_element(e, width)
        when /_add\z/
          e[1] = sub[e[1]]
        end
      elsif String === e
        dedent_string(e, width)
      end
      e
    end
  end
  sub[val]
  val
end

#on_parse_error(mesg) (private)

Alias for #on_error.

[ GitHub ]

  
# File 'lib/prism/translation/ripper/sexp.rb', line 65

alias on_parse_error on_error