jruby-prism-parser 0.24.0-java → 1.4.0-java

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.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +269 -1
  4. data/CONTRIBUTING.md +0 -4
  5. data/Makefile +25 -18
  6. data/README.md +57 -6
  7. data/config.yml +1724 -140
  8. data/docs/build_system.md +39 -11
  9. data/docs/configuration.md +4 -0
  10. data/docs/cruby_compilation.md +1 -1
  11. data/docs/fuzzing.md +1 -1
  12. data/docs/parser_translation.md +14 -9
  13. data/docs/parsing_rules.md +4 -1
  14. data/docs/releasing.md +8 -10
  15. data/docs/relocation.md +34 -0
  16. data/docs/ripper_translation.md +72 -0
  17. data/docs/ruby_api.md +2 -1
  18. data/docs/serialization.md +29 -5
  19. data/ext/prism/api_node.c +3395 -1999
  20. data/ext/prism/api_pack.c +9 -0
  21. data/ext/prism/extconf.rb +55 -34
  22. data/ext/prism/extension.c +597 -346
  23. data/ext/prism/extension.h +6 -5
  24. data/include/prism/ast.h +2612 -455
  25. data/include/prism/defines.h +160 -2
  26. data/include/prism/diagnostic.h +188 -76
  27. data/include/prism/encoding.h +22 -4
  28. data/include/prism/node.h +89 -17
  29. data/include/prism/options.h +224 -12
  30. data/include/prism/pack.h +11 -0
  31. data/include/prism/parser.h +267 -66
  32. data/include/prism/prettyprint.h +8 -0
  33. data/include/prism/regexp.h +18 -8
  34. data/include/prism/static_literals.h +121 -0
  35. data/include/prism/util/pm_buffer.h +75 -2
  36. data/include/prism/util/pm_char.h +1 -2
  37. data/include/prism/util/pm_constant_pool.h +18 -9
  38. data/include/prism/util/pm_integer.h +126 -0
  39. data/include/prism/util/pm_list.h +1 -1
  40. data/include/prism/util/pm_newline_list.h +19 -0
  41. data/include/prism/util/pm_string.h +48 -8
  42. data/include/prism/version.h +3 -3
  43. data/include/prism.h +99 -5
  44. data/jruby-prism.jar +0 -0
  45. data/lib/prism/compiler.rb +11 -1
  46. data/lib/prism/desugar_compiler.rb +113 -74
  47. data/lib/prism/dispatcher.rb +45 -1
  48. data/lib/prism/dot_visitor.rb +201 -77
  49. data/lib/prism/dsl.rb +673 -461
  50. data/lib/prism/ffi.rb +233 -45
  51. data/lib/prism/inspect_visitor.rb +2389 -0
  52. data/lib/prism/lex_compat.rb +35 -16
  53. data/lib/prism/mutation_compiler.rb +24 -8
  54. data/lib/prism/node.rb +7731 -8460
  55. data/lib/prism/node_ext.rb +328 -32
  56. data/lib/prism/pack.rb +4 -0
  57. data/lib/prism/parse_result/comments.rb +34 -24
  58. data/lib/prism/parse_result/errors.rb +65 -0
  59. data/lib/prism/parse_result/newlines.rb +102 -12
  60. data/lib/prism/parse_result.rb +448 -44
  61. data/lib/prism/pattern.rb +28 -10
  62. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  63. data/lib/prism/polyfill/byteindex.rb +13 -0
  64. data/lib/prism/polyfill/unpack1.rb +14 -0
  65. data/lib/prism/reflection.rb +413 -0
  66. data/lib/prism/relocation.rb +504 -0
  67. data/lib/prism/serialize.rb +1940 -1198
  68. data/lib/prism/string_query.rb +30 -0
  69. data/lib/prism/translation/parser/builder.rb +61 -0
  70. data/lib/prism/translation/parser/compiler.rb +569 -195
  71. data/lib/prism/translation/parser/lexer.rb +516 -39
  72. data/lib/prism/translation/parser.rb +177 -12
  73. data/lib/prism/translation/parser33.rb +1 -1
  74. data/lib/prism/translation/parser34.rb +1 -1
  75. data/lib/prism/translation/parser35.rb +12 -0
  76. data/lib/prism/translation/ripper/sexp.rb +125 -0
  77. data/lib/prism/translation/ripper/shim.rb +5 -0
  78. data/lib/prism/translation/ripper.rb +3224 -462
  79. data/lib/prism/translation/ruby_parser.rb +194 -69
  80. data/lib/prism/translation.rb +4 -1
  81. data/lib/prism/version.rb +1 -1
  82. data/lib/prism/visitor.rb +13 -0
  83. data/lib/prism.rb +17 -27
  84. data/prism.gemspec +57 -17
  85. data/rbi/prism/compiler.rbi +12 -0
  86. data/rbi/prism/dsl.rbi +524 -0
  87. data/rbi/prism/inspect_visitor.rbi +12 -0
  88. data/rbi/prism/node.rbi +8722 -0
  89. data/rbi/prism/node_ext.rbi +107 -0
  90. data/rbi/prism/parse_result.rbi +404 -0
  91. data/rbi/prism/reflection.rbi +58 -0
  92. data/rbi/prism/string_query.rbi +12 -0
  93. data/rbi/prism/translation/parser.rbi +11 -0
  94. data/rbi/prism/translation/parser33.rbi +6 -0
  95. data/rbi/prism/translation/parser34.rbi +6 -0
  96. data/rbi/prism/translation/parser35.rbi +6 -0
  97. data/rbi/prism/translation/ripper.rbi +15 -0
  98. data/rbi/prism/visitor.rbi +473 -0
  99. data/rbi/prism.rbi +44 -7745
  100. data/sig/prism/compiler.rbs +9 -0
  101. data/sig/prism/dispatcher.rbs +16 -0
  102. data/sig/prism/dot_visitor.rbs +6 -0
  103. data/sig/prism/dsl.rbs +351 -0
  104. data/sig/prism/inspect_visitor.rbs +22 -0
  105. data/sig/prism/lex_compat.rbs +10 -0
  106. data/sig/prism/mutation_compiler.rbs +159 -0
  107. data/sig/prism/node.rbs +3614 -0
  108. data/sig/prism/node_ext.rbs +82 -0
  109. data/sig/prism/pack.rbs +43 -0
  110. data/sig/prism/parse_result.rbs +192 -0
  111. data/sig/prism/pattern.rbs +13 -0
  112. data/sig/prism/reflection.rbs +50 -0
  113. data/sig/prism/relocation.rbs +185 -0
  114. data/sig/prism/serialize.rbs +8 -0
  115. data/sig/prism/string_query.rbs +11 -0
  116. data/sig/prism/visitor.rbs +169 -0
  117. data/sig/prism.rbs +248 -4767
  118. data/src/diagnostic.c +672 -230
  119. data/src/encoding.c +211 -108
  120. data/src/node.c +7541 -1653
  121. data/src/options.c +135 -20
  122. data/src/pack.c +33 -17
  123. data/src/prettyprint.c +1543 -1485
  124. data/src/prism.c +7813 -3050
  125. data/src/regexp.c +225 -73
  126. data/src/serialize.c +101 -77
  127. data/src/static_literals.c +617 -0
  128. data/src/token_type.c +14 -13
  129. data/src/util/pm_buffer.c +187 -20
  130. data/src/util/pm_char.c +5 -5
  131. data/src/util/pm_constant_pool.c +39 -19
  132. data/src/util/pm_integer.c +670 -0
  133. data/src/util/pm_list.c +1 -1
  134. data/src/util/pm_newline_list.c +43 -5
  135. data/src/util/pm_string.c +213 -33
  136. data/src/util/pm_strncasecmp.c +13 -1
  137. data/src/util/pm_strpbrk.c +32 -6
  138. metadata +55 -19
  139. data/docs/ripper.md +0 -36
  140. data/include/prism/util/pm_state_stack.h +0 -42
  141. data/include/prism/util/pm_string_list.h +0 -44
  142. data/lib/prism/debug.rb +0 -206
  143. data/lib/prism/node_inspector.rb +0 -68
  144. data/lib/prism/translation/parser/rubocop.rb +0 -45
  145. data/rbi/prism_static.rbi +0 -207
  146. data/sig/prism_static.rbs +0 -201
  147. data/src/util/pm_state_stack.c +0 -25
  148. data/src/util/pm_string_list.c +0 -28
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby-prism-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.0
4
+ version: 1.4.0
5
5
  platform: java
6
6
  authors:
7
7
  - JRuby Team
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-02-23 00:00:00.000000000 Z
10
+ date: 2025-03-27 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
14
12
  email:
15
13
  - admin@jruby.org
16
14
  executables: []
@@ -18,6 +16,7 @@ extensions:
18
16
  - ext/prism/extconf.rb
19
17
  extra_rdoc_files: []
20
18
  files:
19
+ - BSDmakefile
21
20
  - CHANGELOG.md
22
21
  - CODE_OF_CONDUCT.md
23
22
  - CONTRIBUTING.md
@@ -38,7 +37,8 @@ files:
38
37
  - docs/parser_translation.md
39
38
  - docs/parsing_rules.md
40
39
  - docs/releasing.md
41
- - docs/ripper.md
40
+ - docs/relocation.md
41
+ - docs/ripper_translation.md
42
42
  - docs/ruby_api.md
43
43
  - docs/ruby_parser_translation.md
44
44
  - docs/serialization.md
@@ -59,54 +59,92 @@ files:
59
59
  - include/prism/parser.h
60
60
  - include/prism/prettyprint.h
61
61
  - include/prism/regexp.h
62
+ - include/prism/static_literals.h
62
63
  - include/prism/util/pm_buffer.h
63
64
  - include/prism/util/pm_char.h
64
65
  - include/prism/util/pm_constant_pool.h
66
+ - include/prism/util/pm_integer.h
65
67
  - include/prism/util/pm_list.h
66
68
  - include/prism/util/pm_memchr.h
67
69
  - include/prism/util/pm_newline_list.h
68
- - include/prism/util/pm_state_stack.h
69
70
  - include/prism/util/pm_string.h
70
- - include/prism/util/pm_string_list.h
71
71
  - include/prism/util/pm_strncasecmp.h
72
72
  - include/prism/util/pm_strpbrk.h
73
73
  - include/prism/version.h
74
74
  - jruby-prism.jar
75
75
  - lib/prism.rb
76
76
  - lib/prism/compiler.rb
77
- - lib/prism/debug.rb
78
77
  - lib/prism/desugar_compiler.rb
79
78
  - lib/prism/dispatcher.rb
80
79
  - lib/prism/dot_visitor.rb
81
80
  - lib/prism/dsl.rb
82
81
  - lib/prism/ffi.rb
82
+ - lib/prism/inspect_visitor.rb
83
83
  - lib/prism/lex_compat.rb
84
84
  - lib/prism/mutation_compiler.rb
85
85
  - lib/prism/node.rb
86
86
  - lib/prism/node_ext.rb
87
- - lib/prism/node_inspector.rb
88
87
  - lib/prism/pack.rb
89
88
  - lib/prism/parse_result.rb
90
89
  - lib/prism/parse_result/comments.rb
90
+ - lib/prism/parse_result/errors.rb
91
91
  - lib/prism/parse_result/newlines.rb
92
92
  - lib/prism/pattern.rb
93
+ - lib/prism/polyfill/append_as_bytes.rb
94
+ - lib/prism/polyfill/byteindex.rb
95
+ - lib/prism/polyfill/unpack1.rb
96
+ - lib/prism/reflection.rb
97
+ - lib/prism/relocation.rb
93
98
  - lib/prism/serialize.rb
99
+ - lib/prism/string_query.rb
94
100
  - lib/prism/translation.rb
95
101
  - lib/prism/translation/parser.rb
102
+ - lib/prism/translation/parser/builder.rb
96
103
  - lib/prism/translation/parser/compiler.rb
97
104
  - lib/prism/translation/parser/lexer.rb
98
- - lib/prism/translation/parser/rubocop.rb
99
105
  - lib/prism/translation/parser33.rb
100
106
  - lib/prism/translation/parser34.rb
107
+ - lib/prism/translation/parser35.rb
101
108
  - lib/prism/translation/ripper.rb
109
+ - lib/prism/translation/ripper/sexp.rb
110
+ - lib/prism/translation/ripper/shim.rb
102
111
  - lib/prism/translation/ruby_parser.rb
103
112
  - lib/prism/version.rb
104
113
  - lib/prism/visitor.rb
105
114
  - prism.gemspec
106
115
  - rbi/prism.rbi
107
- - rbi/prism_static.rbi
116
+ - rbi/prism/compiler.rbi
117
+ - rbi/prism/dsl.rbi
118
+ - rbi/prism/inspect_visitor.rbi
119
+ - rbi/prism/node.rbi
120
+ - rbi/prism/node_ext.rbi
121
+ - rbi/prism/parse_result.rbi
122
+ - rbi/prism/reflection.rbi
123
+ - rbi/prism/string_query.rbi
124
+ - rbi/prism/translation/parser.rbi
125
+ - rbi/prism/translation/parser33.rbi
126
+ - rbi/prism/translation/parser34.rbi
127
+ - rbi/prism/translation/parser35.rbi
128
+ - rbi/prism/translation/ripper.rbi
129
+ - rbi/prism/visitor.rbi
108
130
  - sig/prism.rbs
109
- - sig/prism_static.rbs
131
+ - sig/prism/compiler.rbs
132
+ - sig/prism/dispatcher.rbs
133
+ - sig/prism/dot_visitor.rbs
134
+ - sig/prism/dsl.rbs
135
+ - sig/prism/inspect_visitor.rbs
136
+ - sig/prism/lex_compat.rbs
137
+ - sig/prism/mutation_compiler.rbs
138
+ - sig/prism/node.rbs
139
+ - sig/prism/node_ext.rbs
140
+ - sig/prism/pack.rbs
141
+ - sig/prism/parse_result.rbs
142
+ - sig/prism/pattern.rbs
143
+ - sig/prism/reflection.rbs
144
+ - sig/prism/relocation.rbs
145
+ - sig/prism/serialize.rbs
146
+ - sig/prism/string_query.rbs
147
+ - sig/prism/visitor.rbs
110
148
  - src/diagnostic.c
111
149
  - src/encoding.c
112
150
  - src/node.c
@@ -116,16 +154,16 @@ files:
116
154
  - src/prism.c
117
155
  - src/regexp.c
118
156
  - src/serialize.c
157
+ - src/static_literals.c
119
158
  - src/token_type.c
120
159
  - src/util/pm_buffer.c
121
160
  - src/util/pm_char.c
122
161
  - src/util/pm_constant_pool.c
162
+ - src/util/pm_integer.c
123
163
  - src/util/pm_list.c
124
164
  - src/util/pm_memchr.c
125
165
  - src/util/pm_newline_list.c
126
- - src/util/pm_state_stack.c
127
166
  - src/util/pm_string.c
128
- - src/util/pm_string_list.c
129
167
  - src/util/pm_strncasecmp.c
130
168
  - src/util/pm_strpbrk.c
131
169
  homepage: https://github.com/jruby/jruby-prism
@@ -135,7 +173,6 @@ metadata:
135
173
  allowed_push_host: https://rubygems.org
136
174
  source_code_uri: https://github.com/ruby/prism
137
175
  changelog_uri: https://github.com/ruby/prism/blob/main/CHANGELOG.md
138
- post_install_message:
139
176
  rdoc_options: []
140
177
  require_paths:
141
178
  - lib
@@ -143,16 +180,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
180
  requirements:
144
181
  - - ">="
145
182
  - !ruby/object:Gem::Version
146
- version: 2.7.0
183
+ version: 3.4.0
147
184
  required_rubygems_version: !ruby/object:Gem::Requirement
148
185
  requirements:
149
186
  - - ">="
150
187
  - !ruby/object:Gem::Version
151
188
  version: '0'
152
189
  requirements:
153
- - jar org.jruby, jruby-prism, 0.24.0, :scope => :runtime
154
- rubygems_version: 3.3.26
155
- signing_key:
190
+ - jar org.jruby, jruby-prism, 1.4.0, :scope => :runtime
191
+ rubygems_version: 3.6.2
156
192
  specification_version: 4
157
193
  summary: Prism JRuby Parser Support
158
194
  test_files: []
data/docs/ripper.md DELETED
@@ -1,36 +0,0 @@
1
- # Ripper
2
-
3
- To test the parser, we compare against the output from `Ripper`, both for testing the lexer and testing the parser. The lexer test suite is much more feature complete at the moment.
4
-
5
- To lex source code using `prism`, you typically would run `Prism.lex(source)`. If you want to instead get output that `Ripper` would normally produce, you can run `Prism.lex_compat(source)`. This will produce tokens that should be equivalent to `Ripper`.
6
-
7
- To parse source code using `prism`, you typically would run `Prism.parse(source)`. If you want to instead using the `Ripper` streaming interface, you can inherit from `Prism::RipperCompat` and override the `on_*` methods. This will produce a syntax tree that should be equivalent to `Ripper`. That would look like:
8
-
9
- ```ruby
10
- class ArithmeticRipper < Prism::RipperCompat
11
- def on_binary(left, operator, right)
12
- left.public_send(operator, right)
13
- end
14
-
15
- def on_int(value)
16
- value.to_i
17
- end
18
-
19
- def on_program(stmts)
20
- stmts
21
- end
22
-
23
- def on_stmts_new
24
- []
25
- end
26
-
27
- def on_stmts_add(stmts, stmt)
28
- stmts << stmt
29
- stmts
30
- end
31
- end
32
-
33
- ArithmeticRipper.new("1 + 2 - 3").parse # => [0]
34
- ```
35
-
36
- There are also APIs for building trees similar to the s-expression builders in `Ripper`. The method names are the same. These include `Prism::RipperCompat.sexp_raw(source)` and `Prism::RipperCompat.sexp(source)`.
@@ -1,42 +0,0 @@
1
- /**
2
- * @file pm_state_stack.h
3
- *
4
- * A stack of boolean values.
5
- */
6
- #ifndef PRISM_STATE_STACK_H
7
- #define PRISM_STATE_STACK_H
8
-
9
- #include "prism/defines.h"
10
-
11
- #include <stdbool.h>
12
- #include <stdint.h>
13
-
14
- /**
15
- * A struct that represents a stack of boolean values.
16
- */
17
- typedef uint32_t pm_state_stack_t;
18
-
19
- /**
20
- * Pushes a value onto the stack.
21
- *
22
- * @param stack The stack to push the value onto.
23
- * @param value The value to push onto the stack.
24
- */
25
- void pm_state_stack_push(pm_state_stack_t *stack, bool value);
26
-
27
- /**
28
- * Pops a value off the stack.
29
- *
30
- * @param stack The stack to pop the value off of.
31
- */
32
- void pm_state_stack_pop(pm_state_stack_t *stack);
33
-
34
- /**
35
- * Returns the value at the top of the stack.
36
- *
37
- * @param stack The stack to get the value from.
38
- * @return The value at the top of the stack.
39
- */
40
- bool pm_state_stack_p(pm_state_stack_t *stack);
41
-
42
- #endif
@@ -1,44 +0,0 @@
1
- /**
2
- * @file pm_string_list.h
3
- *
4
- * A list of strings.
5
- */
6
- #ifndef PRISM_STRING_LIST_H
7
- #define PRISM_STRING_LIST_H
8
-
9
- #include "prism/defines.h"
10
- #include "prism/util/pm_string.h"
11
-
12
- #include <stddef.h>
13
- #include <stdlib.h>
14
-
15
- /**
16
- * A list of strings.
17
- */
18
- typedef struct {
19
- /** The length of the string list. */
20
- size_t length;
21
-
22
- /** The capacity of the string list that has been allocated. */
23
- size_t capacity;
24
-
25
- /** A pointer to the start of the string list. */
26
- pm_string_t *strings;
27
- } pm_string_list_t;
28
-
29
- /**
30
- * Append a pm_string_t to the given string list.
31
- *
32
- * @param string_list The string list to append to.
33
- * @param string The string to append.
34
- */
35
- void pm_string_list_append(pm_string_list_t *string_list, pm_string_t *string);
36
-
37
- /**
38
- * Free the memory associated with the string list.
39
- *
40
- * @param string_list The string list to free.
41
- */
42
- PRISM_EXPORTED_FUNCTION void pm_string_list_free(pm_string_list_t *string_list);
43
-
44
- #endif
data/lib/prism/debug.rb DELETED
@@ -1,206 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Prism
4
- # This module is used for testing and debugging and is not meant to be used by
5
- # consumers of this library.
6
- module Debug
7
- # A wrapper around a RubyVM::InstructionSequence that provides a more
8
- # convenient interface for accessing parts of the iseq.
9
- class ISeq # :nodoc:
10
- attr_reader :parts
11
-
12
- def initialize(parts)
13
- @parts = parts
14
- end
15
-
16
- def type
17
- parts[0]
18
- end
19
-
20
- def local_table
21
- parts[10]
22
- end
23
-
24
- def instructions
25
- parts[13]
26
- end
27
-
28
- def each_child
29
- instructions.each do |instruction|
30
- # Only look at arrays. Other instructions are line numbers or
31
- # tracepoint events.
32
- next unless instruction.is_a?(Array)
33
-
34
- instruction.each do |opnd|
35
- # Only look at arrays. Other operands are literals.
36
- next unless opnd.is_a?(Array)
37
-
38
- # Only look at instruction sequences. Other operands are literals.
39
- next unless opnd[0] == "YARVInstructionSequence/SimpleDataFormat"
40
-
41
- yield ISeq.new(opnd)
42
- end
43
- end
44
- end
45
- end
46
-
47
- private_constant :ISeq
48
-
49
- # :call-seq:
50
- # Debug::cruby_locals(source) -> Array
51
- #
52
- # For the given source, compiles with CRuby and returns a list of all of the
53
- # sets of local variables that were encountered.
54
- def self.cruby_locals(source)
55
- verbose, $VERBOSE = $VERBOSE, nil
56
-
57
- begin
58
- locals = []
59
- stack = [ISeq.new(RubyVM::InstructionSequence.compile(source).to_a)]
60
-
61
- while (iseq = stack.pop)
62
- names = [*iseq.local_table]
63
- names.map!.with_index do |name, index|
64
- # When an anonymous local variable is present in the iseq's local
65
- # table, it is represented as the stack offset from the top.
66
- # However, when these are dumped to binary and read back in, they
67
- # are replaced with the symbol :#arg_rest. To consistently handle
68
- # this, we replace them here with their index.
69
- if name == :"#arg_rest"
70
- names.length - index + 1
71
- else
72
- name
73
- end
74
- end
75
-
76
- locals << names
77
- iseq.each_child { |child| stack << child }
78
- end
79
-
80
- locals
81
- ensure
82
- $VERBOSE = verbose
83
- end
84
- end
85
-
86
- # Used to hold the place of a local that will be in the local table but
87
- # cannot be accessed directly from the source code. For example, the
88
- # iteration variable in a for loop or the positional parameter on a method
89
- # definition that is destructured.
90
- AnonymousLocal = Object.new
91
- private_constant :AnonymousLocal
92
-
93
- # :call-seq:
94
- # Debug::prism_locals(source) -> Array
95
- #
96
- # For the given source, parses with prism and returns a list of all of the
97
- # sets of local variables that were encountered.
98
- def self.prism_locals(source)
99
- locals = []
100
- stack = [Prism.parse(source).value]
101
-
102
- while (node = stack.pop)
103
- case node
104
- when BlockNode, DefNode, LambdaNode
105
- names = node.locals
106
- params =
107
- if node.is_a?(DefNode)
108
- node.parameters
109
- elsif node.parameters.is_a?(NumberedParametersNode)
110
- nil
111
- else
112
- node.parameters&.parameters
113
- end
114
-
115
- # prism places parameters in the same order that they appear in the
116
- # source. CRuby places them in the order that they need to appear
117
- # according to their own internal calling convention. We mimic that
118
- # order here so that we can compare properly.
119
- if params
120
- sorted = [
121
- *params.requireds.map do |required|
122
- if required.is_a?(RequiredParameterNode)
123
- required.name
124
- else
125
- AnonymousLocal
126
- end
127
- end,
128
- *params.optionals.map(&:name),
129
- *((params.rest.name || :*) if params.rest && !params.rest.is_a?(ImplicitRestNode)),
130
- *params.posts.map do |post|
131
- if post.is_a?(RequiredParameterNode)
132
- post.name
133
- else
134
- AnonymousLocal
135
- end
136
- end,
137
- *params.keywords.grep(RequiredKeywordParameterNode).map(&:name),
138
- *params.keywords.grep(OptionalKeywordParameterNode).map(&:name),
139
- ]
140
-
141
- sorted << AnonymousLocal if params.keywords.any?
142
-
143
- if params.keyword_rest.is_a?(ForwardingParameterNode)
144
- sorted.push(:*, :**, :&, :"...")
145
- elsif params.keyword_rest.is_a?(KeywordRestParameterNode)
146
- sorted << (params.keyword_rest.name || :**)
147
- end
148
-
149
- # Recurse down the parameter tree to find any destructured
150
- # parameters and add them after the other parameters.
151
- param_stack = params.requireds.concat(params.posts).grep(MultiTargetNode).reverse
152
- while (param = param_stack.pop)
153
- case param
154
- when MultiTargetNode
155
- param_stack.concat(param.rights.reverse)
156
- param_stack << param.rest if param.rest&.expression && !sorted.include?(param.rest.expression.name)
157
- param_stack.concat(param.lefts.reverse)
158
- when RequiredParameterNode
159
- sorted << param.name
160
- when SplatNode
161
- sorted << param.expression.name
162
- end
163
- end
164
-
165
- if params.block
166
- sorted << (params.block.name || :&)
167
- end
168
-
169
- names = sorted.concat(names - sorted)
170
- end
171
-
172
- names.map!.with_index do |name, index|
173
- if name == AnonymousLocal
174
- names.length - index + 1
175
- else
176
- name
177
- end
178
- end
179
-
180
- locals << names
181
- when ClassNode, ModuleNode, ProgramNode, SingletonClassNode
182
- locals << node.locals
183
- when ForNode
184
- locals << [2]
185
- when PostExecutionNode
186
- locals.push([], [])
187
- when InterpolatedRegularExpressionNode
188
- locals << [] if node.once?
189
- end
190
-
191
- stack.concat(node.compact_child_nodes)
192
- end
193
-
194
- locals
195
- end
196
-
197
- # :call-seq:
198
- # Debug::newlines(source) -> Array
199
- #
200
- # For the given source string, return the byte offsets of every newline in
201
- # the source.
202
- def self.newlines(source)
203
- Prism.parse(source).source.offsets
204
- end
205
- end
206
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Prism
4
- # This object is responsible for generating the output for the inspect method
5
- # implementations of child nodes.
6
- class NodeInspector # :nodoc:
7
- attr_reader :prefix, :output
8
-
9
- def initialize(prefix = "")
10
- @prefix = prefix
11
- @output = +""
12
- end
13
-
14
- # Appends a line to the output with the current prefix.
15
- def <<(line)
16
- output << "#{prefix}#{line}"
17
- end
18
-
19
- # This generates a string that is used as the header of the inspect output
20
- # for any given node.
21
- def header(node)
22
- output = +"@ #{node.class.name.split("::").last} ("
23
- output << "location: (#{node.location.start_line},#{node.location.start_column})-(#{node.location.end_line},#{node.location.end_column})"
24
- output << ", newline: true" if node.newline?
25
- output << ")\n"
26
- output
27
- end
28
-
29
- # Generates a string that represents a list of nodes. It handles properly
30
- # using the box drawing characters to make the output look nice.
31
- def list(prefix, nodes)
32
- output = +"(length: #{nodes.length})\n"
33
- last_index = nodes.length - 1
34
-
35
- nodes.each_with_index do |node, index|
36
- pointer, preadd = (index == last_index) ? ["└── ", " "] : ["├── ", "│ "]
37
- node_prefix = "#{prefix}#{preadd}"
38
- output << node.inspect(NodeInspector.new(node_prefix)).sub(node_prefix, "#{prefix}#{pointer}")
39
- end
40
-
41
- output
42
- end
43
-
44
- # Generates a string that represents a location field on a node.
45
- def location(value)
46
- if value
47
- "(#{value.start_line},#{value.start_column})-(#{value.end_line},#{value.end_column}) = #{value.slice.inspect}"
48
- else
49
- "∅"
50
- end
51
- end
52
-
53
- # Generates a string that represents a child node.
54
- def child_node(node, append)
55
- node.inspect(child_inspector(append)).delete_prefix(prefix)
56
- end
57
-
58
- # Returns a new inspector that can be used to inspect a child node.
59
- def child_inspector(append)
60
- NodeInspector.new("#{prefix}#{append}")
61
- end
62
-
63
- # Returns the output as a string.
64
- def to_str
65
- output
66
- end
67
- end
68
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "parser"
4
- require "rubocop"
5
-
6
- require "prism"
7
- require "prism/translation/parser"
8
-
9
- module Prism
10
- module Translation
11
- class Parser
12
- # This is the special version numbers that should be used in RuboCop
13
- # configuration files to trigger using prism.
14
-
15
- # For Ruby 3.3
16
- VERSION_3_3 = 80_82_73_83_77.33
17
-
18
- # For Ruby 3.4
19
- VERSION_3_4 = 80_82_73_83_77.34
20
-
21
- # This module gets prepended into RuboCop::AST::ProcessedSource.
22
- module ProcessedSource
23
- # Redefine parser_class so that we can inject the prism parser into the
24
- # list of known parsers.
25
- def parser_class(ruby_version)
26
- if ruby_version == Prism::Translation::Parser::VERSION_3_3
27
- require "prism/translation/parser33"
28
- Prism::Translation::Parser33
29
- elsif ruby_version == Prism::Translation::Parser::VERSION_3_4
30
- require "prism/translation/parser34"
31
- Prism::Translation::Parser34
32
- else
33
- super
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
-
41
- # :stopdoc:
42
- RuboCop::AST::ProcessedSource.prepend(Prism::Translation::Parser::ProcessedSource)
43
- known_rubies = RuboCop::TargetRuby.const_get(:KNOWN_RUBIES)
44
- RuboCop::TargetRuby.send(:remove_const, :KNOWN_RUBIES)
45
- RuboCop::TargetRuby::KNOWN_RUBIES = [*known_rubies, Prism::Translation::Parser::VERSION_3_3].freeze