prism 1.7.0 → 1.9.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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/Makefile +7 -1
  4. data/config.yml +4 -4
  5. data/docs/releasing.md +2 -4
  6. data/docs/ripper_translation.md +8 -17
  7. data/docs/ruby_api.md +1 -0
  8. data/ext/prism/extension.h +1 -1
  9. data/include/prism/ast.h +4 -4
  10. data/include/prism/version.h +2 -2
  11. data/lib/prism/compiler.rb +152 -152
  12. data/lib/prism/lex_compat.rb +133 -150
  13. data/lib/prism/node.rb +1131 -20
  14. data/lib/prism/parse_result.rb +9 -0
  15. data/lib/prism/serialize.rb +1 -1
  16. data/lib/prism/translation/parser_current.rb +1 -1
  17. data/lib/prism/translation/parser_versions.rb +36 -0
  18. data/lib/prism/translation/ripper/filter.rb +53 -0
  19. data/lib/prism/translation/ripper/lexer.rb +135 -0
  20. data/lib/prism/translation/ripper.rb +84 -38
  21. data/lib/prism/translation/ruby_parser.rb +1 -1
  22. data/lib/prism/translation.rb +5 -5
  23. data/lib/prism/visitor.rb +152 -152
  24. data/lib/prism.rb +1 -14
  25. data/prism.gemspec +5 -11
  26. data/rbi/prism/node.rbi +3 -0
  27. data/rbi/prism/translation/parser_versions.rbi +23 -0
  28. data/rbi/prism.rbi +0 -3
  29. data/sig/prism/node.rbs +4 -0
  30. data/sig/prism/parse_result.rbs +1 -0
  31. data/sig/prism.rbs +54 -40
  32. data/src/prism.c +48 -27
  33. metadata +5 -11
  34. data/lib/prism/translation/parser33.rb +0 -13
  35. data/lib/prism/translation/parser34.rb +0 -13
  36. data/lib/prism/translation/parser35.rb +0 -8
  37. data/lib/prism/translation/parser40.rb +0 -13
  38. data/lib/prism/translation/parser41.rb +0 -13
  39. data/rbi/prism/translation/parser33.rbi +0 -6
  40. data/rbi/prism/translation/parser34.rbi +0 -6
  41. data/rbi/prism/translation/parser35.rbi +0 -4
  42. data/rbi/prism/translation/parser40.rbi +0 -6
  43. data/rbi/prism/translation/parser41.rbi +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34ddf7552f6698f496fba09232eac5bcfb053d0455cdac655d81d4a9e5c60d96
4
- data.tar.gz: 248141836d3f2502508f3374586bfd6590d1457dd0508494588a8905c56aea91
3
+ metadata.gz: 1f7205a73da36d10903c1495fd475e014a30c875568c932568cac22351eb3059
4
+ data.tar.gz: d59eac5f6e8e8955ea9b259b63eec423a0af06c79a748edaa9f64f24463dc874
5
5
  SHA512:
6
- metadata.gz: 6e46578f5a2dd28f487bd4ffbdc7cd34bf15f230118f53bf932bea0ccff22cc4fcd000804f9a7bc27fd3399099bbd368f9ac89b6408df7de766ad1aef24a3cda
7
- data.tar.gz: 7e25c7caf0fbf963e7c7aadaf35535f3c770c1813e0b9cfd3f8d4623d2d47c5a1d8e2e487d59d75a711871b9bdf5dca92c9e85af0dd4d3f513e86d3d7a66e37d
6
+ metadata.gz: 59571b78dba19ec01a6f52094cc6d30e5648e633cd24f3abfbbc765145bed778f88fea75eada071d780ecb3dbe77a1bebab563d676289fed0ea6d21e50056290
7
+ data.tar.gz: 3c5b40536f98839fefb0afcefd49d5e78a3a31f9a55bd33b78b80665b2ca3bd1c2262c1836f9c6f1d3ddc7ad2d9b7dd12f06b3dff2b4aea9475a7171340d95b4
data/CHANGELOG.md CHANGED
@@ -6,6 +6,34 @@ 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.9.0] - 2026-01-27
10
+
11
+ ### Added
12
+
13
+ - Lots of work on the Ripper translation layer to make it more compatible and efficient.
14
+ - Alias `Prism::Node#breadth_first_search` to `Prism::Node#find`.
15
+ - Add `Prism::Node#breadth_first_search_all`/`Prism::Node#find_all` for finding all nodes matching a condition.
16
+
17
+ ### Changed
18
+
19
+ - Fixed location of opening tokens when invalid syntax is parsed.
20
+ - Fix RBI for parsing options.
21
+
22
+ ## [1.8.0] - 2026-01-12
23
+
24
+ ### Added
25
+
26
+ - Optimize ruby visitor.
27
+ - Report unterminated construct errors at opening token.
28
+
29
+ ### Changed
30
+
31
+ - Correctly expose ripper state.
32
+ - Use one file for versioned parser classes.
33
+ - Fix denominator of rational float literal.
34
+ - Decouple ripper translator from ripper library.
35
+ - Sync Prism::Translation::ParserCurrent with Ruby 4.0.
36
+
9
37
  ## [1.7.0] - 2025-12-18
10
38
 
11
39
  ### Added
@@ -716,7 +744,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
716
744
 
717
745
  - 🎉 Initial release! 🎉
718
746
 
719
- [unreleased]: https://github.com/ruby/prism/compare/v1.7.0...HEAD
747
+ [unreleased]: https://github.com/ruby/prism/compare/v1.9.0...HEAD
748
+ [1.9.0]: https://github.com/ruby/prism/compare/v1.8.0...v1.9.0
749
+ [1.8.0]: https://github.com/ruby/prism/compare/v1.7.0...v1.8.0
720
750
  [1.7.0]: https://github.com/ruby/prism/compare/v1.6.0...v1.7.0
721
751
  [1.6.0]: https://github.com/ruby/prism/compare/v1.5.2...v1.6.0
722
752
  [1.5.2]: https://github.com/ruby/prism/compare/v1.5.1...v1.5.2
data/Makefile CHANGED
@@ -43,7 +43,13 @@ build/libprism.a: $(STATIC_OBJECTS)
43
43
 
44
44
  javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)
45
45
  $(ECHO) "building $@"
46
- $(Q) $(WASI_SDK_PATH)/bin/clang --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/ $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -o $@ $(SOURCES)
46
+ $(Q) $(WASI_SDK_PATH)/bin/clang --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/ \
47
+ $(DEBUG_FLAGS) \
48
+ -DPRISM_EXPORT_SYMBOLS -DPRISM_EXCLUDE_PRETTYPRINT -DPRISM_EXCLUDE_JSON -DPRISM_EXCLUDE_PACK \
49
+ -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) \
50
+ -Wl,--export-all -Wl,--gc-sections -Wl,--strip-all -Wl,--lto-O3 -Wl,--no-entry -mexec-model=reactor \
51
+ -Oz -g0 -flto -fdata-sections -ffunction-sections \
52
+ -o $@ $(SOURCES)
47
53
 
48
54
  java-wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS)
49
55
  $(ECHO) "building $@"
data/config.yml CHANGED
@@ -1269,17 +1269,17 @@ nodes:
1269
1269
  - name: opening_loc
1270
1270
  type: location
1271
1271
  comment: |
1272
- Represents the location of the opening `|`.
1272
+ Represents the location of the opening `{` or `do`.
1273
1273
 
1274
1274
  [1, 2, 3].each { |i| puts x }
1275
- ^
1275
+ ^
1276
1276
  - name: closing_loc
1277
1277
  type: location
1278
1278
  comment: |
1279
- Represents the location of the closing `|`.
1279
+ Represents the location of the closing `}` or `end`.
1280
1280
 
1281
1281
  [1, 2, 3].each { |i| puts x }
1282
- ^
1282
+ ^
1283
1283
  comment: |
1284
1284
  Represents a block of ruby code.
1285
1285
 
data/docs/releasing.md CHANGED
@@ -47,10 +47,8 @@ bundle install
47
47
  * Update the version-specific lockfiles:
48
48
 
49
49
  ```sh
50
- for VERSION in "2.7" "3.0" "3.1" "3.2" "3.3" "3.4"; do docker run -it --rm -v "$PWD":/usr/src/app -w /usr/src/app -e BUNDLE_GEMFILE="gemfiles/$VERSION/Gemfile" "ruby:$VERSION" bundle update; done
51
- docker run -it --rm -v "$PWD":/usr/src/app -w /usr/src/app -e BUNDLE_GEMFILE="gemfiles/4.0/Gemfile" ruby:4.0.0-preview2 bundle update
52
- docker run -it --rm -v "$PWD":/usr/src/app -w /usr/src/app -e BUNDLE_GEMFILE="gemfiles/jruby/Gemfile" jruby:latest bundle update
53
- BUNDLE_GEMFILE=gemfiles/truffleruby/Gemfile chruby-exec truffleruby -- bundle update
50
+ for VERSION in "2.7" "3.0" "3.1" "3.2" "3.3" "3.4" "4.0"; do docker run -it --rm -v "$PWD":/usr/src/app -w /usr/src/app -e BUNDLE_GEMFILE="gemfiles/$VERSION/Gemfile" "ruby:$VERSION" bundle update; done
51
+ chruby ruby-4.1.0-dev && BUNDLE_GEMFILE=gemfiles/4.1/Gemfile bundle install
54
52
  ```
55
53
 
56
54
  * Update the cargo lockfiles:
@@ -1,22 +1,6 @@
1
1
  # Ripper translation
2
2
 
3
- Prism provides the ability to mirror the `Ripper` standard library. You can do this by:
4
-
5
- ```ruby
6
- require "prism/translation/ripper/shim"
7
- ```
8
-
9
- This provides the APIs like:
10
-
11
- ```ruby
12
- Ripper.lex
13
- Ripper.parse
14
- Ripper.sexp_raw
15
- Ripper.sexp
16
-
17
- Ripper::SexpBuilder
18
- Ripper::SexpBuilderPP
19
- ```
3
+ Prism provides the ability to mirror the `Ripper` standard library. It is available under `Prism::Translation::Ripper`. You can use the entire public API, and also some undocumented features that are commonly used.
20
4
 
21
5
  Briefly, `Ripper` is a streaming parser that allows you to construct your own syntax tree. As an example:
22
6
 
@@ -49,6 +33,13 @@ ArithmeticRipper.new("1 + 2 - 3").parse # => [0]
49
33
 
50
34
  The exact names of the `on_*` methods are listed in the `Ripper` source.
51
35
 
36
+ You can can also automatically use the ripper translation in places that don't explicitly use the translation layer by doing the following:
37
+
38
+ ```ruby
39
+ # Will redirect access of the `Ripper` constant to `Prism::Translation::Ripper`.
40
+ require "prism/translation/ripper/shim"
41
+ ```
42
+
52
43
  ## Background
53
44
 
54
45
  It is helpful to understand the differences between the `Ripper` library and the `Prism` library. Both libraries perform parsing and provide you with APIs to manipulate and understand the resulting syntax tree. However, there are a few key differences.
data/docs/ruby_api.md CHANGED
@@ -36,6 +36,7 @@ Once you have nodes in hand coming out of a parse result, there are a number of
36
36
  * `#accept(visitor)` - a method that will immediately call `visit_*` to specialize for the node type
37
37
  * `#child_nodes` - a positional array of the child nodes of the node, with `nil` values for any missing children
38
38
  * `#compact_child_nodes` - a positional array of the child nodes of the node with no `nil` values
39
+ * `#each_child_node` - with a block given yields all child nodes, without a block return an enumerator containing all child nodes
39
40
  * `#copy(**keys)` - a method that allows creating a shallow copy of the node with the given keys overridden
40
41
  * `#deconstruct`/`#deconstruct_keys(keys)` - the pattern matching interface for nodes
41
42
  * `#inspect` - a string representation that looks like the syntax tree of the node
@@ -1,7 +1,7 @@
1
1
  #ifndef PRISM_EXT_NODE_H
2
2
  #define PRISM_EXT_NODE_H
3
3
 
4
- #define EXPECTED_PRISM_VERSION "1.7.0"
4
+ #define EXPECTED_PRISM_VERSION "1.9.0"
5
5
 
6
6
  #include <ruby.h>
7
7
  #include <ruby/encoding.h>
data/include/prism/ast.h CHANGED
@@ -1826,20 +1826,20 @@ typedef struct pm_block_node {
1826
1826
  /**
1827
1827
  * BlockNode#opening_loc
1828
1828
  *
1829
- * Represents the location of the opening `|`.
1829
+ * Represents the location of the opening `{` or `do`.
1830
1830
  *
1831
1831
  * [1, 2, 3].each { |i| puts x }
1832
- * ^
1832
+ * ^
1833
1833
  */
1834
1834
  pm_location_t opening_loc;
1835
1835
 
1836
1836
  /**
1837
1837
  * BlockNode#closing_loc
1838
1838
  *
1839
- * Represents the location of the closing `|`.
1839
+ * Represents the location of the closing `}` or `end`.
1840
1840
  *
1841
1841
  * [1, 2, 3].each { |i| puts x }
1842
- * ^
1842
+ * ^
1843
1843
  */
1844
1844
  pm_location_t closing_loc;
1845
1845
  } pm_block_node_t;
@@ -14,7 +14,7 @@
14
14
  /**
15
15
  * The minor version of the Prism library as an int.
16
16
  */
17
- #define PRISM_VERSION_MINOR 7
17
+ #define PRISM_VERSION_MINOR 9
18
18
 
19
19
  /**
20
20
  * The patch version of the Prism library as an int.
@@ -24,6 +24,6 @@
24
24
  /**
25
25
  * The version of the Prism library as a constant string.
26
26
  */
27
- #define PRISM_VERSION "1.7.0"
27
+ #define PRISM_VERSION "1.9.0"
28
28
 
29
29
  #endif