prism 1.5.1 → 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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +74 -1
  3. data/Makefile +12 -5
  4. data/README.md +2 -1
  5. data/config.yml +34 -8
  6. data/docs/build_system.md +2 -2
  7. data/docs/cruby_compilation.md +1 -1
  8. data/docs/design.md +2 -2
  9. data/docs/parser_translation.md +1 -1
  10. data/docs/releasing.md +4 -25
  11. data/docs/ripper_translation.md +8 -17
  12. data/docs/ruby_api.md +1 -0
  13. data/ext/prism/api_node.c +7 -3
  14. data/ext/prism/extconf.rb +1 -1
  15. data/ext/prism/extension.c +10 -2
  16. data/ext/prism/extension.h +1 -1
  17. data/include/prism/ast.h +89 -25
  18. data/include/prism/diagnostic.h +3 -0
  19. data/include/prism/options.h +8 -2
  20. data/include/prism/parser.h +3 -0
  21. data/include/prism/version.h +3 -3
  22. data/include/prism.h +1 -1
  23. data/lib/prism/compiler.rb +152 -152
  24. data/lib/prism/dot_visitor.rb +5 -0
  25. data/lib/prism/dsl.rb +2 -2
  26. data/lib/prism/ffi.rb +11 -3
  27. data/lib/prism/inspect_visitor.rb +1 -0
  28. data/lib/prism/lex_compat.rb +133 -150
  29. data/lib/prism/node.rb +1184 -34
  30. data/lib/prism/parse_result.rb +11 -15
  31. data/lib/prism/polyfill/scan_byte.rb +1 -1
  32. data/lib/prism/polyfill/warn.rb +16 -22
  33. data/lib/prism/reflection.rb +1 -1
  34. data/lib/prism/serialize.rb +8 -5
  35. data/lib/prism/translation/parser/compiler.rb +16 -16
  36. data/lib/prism/translation/parser.rb +12 -3
  37. data/lib/prism/translation/parser_current.rb +5 -3
  38. data/lib/prism/translation/parser_versions.rb +36 -0
  39. data/lib/prism/translation/ripper/filter.rb +53 -0
  40. data/lib/prism/translation/ripper/lexer.rb +135 -0
  41. data/lib/prism/translation/ripper.rb +86 -40
  42. data/lib/prism/translation/ruby_parser.rb +55 -20
  43. data/lib/prism/translation.rb +5 -3
  44. data/lib/prism/visitor.rb +152 -152
  45. data/lib/prism.rb +21 -14
  46. data/prism.gemspec +5 -7
  47. data/rbi/prism/dsl.rbi +3 -3
  48. data/rbi/prism/node.rbi +24 -8
  49. data/rbi/prism/translation/parser_versions.rbi +23 -0
  50. data/rbi/prism.rbi +0 -3
  51. data/sig/prism/dsl.rbs +2 -2
  52. data/sig/prism/node.rbs +22 -8
  53. data/sig/prism/parse_result.rbs +1 -0
  54. data/sig/prism.rbs +58 -40
  55. data/src/diagnostic.c +7 -1
  56. data/src/encoding.c +172 -67
  57. data/src/node.c +9 -0
  58. data/src/options.c +17 -7
  59. data/src/prettyprint.c +16 -0
  60. data/src/prism.c +1335 -1958
  61. data/src/serialize.c +7 -1
  62. data/src/token_type.c +2 -2
  63. data/src/util/pm_constant_pool.c +1 -1
  64. data/src/util/pm_string.c +6 -8
  65. metadata +7 -9
  66. data/lib/prism/translation/parser33.rb +0 -13
  67. data/lib/prism/translation/parser34.rb +0 -13
  68. data/lib/prism/translation/parser35.rb +0 -13
  69. data/rbi/prism/translation/parser33.rbi +0 -6
  70. data/rbi/prism/translation/parser34.rbi +0 -6
  71. data/rbi/prism/translation/parser35.rbi +0 -6
data/include/prism/ast.h CHANGED
@@ -76,6 +76,9 @@ typedef enum pm_token_type {
76
76
  /** ) */
77
77
  PM_TOKEN_PARENTHESIS_RIGHT,
78
78
 
79
+ /** | */
80
+ PM_TOKEN_PIPE,
81
+
79
82
  /** ; */
80
83
  PM_TOKEN_SEMICOLON,
81
84
 
@@ -424,9 +427,6 @@ typedef enum pm_token_type {
424
427
  /** %W */
425
428
  PM_TOKEN_PERCENT_UPPER_W,
426
429
 
427
- /** | */
428
- PM_TOKEN_PIPE,
429
-
430
430
  /** |= */
431
431
  PM_TOKEN_PIPE_EQUAL,
432
432
 
@@ -1050,22 +1050,6 @@ typedef uint16_t pm_node_flags_t;
1050
1050
  static const pm_node_flags_t PM_NODE_FLAG_NEWLINE = 0x1;
1051
1051
  static const pm_node_flags_t PM_NODE_FLAG_STATIC_LITERAL = 0x2;
1052
1052
 
1053
- /**
1054
- * Cast the type to an enum to allow the compiler to provide exhaustiveness
1055
- * checking.
1056
- */
1057
- #define PM_NODE_TYPE(node) ((enum pm_node_type) (node)->type)
1058
-
1059
- /**
1060
- * Return true if the type of the given node matches the given type.
1061
- */
1062
- #define PM_NODE_TYPE_P(node, type) (PM_NODE_TYPE(node) == (type))
1063
-
1064
- /**
1065
- * Return true if the given flag is set on the given node.
1066
- */
1067
- #define PM_NODE_FLAG_P(node, flag) ((((pm_node_t *)(node))->flags & (flag)) != 0)
1068
-
1069
1053
  /**
1070
1054
  * This is the base structure that represents a node in the syntax tree. It is
1071
1055
  * embedded into every node type.
@@ -1096,6 +1080,32 @@ typedef struct pm_node {
1096
1080
  pm_location_t location;
1097
1081
  } pm_node_t;
1098
1082
 
1083
+ /**
1084
+ * Cast the given node to the base pm_node_t type.
1085
+ */
1086
+ #define PM_NODE_UPCAST(node_) ((pm_node_t *) (node_))
1087
+
1088
+ /**
1089
+ * Cast the type to an enum to allow the compiler to provide exhaustiveness
1090
+ * checking.
1091
+ */
1092
+ #define PM_NODE_TYPE(node_) ((enum pm_node_type) (node_)->type)
1093
+
1094
+ /**
1095
+ * Return true if the type of the given node matches the given type.
1096
+ */
1097
+ #define PM_NODE_TYPE_P(node_, type_) (PM_NODE_TYPE(node_) == (type_))
1098
+
1099
+ /**
1100
+ * Return the flags associated with the given node.
1101
+ */
1102
+ #define PM_NODE_FLAGS(node_) (PM_NODE_UPCAST(node_)->flags)
1103
+
1104
+ /**
1105
+ * Return true if the given flag is set on the given node.
1106
+ */
1107
+ #define PM_NODE_FLAG_P(node_, flag_) ((PM_NODE_FLAGS(node_) & (flag_)) != 0)
1108
+
1099
1109
  /**
1100
1110
  * AliasGlobalVariableNode
1101
1111
  *
@@ -1816,20 +1826,20 @@ typedef struct pm_block_node {
1816
1826
  /**
1817
1827
  * BlockNode#opening_loc
1818
1828
  *
1819
- * Represents the location of the opening `|`.
1829
+ * Represents the location of the opening `{` or `do`.
1820
1830
  *
1821
1831
  * [1, 2, 3].each { |i| puts x }
1822
- * ^
1832
+ * ^
1823
1833
  */
1824
1834
  pm_location_t opening_loc;
1825
1835
 
1826
1836
  /**
1827
1837
  * BlockNode#closing_loc
1828
1838
  *
1829
- * Represents the location of the closing `|`.
1839
+ * Represents the location of the closing `}` or `end`.
1830
1840
  *
1831
1841
  * [1, 2, 3].each { |i| puts x }
1832
- * ^
1842
+ * ^
1833
1843
  */
1834
1844
  pm_location_t closing_loc;
1835
1845
  } pm_block_node_t;
@@ -2214,6 +2224,19 @@ typedef struct pm_call_node {
2214
2224
  */
2215
2225
  pm_location_t closing_loc;
2216
2226
 
2227
+ /**
2228
+ * CallNode#equal_loc
2229
+ *
2230
+ * Represents the location of the equal sign, in the case that this is an attribute write.
2231
+ *
2232
+ * foo.bar = value
2233
+ * ^
2234
+ *
2235
+ * foo[bar] = value
2236
+ * ^
2237
+ */
2238
+ pm_location_t equal_loc;
2239
+
2217
2240
  /**
2218
2241
  * CallNode#block
2219
2242
  *
@@ -2638,7 +2661,7 @@ typedef struct pm_case_node {
2638
2661
  * Represents the predicate of the case statement. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
2639
2662
  *
2640
2663
  * case true; when false; end
2641
- * ^^^^
2664
+ * ^^^^
2642
2665
  */
2643
2666
  struct pm_node *predicate;
2644
2667
 
@@ -4084,11 +4107,16 @@ typedef struct pm_forwarding_parameter_node {
4084
4107
  /**
4085
4108
  * ForwardingSuperNode
4086
4109
  *
4087
- * Represents the use of the `super` keyword without parentheses or arguments.
4110
+ * Represents the use of the `super` keyword without parentheses or arguments, but which might have a block.
4088
4111
  *
4089
4112
  * super
4090
4113
  * ^^^^^
4091
4114
  *
4115
+ * super { 123 }
4116
+ * ^^^^^^^^^^^^^
4117
+ *
4118
+ * If it has any other arguments, it would be a `SuperNode` instead.
4119
+ *
4092
4120
  * Type: ::PM_FORWARDING_SUPER_NODE
4093
4121
  *
4094
4122
  * @extends pm_node_t
@@ -4100,6 +4128,8 @@ typedef struct pm_forwarding_super_node {
4100
4128
 
4101
4129
  /**
4102
4130
  * ForwardingSuperNode#block
4131
+ *
4132
+ * All other arguments are forwarded as normal, except the original block is replaced with the new block.
4103
4133
  */
4104
4134
  struct pm_block_node *block;
4105
4135
  } pm_forwarding_super_node_t;
@@ -7539,6 +7569,8 @@ typedef struct pm_string_node {
7539
7569
  * super foo, bar
7540
7570
  * ^^^^^^^^^^^^^^
7541
7571
  *
7572
+ * If no arguments are provided (except for a block), it would be a `ForwardingSuperNode` instead.
7573
+ *
7542
7574
  * Type: ::PM_SUPER_NODE
7543
7575
  *
7544
7576
  * @extends pm_node_t
@@ -7560,6 +7592,8 @@ typedef struct pm_super_node {
7560
7592
 
7561
7593
  /**
7562
7594
  * SuperNode#arguments
7595
+ *
7596
+ * Can be only `nil` when there are empty parentheses, like `super()`.
7563
7597
  */
7564
7598
  struct pm_arguments_node *arguments;
7565
7599
 
@@ -7990,6 +8024,8 @@ typedef enum pm_arguments_node_flags {
7990
8024
 
7991
8025
  /** if the arguments contain multiple splats */
7992
8026
  PM_ARGUMENTS_NODE_FLAGS_CONTAINS_MULTIPLE_SPLATS = 64,
8027
+
8028
+ PM_ARGUMENTS_NODE_FLAGS_LAST,
7993
8029
  } pm_arguments_node_flags_t;
7994
8030
 
7995
8031
  /**
@@ -7998,6 +8034,8 @@ typedef enum pm_arguments_node_flags {
7998
8034
  typedef enum pm_array_node_flags {
7999
8035
  /** if array contains splat nodes */
8000
8036
  PM_ARRAY_NODE_FLAGS_CONTAINS_SPLAT = 4,
8037
+
8038
+ PM_ARRAY_NODE_FLAGS_LAST,
8001
8039
  } pm_array_node_flags_t;
8002
8040
 
8003
8041
  /**
@@ -8015,6 +8053,8 @@ typedef enum pm_call_node_flags {
8015
8053
 
8016
8054
  /** a call that ignores method visibility */
8017
8055
  PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY = 32,
8056
+
8057
+ PM_CALL_NODE_FLAGS_LAST,
8018
8058
  } pm_call_node_flags_t;
8019
8059
 
8020
8060
  /**
@@ -8026,6 +8066,8 @@ typedef enum pm_encoding_flags {
8026
8066
 
8027
8067
  /** internal bytes forced the encoding to binary */
8028
8068
  PM_ENCODING_FLAGS_FORCED_BINARY_ENCODING = 8,
8069
+
8070
+ PM_ENCODING_FLAGS_LAST,
8029
8071
  } pm_encoding_flags_t;
8030
8072
 
8031
8073
  /**
@@ -8043,6 +8085,8 @@ typedef enum pm_integer_base_flags {
8043
8085
 
8044
8086
  /** 0x prefix */
8045
8087
  PM_INTEGER_BASE_FLAGS_HEXADECIMAL = 32,
8088
+
8089
+ PM_INTEGER_BASE_FLAGS_LAST,
8046
8090
  } pm_integer_base_flags_t;
8047
8091
 
8048
8092
  /**
@@ -8054,6 +8098,8 @@ typedef enum pm_interpolated_string_node_flags {
8054
8098
 
8055
8099
  /** mutable by virtue of a `frozen_string_literal: false` comment or `--disable-frozen-string-literal`; only for adjacent string literals like `'a' 'b'` */
8056
8100
  PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE = 8,
8101
+
8102
+ PM_INTERPOLATED_STRING_NODE_FLAGS_LAST,
8057
8103
  } pm_interpolated_string_node_flags_t;
8058
8104
 
8059
8105
  /**
@@ -8062,6 +8108,8 @@ typedef enum pm_interpolated_string_node_flags {
8062
8108
  typedef enum pm_keyword_hash_node_flags {
8063
8109
  /** a keyword hash which only has `AssocNode` elements all with symbol keys, which means the elements can be treated as keyword arguments */
8064
8110
  PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS = 4,
8111
+
8112
+ PM_KEYWORD_HASH_NODE_FLAGS_LAST,
8065
8113
  } pm_keyword_hash_node_flags_t;
8066
8114
 
8067
8115
  /**
@@ -8070,6 +8118,8 @@ typedef enum pm_keyword_hash_node_flags {
8070
8118
  typedef enum pm_loop_flags {
8071
8119
  /** a loop after a begin statement, so the body is executed first before the condition */
8072
8120
  PM_LOOP_FLAGS_BEGIN_MODIFIER = 4,
8121
+
8122
+ PM_LOOP_FLAGS_LAST,
8073
8123
  } pm_loop_flags_t;
8074
8124
 
8075
8125
  /**
@@ -8078,6 +8128,8 @@ typedef enum pm_loop_flags {
8078
8128
  typedef enum pm_parameter_flags {
8079
8129
  /** a parameter name that has been repeated in the method signature */
8080
8130
  PM_PARAMETER_FLAGS_REPEATED_PARAMETER = 4,
8131
+
8132
+ PM_PARAMETER_FLAGS_LAST,
8081
8133
  } pm_parameter_flags_t;
8082
8134
 
8083
8135
  /**
@@ -8086,6 +8138,8 @@ typedef enum pm_parameter_flags {
8086
8138
  typedef enum pm_parentheses_node_flags {
8087
8139
  /** parentheses that contain multiple potentially void statements */
8088
8140
  PM_PARENTHESES_NODE_FLAGS_MULTIPLE_STATEMENTS = 4,
8141
+
8142
+ PM_PARENTHESES_NODE_FLAGS_LAST,
8089
8143
  } pm_parentheses_node_flags_t;
8090
8144
 
8091
8145
  /**
@@ -8094,6 +8148,8 @@ typedef enum pm_parentheses_node_flags {
8094
8148
  typedef enum pm_range_flags {
8095
8149
  /** ... operator */
8096
8150
  PM_RANGE_FLAGS_EXCLUDE_END = 4,
8151
+
8152
+ PM_RANGE_FLAGS_LAST,
8097
8153
  } pm_range_flags_t;
8098
8154
 
8099
8155
  /**
@@ -8132,6 +8188,8 @@ typedef enum pm_regular_expression_flags {
8132
8188
 
8133
8189
  /** internal bytes forced the encoding to US-ASCII */
8134
8190
  PM_REGULAR_EXPRESSION_FLAGS_FORCED_US_ASCII_ENCODING = 4096,
8191
+
8192
+ PM_REGULAR_EXPRESSION_FLAGS_LAST,
8135
8193
  } pm_regular_expression_flags_t;
8136
8194
 
8137
8195
  /**
@@ -8146,6 +8204,8 @@ typedef enum pm_shareable_constant_node_flags {
8146
8204
 
8147
8205
  /** constant writes that should be modified with shareable constant value experimental copy */
8148
8206
  PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY = 16,
8207
+
8208
+ PM_SHAREABLE_CONSTANT_NODE_FLAGS_LAST,
8149
8209
  } pm_shareable_constant_node_flags_t;
8150
8210
 
8151
8211
  /**
@@ -8163,6 +8223,8 @@ typedef enum pm_string_flags {
8163
8223
 
8164
8224
  /** mutable by virtue of a `frozen_string_literal: false` comment or `--disable-frozen-string-literal` */
8165
8225
  PM_STRING_FLAGS_MUTABLE = 32,
8226
+
8227
+ PM_STRING_FLAGS_LAST,
8166
8228
  } pm_string_flags_t;
8167
8229
 
8168
8230
  /**
@@ -8177,6 +8239,8 @@ typedef enum pm_symbol_flags {
8177
8239
 
8178
8240
  /** internal bytes forced the encoding to US-ASCII */
8179
8241
  PM_SYMBOL_FLAGS_FORCED_US_ASCII_ENCODING = 16,
8242
+
8243
+ PM_SYMBOL_FLAGS_LAST,
8180
8244
  } pm_symbol_flags_t;
8181
8245
 
8182
8246
  /**
@@ -91,6 +91,7 @@ typedef enum {
91
91
  PM_ERR_CONDITIONAL_WHILE_PREDICATE,
92
92
  PM_ERR_CONSTANT_PATH_COLON_COLON_CONSTANT,
93
93
  PM_ERR_DEF_ENDLESS,
94
+ PM_ERR_DEF_ENDLESS_PARAMETERS,
94
95
  PM_ERR_DEF_ENDLESS_SETTER,
95
96
  PM_ERR_DEF_NAME,
96
97
  PM_ERR_DEF_PARAMS_TERM,
@@ -249,6 +250,7 @@ typedef enum {
249
250
  PM_ERR_PARAMETER_WILD_LOOSE_COMMA,
250
251
  PM_ERR_PATTERN_ARRAY_MULTIPLE_RESTS,
251
252
  PM_ERR_PATTERN_CAPTURE_DUPLICATE,
253
+ PM_ERR_PATTERN_CAPTURE_IN_ALTERNATIVE,
252
254
  PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET,
253
255
  PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA,
254
256
  PM_ERR_PATTERN_EXPRESSION_AFTER_HROCKET,
@@ -310,6 +312,7 @@ typedef enum {
310
312
  PM_ERR_UNEXPECTED_INDEX_KEYWORDS,
311
313
  PM_ERR_UNEXPECTED_LABEL,
312
314
  PM_ERR_UNEXPECTED_MULTI_WRITE,
315
+ PM_ERR_UNEXPECTED_PARAMETER_DEFAULT_VALUE,
313
316
  PM_ERR_UNEXPECTED_RANGE_OPERATOR,
314
317
  PM_ERR_UNEXPECTED_SAFE_NAVIGATION,
315
318
  PM_ERR_UNEXPECTED_TOKEN_CLOSE_CONTEXT,
@@ -91,11 +91,17 @@ typedef enum {
91
91
  /** The vendored version of prism in CRuby 3.4.x. */
92
92
  PM_OPTIONS_VERSION_CRUBY_3_4 = 2,
93
93
 
94
- /** The vendored version of prism in CRuby 3.5.x. */
94
+ /** The vendored version of prism in CRuby 4.0.x. */
95
95
  PM_OPTIONS_VERSION_CRUBY_3_5 = 3,
96
96
 
97
+ /** The vendored version of prism in CRuby 4.0.x. */
98
+ PM_OPTIONS_VERSION_CRUBY_4_0 = 3,
99
+
100
+ /** The vendored version of prism in CRuby 4.1.x. */
101
+ PM_OPTIONS_VERSION_CRUBY_4_1 = 4,
102
+
97
103
  /** The current version of prism. */
98
- PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_3_5
104
+ PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_4_1
99
105
  } pm_options_version_t;
100
106
 
101
107
  /**
@@ -299,6 +299,9 @@ typedef enum {
299
299
  /** a rescue else statement within a do..end block */
300
300
  PM_CONTEXT_BLOCK_ELSE,
301
301
 
302
+ /** expressions in block parameters `foo do |...| end ` */
303
+ PM_CONTEXT_BLOCK_PARAMETERS,
304
+
302
305
  /** a rescue statement within a do..end block */
303
306
  PM_CONTEXT_BLOCK_RESCUE,
304
307
 
@@ -14,16 +14,16 @@
14
14
  /**
15
15
  * The minor version of the Prism library as an int.
16
16
  */
17
- #define PRISM_VERSION_MINOR 5
17
+ #define PRISM_VERSION_MINOR 9
18
18
 
19
19
  /**
20
20
  * The patch version of the Prism library as an int.
21
21
  */
22
- #define PRISM_VERSION_PATCH 1
22
+ #define PRISM_VERSION_PATCH 0
23
23
 
24
24
  /**
25
25
  * The version of the Prism library as a constant string.
26
26
  */
27
- #define PRISM_VERSION "1.5.1"
27
+ #define PRISM_VERSION "1.9.0"
28
28
 
29
29
  #endif
data/include/prism.h CHANGED
@@ -314,7 +314,7 @@ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint
314
314
  * dependencies. It is currently being integrated into
315
315
  * [CRuby](https://github.com/ruby/ruby),
316
316
  * [JRuby](https://github.com/jruby/jruby),
317
- * [TruffleRuby](https://github.com/oracle/truffleruby),
317
+ * [TruffleRuby](https://github.com/truffleruby/truffleruby),
318
318
  * [Sorbet](https://github.com/sorbet/sorbet), and
319
319
  * [Syntax Tree](https://github.com/ruby-syntax-tree/syntax_tree).
320
320
  *