prism 0.29.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +115 -1
  3. data/CONTRIBUTING.md +0 -4
  4. data/Makefile +1 -1
  5. data/README.md +4 -0
  6. data/config.yml +920 -148
  7. data/docs/build_system.md +8 -11
  8. data/docs/fuzzing.md +1 -1
  9. data/docs/parsing_rules.md +4 -1
  10. data/docs/relocation.md +34 -0
  11. data/docs/ripper_translation.md +22 -0
  12. data/docs/serialization.md +3 -0
  13. data/ext/prism/api_node.c +2863 -2079
  14. data/ext/prism/extconf.rb +14 -37
  15. data/ext/prism/extension.c +241 -391
  16. data/ext/prism/extension.h +2 -2
  17. data/include/prism/ast.h +2156 -453
  18. data/include/prism/defines.h +58 -7
  19. data/include/prism/diagnostic.h +24 -6
  20. data/include/prism/node.h +0 -21
  21. data/include/prism/options.h +94 -3
  22. data/include/prism/parser.h +82 -40
  23. data/include/prism/regexp.h +18 -8
  24. data/include/prism/static_literals.h +3 -2
  25. data/include/prism/util/pm_char.h +1 -2
  26. data/include/prism/util/pm_constant_pool.h +0 -8
  27. data/include/prism/util/pm_integer.h +22 -15
  28. data/include/prism/util/pm_newline_list.h +11 -0
  29. data/include/prism/util/pm_string.h +28 -12
  30. data/include/prism/version.h +3 -3
  31. data/include/prism.h +47 -11
  32. data/lib/prism/compiler.rb +3 -0
  33. data/lib/prism/desugar_compiler.rb +111 -74
  34. data/lib/prism/dispatcher.rb +16 -1
  35. data/lib/prism/dot_visitor.rb +55 -34
  36. data/lib/prism/dsl.rb +660 -468
  37. data/lib/prism/ffi.rb +113 -8
  38. data/lib/prism/inspect_visitor.rb +296 -64
  39. data/lib/prism/lex_compat.rb +1 -1
  40. data/lib/prism/mutation_compiler.rb +11 -6
  41. data/lib/prism/node.rb +4262 -5023
  42. data/lib/prism/node_ext.rb +91 -14
  43. data/lib/prism/parse_result/comments.rb +0 -7
  44. data/lib/prism/parse_result/errors.rb +65 -0
  45. data/lib/prism/parse_result/newlines.rb +101 -11
  46. data/lib/prism/parse_result.rb +183 -6
  47. data/lib/prism/reflection.rb +12 -10
  48. data/lib/prism/relocation.rb +504 -0
  49. data/lib/prism/serialize.rb +496 -609
  50. data/lib/prism/string_query.rb +30 -0
  51. data/lib/prism/translation/parser/compiler.rb +185 -155
  52. data/lib/prism/translation/parser/lexer.rb +26 -4
  53. data/lib/prism/translation/parser.rb +9 -4
  54. data/lib/prism/translation/ripper.rb +23 -25
  55. data/lib/prism/translation/ruby_parser.rb +86 -17
  56. data/lib/prism/visitor.rb +3 -0
  57. data/lib/prism.rb +6 -8
  58. data/prism.gemspec +9 -5
  59. data/rbi/prism/dsl.rbi +521 -0
  60. data/rbi/prism/node.rbi +1115 -1120
  61. data/rbi/prism/parse_result.rbi +29 -0
  62. data/rbi/prism/string_query.rbi +12 -0
  63. data/rbi/prism/visitor.rbi +3 -0
  64. data/rbi/prism.rbi +36 -30
  65. data/sig/prism/dsl.rbs +190 -303
  66. data/sig/prism/mutation_compiler.rbs +1 -0
  67. data/sig/prism/node.rbs +678 -632
  68. data/sig/prism/parse_result.rbs +22 -0
  69. data/sig/prism/relocation.rbs +185 -0
  70. data/sig/prism/string_query.rbs +11 -0
  71. data/sig/prism/visitor.rbs +1 -0
  72. data/sig/prism.rbs +103 -64
  73. data/src/diagnostic.c +64 -28
  74. data/src/node.c +502 -1739
  75. data/src/options.c +76 -27
  76. data/src/prettyprint.c +188 -112
  77. data/src/prism.c +3376 -2293
  78. data/src/regexp.c +208 -71
  79. data/src/serialize.c +182 -50
  80. data/src/static_literals.c +64 -85
  81. data/src/token_type.c +4 -4
  82. data/src/util/pm_char.c +1 -1
  83. data/src/util/pm_constant_pool.c +0 -8
  84. data/src/util/pm_integer.c +53 -25
  85. data/src/util/pm_newline_list.c +29 -0
  86. data/src/util/pm_string.c +131 -80
  87. data/src/util/pm_strpbrk.c +32 -6
  88. metadata +11 -7
  89. data/include/prism/util/pm_string_list.h +0 -44
  90. data/lib/prism/debug.rb +0 -249
  91. data/lib/prism/translation/parser/rubocop.rb +0 -73
  92. data/src/util/pm_string_list.c +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ac8167684c0f975fdba449e77206d97756f6c39f22ce871f79a79a61260503f
4
- data.tar.gz: 6a2dd5c0a47df7c8c575ad2e5b344c789d548e93cfe82e5fa29974d46a52bb3c
3
+ metadata.gz: cc945a81285247ae139110607116e5ad0211e008f8e69d76002238755deca5dc
4
+ data.tar.gz: 81703e9b86fd950af63fbea201f8cd9ddec3a3a330d24c80aba7461782bb347b
5
5
  SHA512:
6
- metadata.gz: dfa7fe63285b85cb45aa0be681916d6891ee5e5adf2162ab5c18423417f7938afc99f00eca8fd6187fbd0b7168af088d932fbda3c1361d1c73953f39329bed70
7
- data.tar.gz: 79bc51db60600d74a6bfbeae5eba3a8ec505e9809d0f7ff0b05563f1f7a8cd284cc293233397323a443217a4a5271f90b4c40516168ae3a8be0ddc2d7376cef9
6
+ metadata.gz: 39fb25eec8d603cd26f31ce75281e3cf257f8f21451e6687eda11d14e090013651284b1f7b35612004b0603105883d0e1d8de1d82b192ce5238843e03203e9fa
7
+ data.tar.gz: 4544a22d735276ca60cf3dd4e7b91ce64aa60539d555466d73d3eebb91502a0a357232bd1c0722232f3745481e554ba6ab2eb7a23f05a25e5d0c114f9077dc52
data/CHANGELOG.md CHANGED
@@ -6,6 +6,115 @@ 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.3.0] - 2024-12-21
10
+
11
+ ### Added
12
+
13
+ - Introduce `Prism::StringQuery`.
14
+ - Introduce `Prism::Relocation`.
15
+ - Track `do` keyword for `WhileNode` and `UntilNode`.
16
+ - Change the way the gem is built to rely on `mkmf` instead of `make`.
17
+ - Lots more documentation on node fields.
18
+
19
+ ### Changed
20
+
21
+ - Properly add an error for `def @foo; end`.
22
+ - Properly add an error for `foo(**, *)`.
23
+ - Fix up regression in string parsing in `RubyParser` translation.
24
+ - Reject invalid dot method call after match expression.
25
+ - Reject invalid operator after match expression.
26
+ - Fix up %-literals delimited by newlines.
27
+ - Properly add an error for `-> { _1; -> { _1 } }`.
28
+ - Reject blocks and keywords in index writes.
29
+
30
+ ## [1.2.0] - 2024-10-10
31
+
32
+ ### Added
33
+
34
+ - Introduce `Prism::CodeUnitsCache`.
35
+
36
+ ### Changed
37
+
38
+ - Properly handle lexing global variables that begin with `$-`.
39
+ - Properly reject invalid multi writes within parentheses.
40
+ - Fix unary `*` binding power.
41
+ - Set `contains_keywords` flag for implicit `gets` calls when `-p` is used.
42
+ - Properly reject invalid non-associative operator patterns.
43
+ - Do not warn about unused variables declared on negative lines.
44
+
45
+ ## [1.1.0] - 2024-10-02
46
+
47
+ ### Added
48
+
49
+ - Explicitly type each child node field in the Ruby API.
50
+ - Add the `main_script` option to the parse APIs, which controls whether or not shebangs are considered.
51
+ - 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`.
52
+ - Add `ArgumentsNode#contains_multiple_splats?`.
53
+ - Add `ArgumentsNode#contains_forwarding?`.
54
+ - Accept all valid Ruby versions for the `version` option on parse APIs.
55
+ - Accept version shorthands like `"3.3"` and `"3.4"` for the `version` option on parse APIs.
56
+ - Support a max depth to protect against malicious payloads without hitting the stack limit.
57
+
58
+ ### Changed
59
+
60
+ - Fix some token incompatibilities in the `parser` translation.
61
+ - Fix up parsing tempfiles on Windows.
62
+ - Fix up handling UTF-8 characters in file paths on Windows.
63
+ - Do not warn for a `\r` at the end of a shebang on Windows.
64
+ - Properly handle erroring for parsing a directory on Windows.
65
+ - When a numbered reference is out of range, warn instead of raise.
66
+ - Allow returns in default parameter values.
67
+ - Reject many more invalid syntax patterns.
68
+
69
+ ## [1.0.0] - 2024-08-28
70
+
71
+ ### Added
72
+
73
+ - Add `Node#breadth_first_search`.
74
+ - Add `Node#node_id`.
75
+ - Add `ArgumentsNode#contains_splat?`.
76
+ - Passing the special value `false` for the `encoding` option tells Prism to ignore magic encoding comments.
77
+ - Expose flags on every node type (allows checking static literal and newline).
78
+ - Implement mismatched indentation warning.
79
+ - Add C API for receiving a callback when parsing shebangs with additional flags.
80
+
81
+ ### Changed
82
+
83
+ - **BREAKING**: Some fields are renamed that had illogical names. The previous names all now emit deprecation warnings.
84
+ - `CaseMatchNode#consequent` was renamed to `CaseMatchNode#else_clause`
85
+ - `CaseNode#consequent` was renamed to `CaseNode#else_clause`
86
+ - `IfNode#consequent` was renamed to `IfNode#subsequent`
87
+ - `RescueNode#consequent` was renamed to `RescueNode#subsequent`
88
+ - `UnlessNode#consequent` was renamed to `UnlessNode#else_clause`
89
+ - Block exits are now allowed in loop predicates (e.g., `while _ && break do end`).
90
+ - Multi-writes are now disallowed when not at the statement level.
91
+ - Ensure that range operators are non-associative.
92
+ - (JavaScript) Correctly deserialize encoded strings.
93
+ - Properly support parsing regular expressions in extended mode.
94
+ - Use gmake on FreeBSD.
95
+ - Parsing streams now handles NUL bytes in the middle of the stream.
96
+ - Properly detect invalid returns.
97
+
98
+ ## [0.30.0] - 2024-06-07
99
+
100
+ ### Added
101
+
102
+ - More correctly raise mixed encoding errors.
103
+ - Implement ambiguous binary operator warning.
104
+ - Fix up regexp escapes with control and meta characters.
105
+ - Fix up support for the `it` implicit local variable.
106
+ - Heredoc identifiers now properly disallow CLRF.
107
+ - Errors added for void value expressions in begin clauses.
108
+ - Many updates to more closely match the `parser` gem in parser translation.
109
+ - Many errors added for invalid regular expressions.
110
+
111
+ ### Changed
112
+
113
+ - Handle parser translation missing the `parser` gem.
114
+ - Handle ruby_parser translation missing the `ruby_parser` gem.
115
+ - Various error messages have been updated to more closely match CRuby.
116
+ - `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.
117
+
9
118
  ## [0.29.0] - 2024-05-10
10
119
 
11
120
  ### Added
@@ -518,7 +627,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
518
627
 
519
628
  - 🎉 Initial release! 🎉
520
629
 
521
- [unreleased]: https://github.com/ruby/prism/compare/v0.29.0...HEAD
630
+ [unreleased]: https://github.com/ruby/prism/compare/v1.3.0...HEAD
631
+ [1.3.0]: https://github.com/ruby/prism/compare/v1.2.0...v1.3.0
632
+ [1.2.0]: https://github.com/ruby/prism/compare/v1.1.0...v1.2.0
633
+ [1.1.0]: https://github.com/ruby/prism/compare/v1.0.0...v1.1.0
634
+ [1.0.0]: https://github.com/ruby/prism/compare/v0.30.0...v1.0.0
635
+ [0.30.0]: https://github.com/ruby/prism/compare/v0.29.0...v0.30.0
522
636
  [0.29.0]: https://github.com/ruby/prism/compare/v0.28.0...v0.29.0
523
637
  [0.28.0]: https://github.com/ruby/prism/compare/v0.27.0...v0.28.0
524
638
  [0.27.0]: https://github.com/ruby/prism/compare/v0.26.0...v0.27.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
@@ -11,7 +11,7 @@ FUZZ_OUTPUT_DIR = $(CURDIR)/fuzz/output
11
11
  SOEXT ?= $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
12
12
 
13
13
  CPPFLAGS := -Iinclude $(CPPFLAGS)
14
- CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden $(CFLAGS)
14
+ CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden -Wimplicit-fallthrough $(CFLAGS)
15
15
  CC ?= cc
16
16
  AR ?= ar
17
17
  WASI_SDK_PATH := /opt/wasi-sdk
data/README.md CHANGED
@@ -40,6 +40,8 @@ The repository contains the infrastructure for both a shared library (libprism)
40
40
  ├── rust
41
41
  │   ├── ruby-prism Rustified crate for the shared library
42
42
  │   └── ruby-prism-sys FFI binding for Rust
43
+ ├── sample
44
+ │ └── prism Sample code that uses the Ruby API for documentation purposes
43
45
  ├── sig RBS type signatures for the Ruby library
44
46
  ├── src
45
47
  │   ├── util various utility files
@@ -119,6 +121,7 @@ Prism has been integrated into the majority of Ruby runtimes, many libraries, an
119
121
  ### Libraries
120
122
 
121
123
  * [dispersion](https://github.com/joeldrapper/dispersion)
124
+ * [minifyrb](https://github.com/koic/minifyrb)
122
125
  * [packwerk](https://github.com/Shopify/packwerk/pull/388) (via parser translator)
123
126
  * [rbi](https://github.com/Shopify/rbi)
124
127
  * [rails](https://github.com/rails/rails)
@@ -131,6 +134,7 @@ Prism has been integrated into the majority of Ruby runtimes, many libraries, an
131
134
  * [smart_todo](https://github.com/Shopify/smart_todo/pull/69)
132
135
  * [sorbet-eraser](https://github.com/kddnewton/sorbet-eraser/pull/25)
133
136
  * [synvert](https://github.com/xinminlabs/synvert-core-ruby)
137
+ * [typeprof](https://github.com/ruby/typeprof)
134
138
 
135
139
  ### Applications
136
140