prism 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,8 +58,6 @@ module Prism
58
58
 
59
59
  # Walk the tree and mark nodes that are on a new line.
60
60
  def mark_newlines!
61
- value = self.value
62
- raise "This method should only be called on a parse result that contains a node" unless Node === value
63
61
  value.accept(Newlines.new(Array.new(1 + source.offsets.size, false))) # steep:ignore
64
62
  end
65
63
  end
@@ -438,14 +438,9 @@ module Prism
438
438
  end
439
439
 
440
440
  # This represents the result of a call to ::parse or ::parse_file. It contains
441
- # the AST, any comments that were encounters, and any errors that were
442
- # encountered.
443
- class ParseResult
444
- # The value that was generated by parsing. Normally this holds the AST, but
445
- # it can sometimes how a list of tokens or other results passed back from
446
- # the parser.
447
- attr_reader :value
448
-
441
+ # the requested structure, any comments that were encounters, and any errors
442
+ # that were encountered.
443
+ class Result
449
444
  # The list of comments that were encountered during parsing.
450
445
  attr_reader :comments
451
446
 
@@ -466,9 +461,8 @@ module Prism
466
461
  # A Source instance that represents the source code that was parsed.
467
462
  attr_reader :source
468
463
 
469
- # Create a new parse result object with the given values.
470
- def initialize(value, comments, magic_comments, data_loc, errors, warnings, source)
471
- @value = value
464
+ # Create a new result object with the given values.
465
+ def initialize(comments, magic_comments, data_loc, errors, warnings, source)
472
466
  @comments = comments
473
467
  @magic_comments = magic_comments
474
468
  @data_loc = data_loc
@@ -477,9 +471,9 @@ module Prism
477
471
  @source = source
478
472
  end
479
473
 
480
- # Implement the hash pattern matching interface for ParseResult.
474
+ # Implement the hash pattern matching interface for Result.
481
475
  def deconstruct_keys(keys)
482
- { value: value, comments: comments, magic_comments: magic_comments, data_loc: data_loc, errors: errors, warnings: warnings }
476
+ { comments: comments, magic_comments: magic_comments, data_loc: data_loc, errors: errors, warnings: warnings }
483
477
  end
484
478
 
485
479
  # Returns the encoding of the source code that was parsed.
@@ -500,6 +494,58 @@ module Prism
500
494
  end
501
495
  end
502
496
 
497
+ # This is a result specific to the `parse` and `parse_file` methods.
498
+ class ParseResult < Result
499
+ # The syntax tree that was parsed from the source code.
500
+ attr_reader :value
501
+
502
+ # Create a new parse result object with the given values.
503
+ def initialize(value, comments, magic_comments, data_loc, errors, warnings, source)
504
+ @value = value
505
+ super(comments, magic_comments, data_loc, errors, warnings, source)
506
+ end
507
+
508
+ # Implement the hash pattern matching interface for ParseResult.
509
+ def deconstruct_keys(keys)
510
+ super.merge!(value: value)
511
+ end
512
+ end
513
+
514
+ # This is a result specific to the `lex` and `lex_file` methods.
515
+ class LexResult < Result
516
+ # The list of tokens that were parsed from the source code.
517
+ attr_reader :value
518
+
519
+ # Create a new lex result object with the given values.
520
+ def initialize(value, comments, magic_comments, data_loc, errors, warnings, source)
521
+ @value = value
522
+ super(comments, magic_comments, data_loc, errors, warnings, source)
523
+ end
524
+
525
+ # Implement the hash pattern matching interface for LexResult.
526
+ def deconstruct_keys(keys)
527
+ super.merge!(value: value)
528
+ end
529
+ end
530
+
531
+ # This is a result specific to the `parse_lex` and `parse_lex_file` methods.
532
+ class ParseLexResult < Result
533
+ # A tuple of the syntax tree and the list of tokens that were parsed from
534
+ # the source code.
535
+ attr_reader :value
536
+
537
+ # Create a new parse lex result object with the given values.
538
+ def initialize(value, comments, magic_comments, data_loc, errors, warnings, source)
539
+ @value = value
540
+ super(comments, magic_comments, data_loc, errors, warnings, source)
541
+ end
542
+
543
+ # Implement the hash pattern matching interface for ParseLexResult.
544
+ def deconstruct_keys(keys)
545
+ super.merge!(value: value)
546
+ end
547
+ end
548
+
503
549
  # This represents a token from the Ruby source.
504
550
  class Token
505
551
  # The Source object that represents the source this token came from.
@@ -73,14 +73,16 @@ module Prism
73
73
  class OptionalLocationField < Field
74
74
  end
75
75
 
76
- # A uint8 field represents an unsigned 8-bit integer value on a node. It
77
- # resolves to an Integer in Ruby.
78
- class UInt8Field < Field
76
+ # An integer field represents an integer value. It is used to represent the
77
+ # value of an integer literal, the depth of local variables, and the number
78
+ # of a numbered reference. It resolves to an Integer in Ruby.
79
+ class IntegerField < Field
79
80
  end
80
81
 
81
- # A uint32 field represents an unsigned 32-bit integer value on a node. It
82
- # resolves to an Integer in Ruby.
83
- class UInt32Field < Field
82
+ # A float field represents a double-precision floating point value. It is
83
+ # used exclusively to represent the value of a floating point literal. It
84
+ # resolves to a Float in Ruby.
85
+ class FloatField < Field
84
86
  end
85
87
 
86
88
  # A flags field represents a bitset of flags on a node. It resolves to an
@@ -98,18 +100,6 @@ module Prism
98
100
  end
99
101
  end
100
102
 
101
- # An integer field represents an arbitrarily-sized integer value. It is used
102
- # exclusively to represent the value of an integer literal. It resolves to
103
- # an Integer in Ruby.
104
- class IntegerField < Field
105
- end
106
-
107
- # A double field represents a double-precision floating point value. It is
108
- # used exclusively to represent the value of a floating point literal. It
109
- # resolves to a Float in Ruby.
110
- class DoubleField < Field
111
- end
112
-
113
103
  # Returns the fields for the given node.
114
104
  def self.fields_for(node)
115
105
  case node.type
@@ -220,7 +210,7 @@ module Prism
220
210
  when :flip_flop_node
221
211
  [FlagsField.new(:flags, [:exclude_end?]), OptionalNodeField.new(:left), OptionalNodeField.new(:right), LocationField.new(:operator_loc)]
222
212
  when :float_node
223
- [DoubleField.new(:value)]
213
+ [FloatField.new(:value)]
224
214
  when :for_node
225
215
  [NodeField.new(:index), NodeField.new(:collection), OptionalNodeField.new(:statements), LocationField.new(:for_keyword_loc), LocationField.new(:in_keyword_loc), OptionalLocationField.new(:do_keyword_loc), LocationField.new(:end_keyword_loc)]
226
216
  when :forwarding_arguments_node
@@ -276,7 +266,7 @@ module Prism
276
266
  when :instance_variable_write_node
277
267
  [ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
278
268
  when :integer_node
279
- [FlagsField.new(:flags, [:binary?, :decimal?, :octal?, :hexadecimal?]), IntegerField.new(:value)]
269
+ [FlagsField.new(:flags, [:binary?, :decimal?, :octal?, :hexadecimal?]), Integer.new(:value)]
280
270
  when :interpolated_match_last_line_node
281
271
  [FlagsField.new(:flags, [:ignore_case?, :extended?, :multi_line?, :once?, :euc_jp?, :ascii_8bit?, :windows_31j?, :utf_8?, :forced_utf8_encoding?, :forced_binary_encoding?, :forced_us_ascii_encoding?]), LocationField.new(:opening_loc), NodeListField.new(:parts), LocationField.new(:closing_loc)]
282
272
  when :interpolated_regular_expression_node
@@ -296,17 +286,17 @@ module Prism
296
286
  when :lambda_node
297
287
  [ConstantListField.new(:locals), LocationField.new(:operator_loc), LocationField.new(:opening_loc), LocationField.new(:closing_loc), OptionalNodeField.new(:parameters), OptionalNodeField.new(:body)]
298
288
  when :local_variable_and_write_node
299
- [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), UInt32Field.new(:depth)]
289
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), Integer.new(:depth)]
300
290
  when :local_variable_operator_write_node
301
- [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), ConstantField.new(:operator), UInt32Field.new(:depth)]
291
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), ConstantField.new(:operator), Integer.new(:depth)]
302
292
  when :local_variable_or_write_node
303
- [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), UInt32Field.new(:depth)]
293
+ [LocationField.new(:name_loc), LocationField.new(:operator_loc), NodeField.new(:value), ConstantField.new(:name), Integer.new(:depth)]
304
294
  when :local_variable_read_node
305
- [ConstantField.new(:name), UInt32Field.new(:depth)]
295
+ [ConstantField.new(:name), Integer.new(:depth)]
306
296
  when :local_variable_target_node
307
- [ConstantField.new(:name), UInt32Field.new(:depth)]
297
+ [ConstantField.new(:name), Integer.new(:depth)]
308
298
  when :local_variable_write_node
309
- [ConstantField.new(:name), UInt32Field.new(:depth), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
299
+ [ConstantField.new(:name), Integer.new(:depth), LocationField.new(:name_loc), NodeField.new(:value), LocationField.new(:operator_loc)]
310
300
  when :match_last_line_node
311
301
  [FlagsField.new(:flags, [:ignore_case?, :extended?, :multi_line?, :once?, :euc_jp?, :ascii_8bit?, :windows_31j?, :utf_8?, :forced_utf8_encoding?, :forced_binary_encoding?, :forced_us_ascii_encoding?]), LocationField.new(:opening_loc), LocationField.new(:content_loc), LocationField.new(:closing_loc), StringField.new(:unescaped)]
312
302
  when :match_predicate_node
@@ -330,9 +320,9 @@ module Prism
330
320
  when :no_keywords_parameter_node
331
321
  [LocationField.new(:operator_loc), LocationField.new(:keyword_loc)]
332
322
  when :numbered_parameters_node
333
- [UInt8Field.new(:maximum)]
323
+ [Integer.new(:maximum)]
334
324
  when :numbered_reference_read_node
335
- [UInt32Field.new(:number)]
325
+ [Integer.new(:number)]
336
326
  when :optional_keyword_parameter_node
337
327
  [FlagsField.new(:flags, [:repeated_parameter?]), ConstantField.new(:name), LocationField.new(:name_loc), NodeField.new(:value)]
338
328
  when :optional_parameter_node
@@ -18,7 +18,7 @@ module Prism
18
18
 
19
19
  # The minor version of prism that we are expecting to find in the serialized
20
20
  # strings.
21
- MINOR_VERSION = 26
21
+ MINOR_VERSION = 27
22
22
 
23
23
  # The patch version of prism that we are expecting to find in the serialized
24
24
  # strings.
@@ -260,6 +260,8 @@ module Prism
260
260
  :invalid_character,
261
261
  :invalid_encoding_magic_comment,
262
262
  :invalid_float_exponent,
263
+ :invalid_local_variable_read,
264
+ :invalid_local_variable_write,
263
265
  :invalid_multibyte_char,
264
266
  :invalid_multibyte_character,
265
267
  :invalid_multibyte_escape,
@@ -332,6 +334,7 @@ module Prism
332
334
  :pattern_hash_key,
333
335
  :pattern_hash_key_duplicate,
334
336
  :pattern_hash_key_label,
337
+ :pattern_hash_key_locals,
335
338
  :pattern_ident_after_hrocket,
336
339
  :pattern_label_after_comma,
337
340
  :pattern_rest,
@@ -426,7 +429,7 @@ module Prism
426
429
  length = load_varuint
427
430
  lex_state = load_varuint
428
431
  location = Location.new(@source, start, length)
429
- tokens << [Prism::Token.new(source, type, location.slice, location), lex_state]
432
+ tokens << [Token.new(source, type, location.slice, location), lex_state]
430
433
  end
431
434
 
432
435
  tokens
@@ -441,7 +444,7 @@ module Prism
441
444
  tokens.each { |token,| token.value.force_encoding(encoding) }
442
445
 
443
446
  raise "Expected to consume all bytes while deserializing" unless @io.eof?
444
- Prism::ParseResult.new(tokens, comments, magic_comments, data_loc, errors, warnings, @source)
447
+ LexResult.new(tokens, comments, magic_comments, data_loc, errors, warnings, @source)
445
448
  end
446
449
 
447
450
  def load_nodes
@@ -460,7 +463,7 @@ module Prism
460
463
 
461
464
  def load_result
462
465
  node, comments, magic_comments, data_loc, errors, warnings = load_nodes
463
- Prism::ParseResult.new(node, comments, magic_comments, data_loc, errors, warnings, @source)
466
+ ParseResult.new(node, comments, magic_comments, data_loc, errors, warnings, @source)
464
467
  end
465
468
 
466
469
  private
@@ -839,7 +839,7 @@ module Prism
839
839
  token(node.in_loc),
840
840
  pattern,
841
841
  guard,
842
- srange_find(node.pattern.location.end_offset, node.statements&.location&.start_offset || node.location.end_offset, [";", "then"]),
842
+ srange_find(node.pattern.location.end_offset, node.statements&.location&.start_offset, [";", "then"]),
843
843
  visit(node.statements)
844
844
  )
845
845
  end
@@ -1030,6 +1030,12 @@ module Prism
1030
1030
  end
1031
1031
  end
1032
1032
 
1033
+ # -> { it }
1034
+ # ^^^^^^^^^
1035
+ def visit_it_parameters_node(node)
1036
+ builder.args(nil, [], nil, false)
1037
+ end
1038
+
1033
1039
  # foo(bar: baz)
1034
1040
  # ^^^^^^^^
1035
1041
  def visit_keyword_hash_node(node)
@@ -1052,13 +1058,14 @@ module Prism
1052
1058
  # ^^^^^
1053
1059
  def visit_lambda_node(node)
1054
1060
  parameters = node.parameters
1061
+ implicit_parameters = parameters.is_a?(NumberedParametersNode) || parameters.is_a?(ItParametersNode)
1055
1062
 
1056
1063
  builder.block(
1057
1064
  builder.call_lambda(token(node.operator_loc)),
1058
1065
  [node.opening, srange(node.opening_loc)],
1059
1066
  if parameters.nil?
1060
1067
  builder.args(nil, [], nil, false)
1061
- elsif node.parameters.is_a?(NumberedParametersNode)
1068
+ elsif implicit_parameters
1062
1069
  visit(node.parameters)
1063
1070
  else
1064
1071
  builder.args(
@@ -1068,7 +1075,7 @@ module Prism
1068
1075
  false
1069
1076
  )
1070
1077
  end,
1071
- node.body&.accept(copy_compiler(forwarding: parameters.is_a?(NumberedParametersNode) ? [] : find_forwarding(parameters&.parameters))),
1078
+ node.body&.accept(copy_compiler(forwarding: implicit_parameters ? [] : find_forwarding(parameters&.parameters))),
1072
1079
  [node.closing, srange(node.closing_loc)]
1073
1080
  )
1074
1081
  end
@@ -1076,7 +1083,14 @@ module Prism
1076
1083
  # foo
1077
1084
  # ^^^
1078
1085
  def visit_local_variable_read_node(node)
1079
- builder.ident([node.name, srange(node.location)]).updated(:lvar)
1086
+ name = node.name
1087
+
1088
+ # This is just a guess. parser doesn't have support for the implicit
1089
+ # `it` variable yet, so we'll probably have to visit this once it
1090
+ # does.
1091
+ name = :it if name == :"0it"
1092
+
1093
+ builder.ident([name, srange(node.location)]).updated(:lvar)
1080
1094
  end
1081
1095
 
1082
1096
  # foo = 1
@@ -1665,7 +1679,7 @@ module Prism
1665
1679
  end
1666
1680
 
1667
1681
  # until foo; bar end
1668
- # ^^^^^^^^^^^^^^^^^
1682
+ # ^^^^^^^^^^^^^^^^^^
1669
1683
  #
1670
1684
  # bar until foo
1671
1685
  # ^^^^^^^^^^^^^
@@ -1698,7 +1712,7 @@ module Prism
1698
1712
  if node.then_keyword_loc
1699
1713
  token(node.then_keyword_loc)
1700
1714
  else
1701
- srange_find(node.conditions.last.location.end_offset, node.statements&.location&.start_offset || (node.conditions.last.location.end_offset + 1), [";"])
1715
+ srange_find(node.conditions.last.location.end_offset, node.statements&.location&.start_offset, [";"])
1702
1716
  end,
1703
1717
  visit(node.statements)
1704
1718
  )
@@ -1857,12 +1871,16 @@ module Prism
1857
1871
 
1858
1872
  # Constructs a new source range by finding the given tokens between the
1859
1873
  # given start offset and end offset. If the needle is not found, it
1860
- # returns nil.
1874
+ # returns nil. Importantly it does not search past newlines or comments.
1875
+ #
1876
+ # Note that end_offset is allowed to be nil, in which case this will
1877
+ # search until the end of the string.
1861
1878
  def srange_find(start_offset, end_offset, tokens)
1862
- tokens.find do |token|
1863
- next unless (index = source_buffer.source.byteslice(start_offset...end_offset).index(token))
1864
- offset = start_offset + index
1865
- return [token, Range.new(source_buffer, offset_cache[offset], offset_cache[offset + token.length])]
1879
+ if (match = source_buffer.source.byteslice(start_offset...end_offset).match(/(\s*)(#{tokens.join("|")})/))
1880
+ _, whitespace, token = *match
1881
+ token_offset = start_offset + whitespace.bytesize
1882
+
1883
+ [token, Range.new(source_buffer, offset_cache[token_offset], offset_cache[token_offset + token.bytesize])]
1866
1884
  end
1867
1885
  end
1868
1886
 
@@ -1875,13 +1893,14 @@ module Prism
1875
1893
  def visit_block(call, block)
1876
1894
  if block
1877
1895
  parameters = block.parameters
1896
+ implicit_parameters = parameters.is_a?(NumberedParametersNode) || parameters.is_a?(ItParametersNode)
1878
1897
 
1879
1898
  builder.block(
1880
1899
  call,
1881
1900
  token(block.opening_loc),
1882
1901
  if parameters.nil?
1883
1902
  builder.args(nil, [], nil, false)
1884
- elsif parameters.is_a?(NumberedParametersNode)
1903
+ elsif implicit_parameters
1885
1904
  visit(parameters)
1886
1905
  else
1887
1906
  builder.args(
@@ -1896,7 +1915,7 @@ module Prism
1896
1915
  false
1897
1916
  )
1898
1917
  end,
1899
- block.body&.accept(copy_compiler(forwarding: parameters.is_a?(NumberedParametersNode) ? [] : find_forwarding(parameters&.parameters))),
1918
+ block.body&.accept(copy_compiler(forwarding: implicit_parameters ? [] : find_forwarding(parameters&.parameters))),
1900
1919
  token(block.closing_loc)
1901
1920
  )
1902
1921
  else
@@ -19,31 +19,31 @@ module Prism
19
19
  # The main known difference is that we may omit dispatching some events in
20
20
  # some cases. This impacts the following events:
21
21
  #
22
- # * on_assign_error
23
- # * on_comma
24
- # * on_ignored_nl
25
- # * on_ignored_sp
26
- # * on_kw
27
- # * on_label_end
28
- # * on_lbrace
29
- # * on_lbracket
30
- # * on_lparen
31
- # * on_nl
32
- # * on_op
33
- # * on_operator_ambiguous
34
- # * on_rbrace
35
- # * on_rbracket
36
- # * on_rparen
37
- # * on_semicolon
38
- # * on_sp
39
- # * on_symbeg
40
- # * on_tstring_beg
41
- # * on_tstring_end
22
+ # - on_assign_error
23
+ # - on_comma
24
+ # - on_ignored_nl
25
+ # - on_ignored_sp
26
+ # - on_kw
27
+ # - on_label_end
28
+ # - on_lbrace
29
+ # - on_lbracket
30
+ # - on_lparen
31
+ # - on_nl
32
+ # - on_op
33
+ # - on_operator_ambiguous
34
+ # - on_rbrace
35
+ # - on_rbracket
36
+ # - on_rparen
37
+ # - on_semicolon
38
+ # - on_sp
39
+ # - on_symbeg
40
+ # - on_tstring_beg
41
+ # - on_tstring_end
42
42
  #
43
43
  class Ripper < Compiler
44
44
  # Parses the given Ruby program read from +src+.
45
45
  # +src+ must be a String or an IO or a object with a #gets method.
46
- def Ripper.parse(src, filename = "(ripper)", lineno = 1)
46
+ def self.parse(src, filename = "(ripper)", lineno = 1)
47
47
  new(src, filename, lineno).parse
48
48
  end
49
49
 
@@ -54,22 +54,22 @@ module Prism
54
54
  # By default, this method does not handle syntax errors in +src+,
55
55
  # use the +raise_errors+ keyword to raise a SyntaxError for an error in +src+.
56
56
  #
57
- # require 'ripper'
58
- # require 'pp'
57
+ # require "ripper"
58
+ # require "pp"
59
59
  #
60
- # pp Ripper.lex("def m(a) nil end")
61
- # #=> [[[1, 0], :on_kw, "def", FNAME ],
62
- # [[1, 3], :on_sp, " ", FNAME ],
63
- # [[1, 4], :on_ident, "m", ENDFN ],
64
- # [[1, 5], :on_lparen, "(", BEG|LABEL],
65
- # [[1, 6], :on_ident, "a", ARG ],
66
- # [[1, 7], :on_rparen, ")", ENDFN ],
67
- # [[1, 8], :on_sp, " ", BEG ],
68
- # [[1, 9], :on_kw, "nil", END ],
69
- # [[1, 12], :on_sp, " ", END ],
70
- # [[1, 13], :on_kw, "end", END ]]
60
+ # pp Ripper.lex("def m(a) nil end")
61
+ # #=> [[[1, 0], :on_kw, "def", FNAME ],
62
+ # [[1, 3], :on_sp, " ", FNAME ],
63
+ # [[1, 4], :on_ident, "m", ENDFN ],
64
+ # [[1, 5], :on_lparen, "(", BEG|LABEL],
65
+ # [[1, 6], :on_ident, "a", ARG ],
66
+ # [[1, 7], :on_rparen, ")", ENDFN ],
67
+ # [[1, 8], :on_sp, " ", BEG ],
68
+ # [[1, 9], :on_kw, "nil", END ],
69
+ # [[1, 12], :on_sp, " ", END ],
70
+ # [[1, 13], :on_kw, "end", END ]]
71
71
  #
72
- def Ripper.lex(src, filename = "-", lineno = 1, raise_errors: false)
72
+ def self.lex(src, filename = "-", lineno = 1, raise_errors: false)
73
73
  result = Prism.lex_compat(src, filepath: filename, line: lineno)
74
74
 
75
75
  if result.failure? && raise_errors
@@ -368,17 +368,17 @@ module Prism
368
368
  # returning +nil+ in such cases. Use the +raise_errors+ keyword
369
369
  # to raise a SyntaxError for an error in +src+.
370
370
  #
371
- # require "ripper"
372
- # require "pp"
371
+ # require "ripper"
372
+ # require "pp"
373
373
  #
374
- # pp Ripper.sexp("def m(a) nil end")
375
- # #=> [:program,
376
- # [[:def,
377
- # [:@ident, "m", [1, 4]],
378
- # [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil, nil, nil, nil]],
379
- # [:bodystmt, [[:var_ref, [:@kw, "nil", [1, 9]]]], nil, nil, nil]]]]
374
+ # pp Ripper.sexp("def m(a) nil end")
375
+ # #=> [:program,
376
+ # [[:def,
377
+ # [:@ident, "m", [1, 4]],
378
+ # [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil, nil, nil, nil]],
379
+ # [:bodystmt, [[:var_ref, [:@kw, "nil", [1, 9]]]], nil, nil, nil]]]]
380
380
  #
381
- def Ripper.sexp(src, filename = "-", lineno = 1, raise_errors: false)
381
+ def self.sexp(src, filename = "-", lineno = 1, raise_errors: false)
382
382
  builder = SexpBuilderPP.new(src, filename, lineno)
383
383
  sexp = builder.parse
384
384
  if builder.error?
@@ -397,23 +397,23 @@ module Prism
397
397
  # returning +nil+ in such cases. Use the +raise_errors+ keyword
398
398
  # to raise a SyntaxError for an error in +src+.
399
399
  #
400
- # require 'ripper'
401
- # require 'pp'
400
+ # require "ripper"
401
+ # require "pp"
402
402
  #
403
- # pp Ripper.sexp_raw("def m(a) nil end")
404
- # #=> [:program,
405
- # [:stmts_add,
406
- # [:stmts_new],
407
- # [:def,
408
- # [:@ident, "m", [1, 4]],
409
- # [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil]],
410
- # [:bodystmt,
411
- # [:stmts_add, [:stmts_new], [:var_ref, [:@kw, "nil", [1, 9]]]],
412
- # nil,
413
- # nil,
414
- # nil]]]]
403
+ # pp Ripper.sexp_raw("def m(a) nil end")
404
+ # #=> [:program,
405
+ # [:stmts_add,
406
+ # [:stmts_new],
407
+ # [:def,
408
+ # [:@ident, "m", [1, 4]],
409
+ # [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil]],
410
+ # [:bodystmt,
411
+ # [:stmts_add, [:stmts_new], [:var_ref, [:@kw, "nil", [1, 9]]]],
412
+ # nil,
413
+ # nil,
414
+ # nil]]]]
415
415
  #
416
- def Ripper.sexp_raw(src, filename = "-", lineno = 1, raise_errors: false)
416
+ def self.sexp_raw(src, filename = "-", lineno = 1, raise_errors: false)
417
417
  builder = SexpBuilder.new(src, filename, lineno)
418
418
  sexp = builder.parse
419
419
  if builder.error?