prism 1.7.0 → 1.8.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.
@@ -21,7 +21,7 @@ module Prism
21
21
 
22
22
  # The minor version of prism that we are expecting to find in the serialized
23
23
  # strings.
24
- MINOR_VERSION = 7
24
+ MINOR_VERSION = 8
25
25
 
26
26
  # The patch version of prism that we are expecting to find in the serialized
27
27
  # strings.
@@ -16,7 +16,7 @@ module Prism
16
16
  ParserCurrent = Parser41
17
17
  else
18
18
  # Keep this in sync with released Ruby.
19
- parser = Parser34
19
+ parser = Parser40
20
20
  major, minor, _patch = Gem::Version.new(RUBY_VERSION).segments
21
21
  warn "warning: `Prism::Translation::Current` is loading #{parser.name}, " \
22
22
  "but you are running #{major}.#{minor}."
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ # :markup: markdown
3
+
4
+ module Prism
5
+ module Translation
6
+ # This class is the entry-point for Ruby 3.3 of `Prism::Translation::Parser`.
7
+ class Parser33 < Parser
8
+ def version # :nodoc:
9
+ 33
10
+ end
11
+ end
12
+
13
+ # This class is the entry-point for Ruby 3.4 of `Prism::Translation::Parser`.
14
+ class Parser34 < Parser
15
+ def version # :nodoc:
16
+ 34
17
+ end
18
+ end
19
+
20
+ # This class is the entry-point for Ruby 4.0 of `Prism::Translation::Parser`.
21
+ class Parser40 < Parser
22
+ def version # :nodoc:
23
+ 40
24
+ end
25
+ end
26
+
27
+ Parser35 = Parser40 # :nodoc:
28
+
29
+ # This class is the entry-point for Ruby 4.1 of `Prism::Translation::Parser`.
30
+ class Parser41 < Parser
31
+ def version # :nodoc:
32
+ 41
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+ # :markup: markdown
3
+
4
+ require_relative "../ripper"
5
+
6
+ module Prism
7
+ module Translation
8
+ class Ripper
9
+ class Lexer # :nodoc:
10
+ # :stopdoc:
11
+ class State
12
+
13
+ attr_reader :to_int, :to_s
14
+
15
+ def initialize(i)
16
+ @to_int = i
17
+ @to_s = Ripper.lex_state_name(i)
18
+ freeze
19
+ end
20
+
21
+ def [](index)
22
+ case index
23
+ when 0, :to_int
24
+ @to_int
25
+ when 1, :to_s
26
+ @to_s
27
+ else
28
+ nil
29
+ end
30
+ end
31
+
32
+ alias to_i to_int
33
+ alias inspect to_s
34
+ def pretty_print(q) q.text(to_s) end
35
+ def ==(i) super or to_int == i end
36
+ def &(i) self.class.new(to_int & i) end
37
+ def |(i) self.class.new(to_int | i) end
38
+ def allbits?(i) to_int.allbits?(i) end
39
+ def anybits?(i) to_int.anybits?(i) end
40
+ def nobits?(i) to_int.nobits?(i) end
41
+ end
42
+ # :startdoc:
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # :markup: markdown
3
3
 
4
- require "ripper"
5
-
6
4
  module Prism
7
5
  module Translation
8
6
  # This class provides a compatibility layer between prism and Ripper. It
@@ -426,9 +424,34 @@ module Prism
426
424
  end
427
425
  end
428
426
 
427
+ autoload :Lexer, "prism/translation/ripper/lexer"
429
428
  autoload :SexpBuilder, "prism/translation/ripper/sexp"
430
429
  autoload :SexpBuilderPP, "prism/translation/ripper/sexp"
431
430
 
431
+ # :stopdoc:
432
+ # This is not part of the public API but used by some gems.
433
+
434
+ # Ripper-internal bitflags.
435
+ LEX_STATE_NAMES = %i[
436
+ BEG END ENDARG ENDFN ARG CMDARG MID FNAME DOT CLASS LABEL LABELED FITEM
437
+ ].map.with_index.to_h { |name, i| [2 ** i, name] }.freeze
438
+ private_constant :LEX_STATE_NAMES
439
+
440
+ LEX_STATE_NAMES.each do |value, key|
441
+ const_set("EXPR_#{key}", value)
442
+ end
443
+ EXPR_NONE = 0
444
+ EXPR_VALUE = EXPR_BEG
445
+ EXPR_BEG_ANY = EXPR_BEG | EXPR_MID | EXPR_CLASS
446
+ EXPR_ARG_ANY = EXPR_ARG | EXPR_CMDARG
447
+ EXPR_END_ANY = EXPR_END | EXPR_ENDARG | EXPR_ENDFN
448
+
449
+ def self.lex_state_name(state)
450
+ LEX_STATE_NAMES.filter_map { |flag, name| name if state & flag != 0 }.join("|")
451
+ end
452
+
453
+ # :startdoc:
454
+
432
455
  # The source that is being parsed.
433
456
  attr_reader :source
434
457
 
@@ -1422,7 +1422,7 @@ module Prism
1422
1422
  # ```
1423
1423
  def visit_parameters_node(node)
1424
1424
  children =
1425
- node.compact_child_nodes.map do |element|
1425
+ node.each_child_node.map do |element|
1426
1426
  if element.is_a?(MultiTargetNode)
1427
1427
  visit_destructured_parameter(element)
1428
1428
  else
@@ -7,11 +7,11 @@ module Prism
7
7
  module Translation # steep:ignore
8
8
  autoload :Parser, "prism/translation/parser"
9
9
  autoload :ParserCurrent, "prism/translation/parser_current"
10
- autoload :Parser33, "prism/translation/parser33"
11
- autoload :Parser34, "prism/translation/parser34"
12
- autoload :Parser35, "prism/translation/parser35"
13
- autoload :Parser40, "prism/translation/parser40"
14
- autoload :Parser41, "prism/translation/parser41"
10
+ autoload :Parser33, "prism/translation/parser_versions"
11
+ autoload :Parser34, "prism/translation/parser_versions"
12
+ autoload :Parser35, "prism/translation/parser_versions"
13
+ autoload :Parser40, "prism/translation/parser_versions"
14
+ autoload :Parser41, "prism/translation/parser_versions"
15
15
  autoload :Ripper, "prism/translation/ripper"
16
16
  autoload :RubyParser, "prism/translation/ruby_parser"
17
17
  end