prism 1.3.0 → 1.4.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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/config.yml +9 -0
  4. data/docs/releasing.md +1 -1
  5. data/docs/ruby_api.md +1 -1
  6. data/ext/prism/api_node.c +1814 -1303
  7. data/ext/prism/extension.c +230 -109
  8. data/ext/prism/extension.h +4 -4
  9. data/include/prism/ast.h +16 -0
  10. data/include/prism/defines.h +4 -1
  11. data/include/prism/options.h +47 -1
  12. data/include/prism/util/pm_buffer.h +10 -0
  13. data/include/prism/version.h +2 -2
  14. data/include/prism.h +4 -4
  15. data/lib/prism/dot_visitor.rb +16 -0
  16. data/lib/prism/dsl.rb +10 -2
  17. data/lib/prism/ffi.rb +45 -27
  18. data/lib/prism/inspect_visitor.rb +2 -1
  19. data/lib/prism/node.rb +48 -10
  20. data/lib/prism/parse_result/newlines.rb +1 -1
  21. data/lib/prism/parse_result.rb +52 -0
  22. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  23. data/lib/prism/reflection.rb +2 -2
  24. data/lib/prism/serialize.rb +1252 -765
  25. data/lib/prism/translation/parser/builder.rb +61 -0
  26. data/lib/prism/translation/parser/compiler.rb +192 -136
  27. data/lib/prism/translation/parser/lexer.rb +435 -61
  28. data/lib/prism/translation/parser.rb +51 -3
  29. data/lib/prism/translation/parser35.rb +12 -0
  30. data/lib/prism/translation/ripper.rb +13 -3
  31. data/lib/prism/translation/ruby_parser.rb +5 -4
  32. data/lib/prism/translation.rb +1 -0
  33. data/lib/prism.rb +3 -3
  34. data/prism.gemspec +5 -1
  35. data/rbi/prism/dsl.rbi +6 -3
  36. data/rbi/prism/node.rbi +22 -7
  37. data/rbi/prism/parse_result.rbi +17 -0
  38. data/rbi/prism/translation/parser35.rbi +6 -0
  39. data/rbi/prism.rbi +39 -36
  40. data/sig/prism/dsl.rbs +4 -2
  41. data/sig/prism/node.rbs +17 -7
  42. data/sig/prism/parse_result.rbs +10 -0
  43. data/sig/prism/serialize.rbs +4 -2
  44. data/sig/prism.rbs +22 -1
  45. data/src/diagnostic.c +2 -2
  46. data/src/node.c +21 -0
  47. data/src/options.c +31 -0
  48. data/src/prettyprint.c +30 -0
  49. data/src/prism.c +374 -118
  50. data/src/serialize.c +6 -0
  51. data/src/util/pm_buffer.c +40 -0
  52. data/src/util/pm_constant_pool.c +6 -2
  53. data/src/util/pm_strncasecmp.c +13 -1
  54. metadata +7 -7
data/src/serialize.c CHANGED
@@ -1706,6 +1706,12 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1706
1706
  } else {
1707
1707
  pm_serialize_node(parser, (pm_node_t *)((pm_rescue_node_t *)node)->reference, buffer);
1708
1708
  }
1709
+ if (((pm_rescue_node_t *)node)->then_keyword_loc.start == NULL) {
1710
+ pm_buffer_append_byte(buffer, 0);
1711
+ } else {
1712
+ pm_buffer_append_byte(buffer, 1);
1713
+ pm_serialize_location(parser, &((pm_rescue_node_t *)node)->then_keyword_loc, buffer);
1714
+ }
1709
1715
  if (((pm_rescue_node_t *)node)->statements == NULL) {
1710
1716
  pm_buffer_append_byte(buffer, 0);
1711
1717
  } else {
data/src/util/pm_buffer.c CHANGED
@@ -172,6 +172,46 @@ pm_buffer_append_double(pm_buffer_t *buffer, double value) {
172
172
  pm_buffer_append(buffer, source, sizeof(double));
173
173
  }
174
174
 
175
+ /**
176
+ * Append a unicode codepoint to the buffer.
177
+ */
178
+ bool
179
+ pm_buffer_append_unicode_codepoint(pm_buffer_t *buffer, uint32_t value) {
180
+ if (value <= 0x7F) {
181
+ pm_buffer_append_byte(buffer, (uint8_t) value); // 0xxxxxxx
182
+ return true;
183
+ } else if (value <= 0x7FF) {
184
+ uint8_t bytes[] = {
185
+ (uint8_t) (0xC0 | ((value >> 6) & 0x3F)), // 110xxxxx
186
+ (uint8_t) (0x80 | (value & 0x3F)) // 10xxxxxx
187
+ };
188
+
189
+ pm_buffer_append_bytes(buffer, bytes, 2);
190
+ return true;
191
+ } else if (value <= 0xFFFF) {
192
+ uint8_t bytes[] = {
193
+ (uint8_t) (0xE0 | ((value >> 12) & 0x3F)), // 1110xxxx
194
+ (uint8_t) (0x80 | ((value >> 6) & 0x3F)), // 10xxxxxx
195
+ (uint8_t) (0x80 | (value & 0x3F)) // 10xxxxxx
196
+ };
197
+
198
+ pm_buffer_append_bytes(buffer, bytes, 3);
199
+ return true;
200
+ } else if (value <= 0x10FFFF) {
201
+ uint8_t bytes[] = {
202
+ (uint8_t) (0xF0 | ((value >> 18) & 0x3F)), // 11110xxx
203
+ (uint8_t) (0x80 | ((value >> 12) & 0x3F)), // 10xxxxxx
204
+ (uint8_t) (0x80 | ((value >> 6) & 0x3F)), // 10xxxxxx
205
+ (uint8_t) (0x80 | (value & 0x3F)) // 10xxxxxx
206
+ };
207
+
208
+ pm_buffer_append_bytes(buffer, bytes, 4);
209
+ return true;
210
+ } else {
211
+ return false;
212
+ }
213
+ }
214
+
175
215
  /**
176
216
  * Append a slice of source code to the buffer.
177
217
  */
@@ -15,8 +15,12 @@ pm_constant_id_list_init(pm_constant_id_list_t *list) {
15
15
  */
16
16
  void
17
17
  pm_constant_id_list_init_capacity(pm_constant_id_list_t *list, size_t capacity) {
18
- list->ids = xcalloc(capacity, sizeof(pm_constant_id_t));
19
- if (list->ids == NULL) abort();
18
+ if (capacity) {
19
+ list->ids = xcalloc(capacity, sizeof(pm_constant_id_t));
20
+ if (list->ids == NULL) abort();
21
+ } else {
22
+ list->ids = NULL;
23
+ }
20
24
 
21
25
  list->size = 0;
22
26
  list->capacity = capacity;
@@ -1,5 +1,17 @@
1
1
  #include "prism/util/pm_strncasecmp.h"
2
2
 
3
+ /**
4
+ * A locale-insensitive version of `tolower(3)`
5
+ */
6
+ static inline int
7
+ pm_tolower(int c)
8
+ {
9
+ if ('A' <= c && c <= 'Z') {
10
+ return c | 0x20;
11
+ }
12
+ return c;
13
+ }
14
+
3
15
  /**
4
16
  * Compare two strings, ignoring case, up to the given length. Returns 0 if the
5
17
  * strings are equal, a negative number if string1 is less than string2, or a
@@ -16,7 +28,7 @@ pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length) {
16
28
 
17
29
  while (offset < length && string1[offset] != '\0') {
18
30
  if (string2[offset] == '\0') return string1[offset];
19
- if ((difference = tolower(string1[offset]) - tolower(string2[offset])) != 0) return difference;
31
+ if ((difference = pm_tolower(string1[offset]) - pm_tolower(string2[offset])) != 0) return difference;
20
32
  offset++;
21
33
  }
22
34
 
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prism
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-21 00:00:00.000000000 Z
10
+ date: 2025-03-18 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
14
12
  email:
15
13
  - ruby@shopify.com
16
14
  executables: []
@@ -91,6 +89,7 @@ files:
91
89
  - lib/prism/parse_result/errors.rb
92
90
  - lib/prism/parse_result/newlines.rb
93
91
  - lib/prism/pattern.rb
92
+ - lib/prism/polyfill/append_as_bytes.rb
94
93
  - lib/prism/polyfill/byteindex.rb
95
94
  - lib/prism/polyfill/unpack1.rb
96
95
  - lib/prism/reflection.rb
@@ -99,10 +98,12 @@ files:
99
98
  - lib/prism/string_query.rb
100
99
  - lib/prism/translation.rb
101
100
  - lib/prism/translation/parser.rb
101
+ - lib/prism/translation/parser/builder.rb
102
102
  - lib/prism/translation/parser/compiler.rb
103
103
  - lib/prism/translation/parser/lexer.rb
104
104
  - lib/prism/translation/parser33.rb
105
105
  - lib/prism/translation/parser34.rb
106
+ - lib/prism/translation/parser35.rb
106
107
  - lib/prism/translation/ripper.rb
107
108
  - lib/prism/translation/ripper/sexp.rb
108
109
  - lib/prism/translation/ripper/shim.rb
@@ -121,6 +122,7 @@ files:
121
122
  - rbi/prism/translation/parser.rbi
122
123
  - rbi/prism/translation/parser33.rbi
123
124
  - rbi/prism/translation/parser34.rbi
125
+ - rbi/prism/translation/parser35.rbi
124
126
  - rbi/prism/translation/ripper.rbi
125
127
  - rbi/prism/visitor.rbi
126
128
  - sig/prism.rbs
@@ -169,7 +171,6 @@ metadata:
169
171
  allowed_push_host: https://rubygems.org
170
172
  source_code_uri: https://github.com/ruby/prism
171
173
  changelog_uri: https://github.com/ruby/prism/blob/main/CHANGELOG.md
172
- post_install_message:
173
174
  rdoc_options: []
174
175
  require_paths:
175
176
  - lib
@@ -184,8 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
185
  - !ruby/object:Gem::Version
185
186
  version: '0'
186
187
  requirements: []
187
- rubygems_version: 3.5.16
188
- signing_key:
188
+ rubygems_version: 3.6.2
189
189
  specification_version: 4
190
190
  summary: Prism Ruby parser
191
191
  test_files: []