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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b82c0b2353ff110c8e7658a168f76c1a5c3b8fee6ee4d0a5bd8fab2d9641aa2
4
- data.tar.gz: bbee6337a99636cf0a96bffa752f1534c4f4eb7baf07e349f597817e6a4eaf33
3
+ metadata.gz: c4143efc7a4fbdbcaddb7220dcd86685476c6c585b85679f7eb83ead2b10dd44
4
+ data.tar.gz: 1e437320584d92b228bfee57490b0946ccd69b44e1dbc12609b722de16bcfa29
5
5
  SHA512:
6
- metadata.gz: 1706d4053f73739e5d6ebd413b94d16065a9b20132a1aeca50104543f05b802f2658111564bde5969621e07453bdb7bc7c9f38de4150df3351905fc23f2ab5a9
7
- data.tar.gz: 78d26fb025d9f3480e9daffeea8e26860743db628640bbbc39c8a78bb78394e11cf26357a377a9d2b950f43a1205dfa8d83fe569a2724bb84e24a32a97954b65
6
+ metadata.gz: bfb3232c63c08d7283ca928654c615a8d4c41d553dd322d63272ffd8f8bd707f017862c94b06a2bd2a807d6a9552f9014209ed811a48ad8117b6da7822f8f4e3
7
+ data.tar.gz: 2f361f6732c10b3b7519732891c789f1d80434afdc635794b9b9ee2e6d63708cb07f03c727ec4d4566fdc94ae00b62d5a890e5189cefa86027e68e3c015d8719
data/BSDmakefile ADDED
@@ -0,0 +1,58 @@
1
+ # GNU makefile proxy script for BSD make
2
+ #
3
+ # Written and maintained by Mahmoud Al-Qudsi <mqudsi@neosmart.net>
4
+ # Copyright NeoSmart Technologies <https://neosmart.net/> 2014-2019
5
+ # Obtain updates from <https://github.com/neosmart/gmake-proxy>
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions are met:
9
+ #
10
+ # 1. Redistributions of source code must retain the above copyright notice, this
11
+ # list of conditions and the following disclaimer.
12
+ #
13
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
14
+ # this list of conditions and the following disclaimer in the documentation
15
+ # and/or other materials provided with the distribution.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ JARG =
29
+ GMAKE = "gmake"
30
+ # When gmake is called from another make instance, -w is automatically added
31
+ # which causes extraneous messages about directory changes to be emitted.
32
+ # Running with --no-print-directory silences these messages.
33
+ GARGS = "--no-print-directory"
34
+
35
+ .if "$(.MAKE.JOBS)" != ""
36
+ JARG = -j$(.MAKE.JOBS)
37
+ .endif
38
+
39
+ # bmake prefers out-of-source builds and tries to cd into ./obj (among others)
40
+ # where possible. GNU Make doesn't, so override that value.
41
+ .OBJDIR: ./
42
+
43
+ # The GNU convention is to use the lowercased `prefix` variable/macro to
44
+ # specify the installation directory. Humor them.
45
+ GPREFIX = ""
46
+ .if defined(PREFIX) && ! defined(prefix)
47
+ GPREFIX = 'prefix = "$(PREFIX)"'
48
+ .endif
49
+
50
+ .BEGIN: .SILENT
51
+ which $(GMAKE) || printf "Error: GNU Make is required!\n\n" 1>&2 && false
52
+
53
+ .PHONY: FRC
54
+ $(.TARGETS): FRC
55
+ $(GMAKE) $(GPREFIX) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)
56
+
57
+ .DONE .DEFAULT: .SILENT
58
+ $(GMAKE) $(GPREFIX) $(GARGS) $(.TARGETS:S,.DONE,,) $(JARG)
data/CHANGELOG.md CHANGED
@@ -6,6 +6,263 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.4.0] - 2025-03-18
10
+
11
+ ### Added
12
+
13
+ - Support `3.5` as a version option.
14
+ - Many, many compatibility fixes for the parser translation layer.
15
+ - Handle escapes in named capture names.
16
+ - The `freeze` option is added to the various `Prism::` APIs to deeply freeze the AST.
17
+ - Properly support `it` for the parser and ruby_parser translation layers.
18
+ - Track the `then` keyword on `rescue` nodes.
19
+ - Add a `multiple_statements?` flag to parentheses nodes to support desired `defined?` behavior.
20
+
21
+ ### Changed
22
+
23
+ - The strings used in the AST are now frozen.
24
+ - Fixed handling escaped characters after control sequences in character literals.
25
+ - Fix reading off the end of an unterminated global variable.
26
+ - Raise a syntax error for defining `[]=` with endless method syntax.
27
+ - Increase value of `PRISM_DEPTH_MAXIMUM` to `10000`.
28
+ - Freeze `Prism::VERSION`.
29
+ - Fix up rescue modifier precedence.
30
+
31
+ ## [1.3.0] - 2024-12-21
32
+
33
+ ### Added
34
+
35
+ - Introduce `Prism::StringQuery`.
36
+ - Introduce `Prism::Relocation`.
37
+ - Track `do` keyword for `WhileNode` and `UntilNode`.
38
+ - Change the way the gem is built to rely on `mkmf` instead of `make`.
39
+ - Lots more documentation on node fields.
40
+
41
+ ### Changed
42
+
43
+ - Properly add an error for `def @foo; end`.
44
+ - Properly add an error for `foo(**, *)`.
45
+ - Fix up regression in string parsing in `RubyParser` translation.
46
+ - Reject invalid dot method call after match expression.
47
+ - Reject invalid operator after match expression.
48
+ - Fix up %-literals delimited by newlines.
49
+ - Properly add an error for `-> { _1; -> { _1 } }`.
50
+ - Reject blocks and keywords in index writes.
51
+
52
+ ## [1.2.0] - 2024-10-10
53
+
54
+ ### Added
55
+
56
+ - Introduce `Prism::CodeUnitsCache`.
57
+
58
+ ### Changed
59
+
60
+ - Properly handle lexing global variables that begin with `$-`.
61
+ - Properly reject invalid multi writes within parentheses.
62
+ - Fix unary `*` binding power.
63
+ - Set `contains_keywords` flag for implicit `gets` calls when `-p` is used.
64
+ - Properly reject invalid non-associative operator patterns.
65
+ - Do not warn about unused variables declared on negative lines.
66
+
67
+ ## [1.1.0] - 2024-10-02
68
+
69
+ ### Added
70
+
71
+ - Explicitly type each child node field in the Ruby API.
72
+ - Add the `main_script` option to the parse APIs, which controls whether or not shebangs are considered.
73
+ - Add the `partial_script` options to the parse APIs, which controls whether or not jumps that would otherwise be considered invalid are allowed. This is useful for parsing things like ERB sources, where you know it will be evaluated in a different context. Note that this functionality is replacing the previous idiom of passing in a list of scopes to indicate an `eval` context, because that behavior has changed upstream in `ruby/ruby`.
74
+ - Add `ArgumentsNode#contains_multiple_splats?`.
75
+ - Add `ArgumentsNode#contains_forwarding?`.
76
+ - Accept all valid Ruby versions for the `version` option on parse APIs.
77
+ - Accept version shorthands like `"3.3"` and `"3.4"` for the `version` option on parse APIs.
78
+ - Support a max depth to protect against malicious payloads without hitting the stack limit.
79
+
80
+ ### Changed
81
+
82
+ - Fix some token incompatibilities in the `parser` translation.
83
+ - Fix up parsing tempfiles on Windows.
84
+ - Fix up handling UTF-8 characters in file paths on Windows.
85
+ - Do not warn for a `\r` at the end of a shebang on Windows.
86
+ - Properly handle erroring for parsing a directory on Windows.
87
+ - When a numbered reference is out of range, warn instead of raise.
88
+ - Allow returns in default parameter values.
89
+ - Reject many more invalid syntax patterns.
90
+
91
+ ## [1.0.0] - 2024-08-28
92
+
93
+ ### Added
94
+
95
+ - Add `Node#breadth_first_search`.
96
+ - Add `Node#node_id`.
97
+ - Add `ArgumentsNode#contains_splat?`.
98
+ - Passing the special value `false` for the `encoding` option tells Prism to ignore magic encoding comments.
99
+ - Expose flags on every node type (allows checking static literal and newline).
100
+ - Implement mismatched indentation warning.
101
+ - Add C API for receiving a callback when parsing shebangs with additional flags.
102
+
103
+ ### Changed
104
+
105
+ - **BREAKING**: Some fields are renamed that had illogical names. The previous names all now emit deprecation warnings.
106
+ - `CaseMatchNode#consequent` was renamed to `CaseMatchNode#else_clause`
107
+ - `CaseNode#consequent` was renamed to `CaseNode#else_clause`
108
+ - `IfNode#consequent` was renamed to `IfNode#subsequent`
109
+ - `RescueNode#consequent` was renamed to `RescueNode#subsequent`
110
+ - `UnlessNode#consequent` was renamed to `UnlessNode#else_clause`
111
+ - Block exits are now allowed in loop predicates (e.g., `while _ && break do end`).
112
+ - Multi-writes are now disallowed when not at the statement level.
113
+ - Ensure that range operators are non-associative.
114
+ - (JavaScript) Correctly deserialize encoded strings.
115
+ - Properly support parsing regular expressions in extended mode.
116
+ - Use gmake on FreeBSD.
117
+ - Parsing streams now handles NUL bytes in the middle of the stream.
118
+ - Properly detect invalid returns.
119
+
120
+ ## [0.30.0] - 2024-06-07
121
+
122
+ ### Added
123
+
124
+ - More correctly raise mixed encoding errors.
125
+ - Implement ambiguous binary operator warning.
126
+ - Fix up regexp escapes with control and meta characters.
127
+ - Fix up support for the `it` implicit local variable.
128
+ - Heredoc identifiers now properly disallow CLRF.
129
+ - Errors added for void value expressions in begin clauses.
130
+ - Many updates to more closely match the `parser` gem in parser translation.
131
+ - Many errors added for invalid regular expressions.
132
+
133
+ ### Changed
134
+
135
+ - Handle parser translation missing the `parser` gem.
136
+ - Handle ruby_parser translation missing the `ruby_parser` gem.
137
+ - Various error messages have been updated to more closely match CRuby.
138
+ - `RationalNode` now has a `numerator` and `denominator` field instead of a `numeric` field. For the Ruby API we provide a `RationalNode#numeric` method for backwards-compatibility.
139
+
140
+ ## [0.29.0] - 2024-05-10
141
+
142
+ ### Added
143
+
144
+ - Added `Prism::CallNode#full_message_loc`, which gives the location including the `=` if there is one.
145
+ - A warning for when `# shareable_constant_value` is not used on its own line.
146
+ - An error for invalid implicit local variable writes.
147
+ - Implicit hash patterns in array patterns are disallowed.
148
+ - We now validate that Unicode escape sequences are not surrogates.
149
+
150
+ ### Changed
151
+
152
+ - All fields named `operator` have been renamed to `binary_operator` for `*OperatorWriteNode` nodes. This is to make it easier to provide C++ support. In the Ruby API, the old fields are aliased to the new fields with a deprecation warning.
153
+ - Many updated error messages to more closely match CRuby.
154
+ - We ensure keyword parameters do not end in `!` or `?`.
155
+ - Fixed some escaping in string literals with control sequences and hex escapes.
156
+ - Fix a bug with RBS types when used outside the `ruby/prism` codebase.
157
+
158
+ ## [0.28.0] - 2024-05-03
159
+
160
+ ### Added
161
+
162
+ - Nested hashes will now warn for duplicated keys, as in: `{ foo: 1, **{ foo: 2 } }`.
163
+ - `Prism::ReturnNode` now has a flag on it to indicate if it is redundant.
164
+ - `Prism::Location#slice_lines` and `Prism::Node#slice_lines` are now provided to slice the source code of a node including the content before the node on the same line that it starts on and the content after the node on the same line that it ends on.
165
+ - Symbols with invalid byte sequences now give errors.
166
+ - You can now pass `"3.3.1"` to the `version:` parameter on all `Prism.*` APIs.
167
+ - `Prism::Source#lines`, `Prism::Location#source_lines`, `Prism::Node#source_lines`, and `Prism::Node#script_lines` are now provided, which will all return the source code of the source as an array of strings.
168
+ - `Prism::ASCIISource` is now provided, which is a subclass of `Prism::Source` but specialized to increase performance when the source is entirely ASCII.
169
+ - Prism now provides errors when parsing Ruby 3.4+ syntax for index expressions with keywords or blocks.
170
+ - Prism now provides an error when `**nil` is used after other keyword parameters.
171
+ - Prism now provides errors when safe navigation is used in call target expressions, e.g., `foo&.bar, = 1`.
172
+ - `Prism::Node#tunnel` is now provided, which returns an array of nodes starting at the current node that contain a given line and column.
173
+
174
+ ### Changed
175
+
176
+ - All translation layers now assume an eval context, which means they will not return errors for invalid jumps like `yield`.
177
+ - `Prism::Node#inspect` now uses a queue instead of recursion to avoid stack overflows.
178
+ - Prism now more closely mirrors CRuby interpolation semantics, which means you could potentially have a static literal string that directly interpolates another static literal string.
179
+ - The shipped RBI sorbet types no longer use generics.
180
+ - `Prism::ConstantPathNode#child` and `Prism::ConstantTargetNode#child` are now deprecated, replaced by two new fields on these nodes: `name` and `name_loc`.
181
+
182
+ ## [0.27.0] - 2024-04-23
183
+
184
+ ### Added
185
+
186
+ - Implemented `===` for each of the nodes, which will check if equality but ignore the specific ranges of locations.
187
+
188
+ ### Changed
189
+
190
+ - Fix translation of `ItParametersNode` for parser translation.
191
+ - Fix translation of `dstr` for ruby_parser translation.
192
+ - Do not allow omitted hash values whose keys end with `!` or `?`.
193
+ - Split up `Prism::ParseResult` into `Prism::Result` with subclasses `Prism::ParseResult`, `Prism::LexResult`, `Prism::ParseLexResult`, and `Prism::LexCompat::Result`.
194
+ - Change reflection classes to have only a single `IntegerField` class and rename `DoubleField` to `FloatField`.
195
+ - Fall back to default `AR` and `CC` in `Makefile`.
196
+ - Use GC-able symbols for the syntax tree to avoid adding to the global symbol table.
197
+ - Fix a bug with karatsuba_multiply that would result in a stack overflow.
198
+ - Fix parser translation when looking for tokens with `srange_find`.
199
+
200
+ ## [0.26.0] - 2024-04-18
201
+
202
+ ### Added
203
+
204
+ - Add `Prism::Node::fields`, which returns a list of `Prism::Reflection::Field` objects representing the fields of the node class. This is useful in metaprogramming contexts.
205
+ - `Prism::Location#chop`, for removing the last byte from a location.
206
+ - The void statement warning is now implemented.
207
+ - The unreachable statement warning is now implemented.
208
+ - A syntax error has been added for block arguments on yields, e.g., `yield(&foo)`.
209
+
210
+ ### Changed
211
+
212
+ - Better fidelity to `parser` when translating heredocs with interpolation.
213
+ - Fixed `RBI` and `RBS` types for `Prism::parse_*` signatures.
214
+ - Remove some incorrect warnings about unused local variables.
215
+ - More closely match CRuby error messages for global variables.
216
+ - Fix an issue with `parser` translation when line continuations are found in string literals.
217
+
218
+ ## [0.25.0] - 2024-04-05
219
+
220
+ ### Added
221
+
222
+ - `Prism::Translation::Ripper` is now able to mirror all of the Ripper APIs.
223
+ - `Prism::Location#leading_comments` and `Prism::Location#trailing_comments` is added.
224
+ - `Prism::Comment#slice` is added.
225
+ - Warn for writing literal values in conditional predicates.
226
+ - Check for `_POSIX_MAPPED_FILES` before using `mmap`.
227
+ - `Prism::ItParametersNode` is added, to support `-> { it }`.
228
+ - Parse integer and float literal values onto the tree.
229
+ - Warn on duplicated hash keys and duplicated when clauses.
230
+ - Ship much improved `RBI` and `RBS` types.
231
+ - Support for the `-p`, `-n`, `-a`, and `-l` command line switches.
232
+ - Warn on integer literals in flip-flops.
233
+ - Support BSD make.
234
+ - Add `Prism::WhenNode#then_keyword_loc`.
235
+ - Support custom allocation functions through the `PRISM_XALLOCATOR` define.
236
+ - Warn for certain keywrods at the end of the line.
237
+ - Provide `pm_visit_node`, a C visitor API.
238
+ - `Prism::parse_stream` is added, which works for any Ruby `IO` object.
239
+ - Provide flags for regular expression literals for their derived encoding.
240
+ - Provide flags for whether or not an interpolated string literal is frozen.
241
+ - Add `Prism::StringNode.mutable?` for when a string is explicitly mutable, to support delineating chilled strings.
242
+ - Warn for incorrect character literal syntax.
243
+ - Warn for chained comparison operators.
244
+ - Warn for `**` interpreted as an argument prefix.
245
+ - Warn for `&` interpreted as an argument prefix.
246
+ - `Prism::ShareableConstantNode` added to support ractors.
247
+ - Warn for frozen string literals found after tokens.
248
+ - Support `PRISM_BUILD_MINIMAL` to provide only the minimal necessary functionality to reduce the binary size.
249
+ - Handle CLRF inside heredocs, strings, and regular expressions.
250
+ - Mark inner strings in interpolated strings as frozen.
251
+ - Support the `-x` command line switch.
252
+ - Error messages now much more closely mirror CRuby.
253
+ - Provide syntax errors for invalid block exits (`break`, `next`, `retry`, and `yield`).
254
+ - Warn on unused local variables.
255
+ - Do not syntax error on default parameter values that only write to the parameter.
256
+
257
+ ### Changed
258
+
259
+ - Many improvements to the compatibility with the `whitequark/parser` translation.
260
+ - Accept newlines before pattern terminators `)` or `]`.
261
+ - `Prism::Node#start_offset` and `Prism::Node#end_offset` are now much more efficient.
262
+ - Read files using `fread` instead of `mmap` when we're going to keep around the source through the Ruby API.
263
+ - Fix `Sexp#line_max` setting in the `seattlerb/ruby_parser` translation layer.
264
+ - Allow spaces before the encoding comment.
265
+
9
266
  ## [0.24.0] - 2024-02-15
10
267
 
11
268
  ### Added
@@ -392,7 +649,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
392
649
 
393
650
  - 🎉 Initial release! 🎉
394
651
 
395
- [unreleased]: https://github.com/ruby/prism/compare/v0.24.0...HEAD
652
+ [unreleased]: https://github.com/ruby/prism/compare/v1.4.0...HEAD
653
+ [1.4.0]: https://github.com/ruby/prism/compare/v1.3.0...v1.4.0
654
+ [1.3.0]: https://github.com/ruby/prism/compare/v1.2.0...v1.3.0
655
+ [1.2.0]: https://github.com/ruby/prism/compare/v1.1.0...v1.2.0
656
+ [1.1.0]: https://github.com/ruby/prism/compare/v1.0.0...v1.1.0
657
+ [1.0.0]: https://github.com/ruby/prism/compare/v0.30.0...v1.0.0
658
+ [0.30.0]: https://github.com/ruby/prism/compare/v0.29.0...v0.30.0
659
+ [0.29.0]: https://github.com/ruby/prism/compare/v0.28.0...v0.29.0
660
+ [0.28.0]: https://github.com/ruby/prism/compare/v0.27.0...v0.28.0
661
+ [0.27.0]: https://github.com/ruby/prism/compare/v0.26.0...v0.27.0
662
+ [0.26.0]: https://github.com/ruby/prism/compare/v0.25.0...v0.26.0
663
+ [0.25.0]: https://github.com/ruby/prism/compare/v0.24.0...v0.25.0
396
664
  [0.24.0]: https://github.com/ruby/prism/compare/v0.23.0...v0.24.0
397
665
  [0.23.0]: https://github.com/ruby/prism/compare/v0.22.0...v0.23.0
398
666
  [0.22.0]: https://github.com/ruby/prism/compare/v0.21.0...v0.22.0
data/CONTRIBUTING.md CHANGED
@@ -10,10 +10,6 @@ The discussions page on the GitHub repository are open. If you have a question o
10
10
 
11
11
  If you want to contribute code, please first open or contribute to a discussion. A lot of the project is in flux, and we want to make sure that you are contributing to the right place. Once you have a discussion going, you can open a pull request with your changes. We will review your code and get it merged in.
12
12
 
13
- ### Ruby Features
14
-
15
- Pattern matching and endless method definitions should be avoided as long as the latest TruffleRuby release does not support it.
16
-
17
13
  ## Tests
18
14
 
19
15
  We could always use more tests! One of the biggest challenges of this project is building up a big test suite. If you want to contribute tests, feel free to open a pull request. These will get merged in as soon as possible.
data/Makefile CHANGED
@@ -6,17 +6,21 @@ Q1 = $(V:1=)
6
6
  Q = $(Q1:0=@)
7
7
  ECHO1 = $(V:1=@ :)
8
8
  ECHO = $(ECHO1:0=@ echo)
9
- FUZZ_OUTPUT_DIR = $(shell pwd)/fuzz/output
9
+ FUZZ_OUTPUT_DIR = $(CURDIR)/fuzz/output
10
10
 
11
- SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
11
+ SOEXT ?= $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
12
12
 
13
- CPPFLAGS := -Iinclude
14
- CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden
15
- CC := cc
13
+ CPPFLAGS := -Iinclude $(CPPFLAGS)
14
+ CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden -Wimplicit-fallthrough $(CFLAGS)
15
+ CC ?= cc
16
+ AR ?= ar
16
17
  WASI_SDK_PATH := /opt/wasi-sdk
17
18
 
18
- HEADERS := $(shell find include -name '*.h')
19
- SOURCES := $(shell find src -name '*.c')
19
+ MAKEDIRS ?= mkdir -p
20
+ RMALL ?= rm -f -r
21
+
22
+ HEADERS := $(wildcard include/*.h include/*/*.h include/*/*/*.h')
23
+ SOURCES := $(wildcard src/*.c src/*/*.c)
20
24
  SHARED_OBJECTS := $(subst src/,build/shared/,$(SOURCES:.c=.o))
21
25
  STATIC_OBJECTS := $(subst src/,build/static/,$(SOURCES:.c=.o))
22
26
 
@@ -28,11 +32,11 @@ wasm: javascript/src/prism.wasm
28
32
  java-wasm: java-wasm/src/test/resources/prism.wasm
29
33
 
30
34
  build/libprism.$(SOEXT): $(SHARED_OBJECTS)
31
- $(ECHO) "linking $@"
35
+ $(ECHO) "linking $@ with $(CC)"
32
36
  $(Q) $(CC) $(DEBUG_FLAGS) $(CFLAGS) -shared -o $@ $(SHARED_OBJECTS)
33
37
 
34
38
  build/libprism.a: $(STATIC_OBJECTS)
35
- $(ECHO) "building $@"
39
+ $(ECHO) "building $@ with $(AR)"
36
40
  $(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS) $(Q1:0=>/dev/null)
37
41
 
38
42
  javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)
@@ -45,17 +49,17 @@ java-wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS)
45
49
 
46
50
  build/shared/%.o: src/%.c Makefile $(HEADERS)
47
51
  $(ECHO) "compiling $@"
48
- $(Q) mkdir -p $(@D)
52
+ $(Q) $(MAKEDIRS) $(@D)
49
53
  $(Q) $(CC) $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
50
54
 
51
55
  build/static/%.o: src/%.c Makefile $(HEADERS)
52
56
  $(ECHO) "compiling $@"
53
- $(Q) mkdir -p $(@D)
57
+ $(Q) $(MAKEDIRS) $(@D)
54
58
  $(Q) $(CC) $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
55
59
 
56
60
  build/fuzz.%: $(SOURCES) fuzz/%.c fuzz/fuzz.c
57
61
  $(ECHO) "building $* fuzzer"
58
- $(Q) mkdir -p $(@D)
62
+ $(Q) $(MAKEDIRS) $(@D)
59
63
  $(ECHO) "building main fuzz binary"
60
64
  $(Q) AFL_HARDEN=1 afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize-ignorelist=fuzz/asan.ignore -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@ $^
61
65
  $(ECHO) "building cmplog binary"
@@ -66,7 +70,7 @@ build/fuzz.heisenbug.%: $(SOURCES) fuzz/%.c fuzz/heisenbug.c
66
70
 
67
71
  fuzz-debug:
68
72
  $(ECHO) "entering debug shell"
69
- $(Q) docker run -it --rm -e HISTFILE=/prism/fuzz/output/.bash_history -v $(shell pwd):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz
73
+ $(Q) docker run -it --rm -e HISTFILE=/prism/fuzz/output/.bash_history -v $(CURDIR):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz
70
74
 
71
75
  fuzz-docker-build: fuzz/docker/Dockerfile
72
76
  $(ECHO) "building docker image"
@@ -76,17 +80,17 @@ fuzz-run-%: FORCE fuzz-docker-build
76
80
  $(ECHO) "generating templates"
77
81
  $(Q) bundle exec rake templates
78
82
  $(ECHO) "running $* fuzzer"
79
- $(Q) docker run --rm -v $(shell pwd):/prism prism/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
83
+ $(Q) docker run --rm -v $(CURDIR):/prism prism/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
80
84
  $(ECHO) "starting AFL++ run"
81
- $(Q) mkdir -p $(FUZZ_OUTPUT_DIR)/$*
82
- $(Q) docker run -it --rm -v $(shell pwd):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
85
+ $(Q) $(MAKEDIRS) $(FUZZ_OUTPUT_DIR)/$*
86
+ $(Q) docker run -it --rm -v $(CURDIR):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
83
87
  FORCE:
84
88
 
85
89
  fuzz-clean:
86
- $(Q) rm -f -r fuzz/output
90
+ $(Q) $(RMALL) fuzz/output
87
91
 
88
92
  clean:
89
- $(Q) rm -f -r build
93
+ $(Q) $(RMALL) build
90
94
 
91
95
  .PHONY: clean fuzz-clean
92
96
 
@@ -94,6 +98,9 @@ all-no-debug: DEBUG_FLAGS := -DNDEBUG=1
94
98
  all-no-debug: OPTFLAGS := -O3
95
99
  all-no-debug: all
96
100
 
101
+ minimal: CFLAGS := $(CFLAGS) -DPRISM_BUILD_MINIMAL
102
+ minimal: all
103
+
97
104
  run: Makefile $(STATIC_OBJECTS) $(HEADERS) test.c
98
105
  $(ECHO) "compiling test.c"
99
106
  $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) $(STATIC_OBJECTS) test.c
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img alt="Prism Ruby parser" height="256px" src="https://github.com/ruby/prism/blob/main/doc/images/prism.png?raw=true">
4
4
  </div>
5
5
 
6
- This is a parser for the Ruby programming language. It is designed to be portable, error tolerant, and maintainable. It is written in C99 and has no dependencies. It is currently being integrated into [CRuby](https://github.com/ruby/ruby), [JRuby](https://github.com/jruby/jruby), [TruffleRuby](https://github.com/oracle/truffleruby), [Sorbet](https://github.com/sorbet/sorbet), and [Syntax Tree](https://github.com/ruby-syntax-tree/syntax_tree).
6
+ This is a parser for the Ruby programming language. It is designed to be portable, error tolerant, and maintainable. It is written in C99 and has no dependencies.
7
7
 
8
8
  ## Overview
9
9
 
@@ -15,27 +15,35 @@ The repository contains the infrastructure for both a shared library (libprism)
15
15
  ├── Rakefile configuration to compile the native extension and run the Ruby tests
16
16
  ├── bin
17
17
  │   ├── lex runs the lexer on a file or string, prints the tokens, and compares to ripper
18
- │   └── parse runs the parser on a file or string and prints the syntax tree
18
+ │   ├── parse runs the parse on a file or string and prints the AST
19
+ │   └── prism a CLI for development and debugging
19
20
  ├── config.yml specification for tokens and nodes in the tree
20
- ├── docs documentation about the project
21
+ ├── doc documentation website
22
+ ├── docs markdown documentation about the project
21
23
  ├── ext
22
24
  │   └── prism
23
25
  │   ├── extconf.rb configuration to generate the Makefile for the native extension
24
26
  │   └── extension.c the native extension that interacts with libprism
25
27
  ├── fuzz files related to fuzz testing
28
+ ├── gemfiles gemfiles used by different Ruby versions in CI
26
29
  ├── include
27
30
  │   ├── prism header files for the shared library
28
31
  │   └── prism.h main header file for the shared library
29
32
  ├── java Java bindings for the shared library
33
+ ├── java-wasm Java WASM bindings for the shared library
34
+ ├── javascript JavaScript WASM bindings for the shared library
30
35
  ├── lib
31
36
  │   ├── prism Ruby library files
32
37
  │   └── prism.rb main entrypoint for the Ruby library
33
38
  ├── rakelib various Rake tasks for the project
39
+ ├── rbi RBI type signatures for the Ruby library
34
40
  ├── rust
35
41
  │   ├── ruby-prism Rustified crate for the shared library
36
42
  │   └── ruby-prism-sys FFI binding for Rust
43
+ ├── sample
44
+ │ └── prism Sample code that uses the Ruby API for documentation purposes
45
+ ├── sig RBS type signatures for the Ruby library
37
46
  ├── src
38
- │   ├── enc various encoding files
39
47
  │   ├── util various utility files
40
48
  │   └── prism.c main entrypoint for the shared library
41
49
  ├── templates contains ERB templates generated by templates/template.rb
@@ -51,7 +59,7 @@ The repository contains the infrastructure for both a shared library (libprism)
51
59
  To compile the shared library, you will need:
52
60
 
53
61
  * C99 compiler
54
- * make
62
+ * GNU make
55
63
  * Ruby 2.7.0 or later
56
64
 
57
65
  Once you have these dependencies, run:
@@ -91,8 +99,51 @@ See the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information. We additio
91
99
  * [Parser translation](docs/parser_translation.md)
92
100
  * [Parsing rules](docs/parsing_rules.md)
93
101
  * [Releasing](docs/releasing.md)
94
- * [Ripper](docs/ripper.md)
102
+ * [Ripper translation](docs/ripper_translation.md)
95
103
  * [Ruby API](docs/ruby_api.md)
96
104
  * [RubyParser translation](docs/ruby_parser_translation.md)
97
105
  * [Serialization](docs/serialization.md)
98
106
  * [Testing](docs/testing.md)
107
+
108
+ ## Examples
109
+
110
+ Prism has been integrated into the majority of Ruby runtimes, many libraries, and some applications. Below is a list of some of the projects that use Prism:
111
+
112
+ ### Runtimes
113
+
114
+ * [CRuby](https://github.com/ruby/ruby/pull/7964) (via C)
115
+ * [Garnet](https://github.com/camertron/garnet-js) (via WASM)
116
+ * [JRuby](https://github.com/jruby/jruby/pull/8103) (via Java)
117
+ * [Natalie](https://github.com/natalie-lang/natalie/pull/1213) (via C++ and Ruby)
118
+ * [Opal](https://github.com/opal/opal/pull/2642) (via Ruby and WASM)
119
+ * [TruffleRuby](https://github.com/oracle/truffleruby/issues/3117) (via Java)
120
+
121
+ ### Libraries
122
+
123
+ * [dispersion](https://github.com/joeldrapper/dispersion)
124
+ * [minifyrb](https://github.com/koic/minifyrb)
125
+ * [packwerk](https://github.com/Shopify/packwerk/pull/388) (via parser translator)
126
+ * [rbi](https://github.com/Shopify/rbi)
127
+ * [rails](https://github.com/rails/rails)
128
+ * [parsing renders](https://github.com/rails/rails/pull/49438)
129
+ * [parsing rdoc](https://github.com/rails/rails/pull/50870)
130
+ * [parsing tests](https://github.com/rails/rails/pull/51006)
131
+ * [repl_type_completor](https://github.com/ruby/repl_type_completor)
132
+ * [rubocop](https://docs.rubocop.org/rubocop/configuration.html#setting-the-parser-engine) (via parser translator)
133
+ * [ruby-lsp](https://github.com/Shopify/ruby-lsp)
134
+ * [smart_todo](https://github.com/Shopify/smart_todo/pull/69)
135
+ * [sorbet-eraser](https://github.com/kddnewton/sorbet-eraser/pull/25)
136
+ * [synvert](https://github.com/xinminlabs/synvert-core-ruby)
137
+ * [typeprof](https://github.com/ruby/typeprof)
138
+
139
+ ### Applications
140
+
141
+ * [gem.sh](https://github.com/marcoroth/gem.sh/pull/96)
142
+
143
+ ### JRuby gem stuff
144
+
145
+ - fetch upstream to main in this repository
146
+ - merge to main
147
+ - merge to jruby_gem branch with last released tag
148
+ - update lib/prism/version.rb to match version
149
+ - re-run bundler to kill conflicts in Gemfile.lock