prism 0.29.0 → 0.30.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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -1
  3. data/CONTRIBUTING.md +0 -4
  4. data/README.md +1 -0
  5. data/config.yml +66 -9
  6. data/docs/fuzzing.md +1 -1
  7. data/docs/ripper_translation.md +22 -0
  8. data/ext/prism/api_node.c +30 -12
  9. data/ext/prism/extension.c +107 -372
  10. data/ext/prism/extension.h +1 -1
  11. data/include/prism/ast.h +138 -70
  12. data/include/prism/diagnostic.h +7 -2
  13. data/include/prism/node.h +0 -21
  14. data/include/prism/parser.h +23 -25
  15. data/include/prism/regexp.h +17 -8
  16. data/include/prism/static_literals.h +3 -2
  17. data/include/prism/util/pm_char.h +1 -2
  18. data/include/prism/util/pm_constant_pool.h +0 -8
  19. data/include/prism/util/pm_integer.h +16 -9
  20. data/include/prism/util/pm_string.h +0 -8
  21. data/include/prism/version.h +2 -2
  22. data/include/prism.h +0 -11
  23. data/lib/prism/compiler.rb +3 -0
  24. data/lib/prism/dispatcher.rb +14 -0
  25. data/lib/prism/dot_visitor.rb +22 -3
  26. data/lib/prism/dsl.rb +7 -2
  27. data/lib/prism/ffi.rb +24 -3
  28. data/lib/prism/inspect_visitor.rb +10 -8
  29. data/lib/prism/mutation_compiler.rb +6 -1
  30. data/lib/prism/node.rb +166 -241
  31. data/lib/prism/node_ext.rb +21 -5
  32. data/lib/prism/parse_result/comments.rb +0 -7
  33. data/lib/prism/parse_result/newlines.rb +101 -11
  34. data/lib/prism/parse_result.rb +17 -0
  35. data/lib/prism/reflection.rb +3 -1
  36. data/lib/prism/serialize.rb +80 -67
  37. data/lib/prism/translation/parser/compiler.rb +134 -114
  38. data/lib/prism/translation/parser.rb +6 -1
  39. data/lib/prism/translation/ripper.rb +8 -6
  40. data/lib/prism/translation/ruby_parser.rb +23 -5
  41. data/lib/prism/visitor.rb +3 -0
  42. data/lib/prism.rb +0 -4
  43. data/prism.gemspec +1 -4
  44. data/rbi/prism/node.rbi +63 -6
  45. data/rbi/prism/visitor.rbi +3 -0
  46. data/rbi/prism.rbi +6 -0
  47. data/sig/prism/dsl.rbs +4 -1
  48. data/sig/prism/mutation_compiler.rbs +1 -0
  49. data/sig/prism/node.rbs +28 -4
  50. data/sig/prism/visitor.rbs +1 -0
  51. data/sig/prism.rbs +21 -0
  52. data/src/diagnostic.c +27 -17
  53. data/src/node.c +408 -1666
  54. data/src/prettyprint.c +49 -6
  55. data/src/prism.c +958 -991
  56. data/src/regexp.c +133 -68
  57. data/src/serialize.c +6 -1
  58. data/src/static_literals.c +63 -84
  59. data/src/token_type.c +2 -2
  60. data/src/util/pm_constant_pool.c +0 -8
  61. data/src/util/pm_integer.c +39 -11
  62. data/src/util/pm_string.c +0 -12
  63. data/src/util/pm_strpbrk.c +32 -6
  64. metadata +2 -5
  65. data/include/prism/util/pm_string_list.h +0 -44
  66. data/lib/prism/debug.rb +0 -249
  67. data/src/util/pm_string_list.c +0 -28
data/include/prism/ast.h CHANGED
@@ -831,194 +831,197 @@ enum pm_node_type {
831
831
  /** InterpolatedXStringNode */
832
832
  PM_INTERPOLATED_X_STRING_NODE = 87,
833
833
 
834
+ /** ItLocalVariableReadNode */
835
+ PM_IT_LOCAL_VARIABLE_READ_NODE = 88,
836
+
834
837
  /** ItParametersNode */
835
- PM_IT_PARAMETERS_NODE = 88,
838
+ PM_IT_PARAMETERS_NODE = 89,
836
839
 
837
840
  /** KeywordHashNode */
838
- PM_KEYWORD_HASH_NODE = 89,
841
+ PM_KEYWORD_HASH_NODE = 90,
839
842
 
840
843
  /** KeywordRestParameterNode */
841
- PM_KEYWORD_REST_PARAMETER_NODE = 90,
844
+ PM_KEYWORD_REST_PARAMETER_NODE = 91,
842
845
 
843
846
  /** LambdaNode */
844
- PM_LAMBDA_NODE = 91,
847
+ PM_LAMBDA_NODE = 92,
845
848
 
846
849
  /** LocalVariableAndWriteNode */
847
- PM_LOCAL_VARIABLE_AND_WRITE_NODE = 92,
850
+ PM_LOCAL_VARIABLE_AND_WRITE_NODE = 93,
848
851
 
849
852
  /** LocalVariableOperatorWriteNode */
850
- PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE = 93,
853
+ PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE = 94,
851
854
 
852
855
  /** LocalVariableOrWriteNode */
853
- PM_LOCAL_VARIABLE_OR_WRITE_NODE = 94,
856
+ PM_LOCAL_VARIABLE_OR_WRITE_NODE = 95,
854
857
 
855
858
  /** LocalVariableReadNode */
856
- PM_LOCAL_VARIABLE_READ_NODE = 95,
859
+ PM_LOCAL_VARIABLE_READ_NODE = 96,
857
860
 
858
861
  /** LocalVariableTargetNode */
859
- PM_LOCAL_VARIABLE_TARGET_NODE = 96,
862
+ PM_LOCAL_VARIABLE_TARGET_NODE = 97,
860
863
 
861
864
  /** LocalVariableWriteNode */
862
- PM_LOCAL_VARIABLE_WRITE_NODE = 97,
865
+ PM_LOCAL_VARIABLE_WRITE_NODE = 98,
863
866
 
864
867
  /** MatchLastLineNode */
865
- PM_MATCH_LAST_LINE_NODE = 98,
868
+ PM_MATCH_LAST_LINE_NODE = 99,
866
869
 
867
870
  /** MatchPredicateNode */
868
- PM_MATCH_PREDICATE_NODE = 99,
871
+ PM_MATCH_PREDICATE_NODE = 100,
869
872
 
870
873
  /** MatchRequiredNode */
871
- PM_MATCH_REQUIRED_NODE = 100,
874
+ PM_MATCH_REQUIRED_NODE = 101,
872
875
 
873
876
  /** MatchWriteNode */
874
- PM_MATCH_WRITE_NODE = 101,
877
+ PM_MATCH_WRITE_NODE = 102,
875
878
 
876
879
  /** MissingNode */
877
- PM_MISSING_NODE = 102,
880
+ PM_MISSING_NODE = 103,
878
881
 
879
882
  /** ModuleNode */
880
- PM_MODULE_NODE = 103,
883
+ PM_MODULE_NODE = 104,
881
884
 
882
885
  /** MultiTargetNode */
883
- PM_MULTI_TARGET_NODE = 104,
886
+ PM_MULTI_TARGET_NODE = 105,
884
887
 
885
888
  /** MultiWriteNode */
886
- PM_MULTI_WRITE_NODE = 105,
889
+ PM_MULTI_WRITE_NODE = 106,
887
890
 
888
891
  /** NextNode */
889
- PM_NEXT_NODE = 106,
892
+ PM_NEXT_NODE = 107,
890
893
 
891
894
  /** NilNode */
892
- PM_NIL_NODE = 107,
895
+ PM_NIL_NODE = 108,
893
896
 
894
897
  /** NoKeywordsParameterNode */
895
- PM_NO_KEYWORDS_PARAMETER_NODE = 108,
898
+ PM_NO_KEYWORDS_PARAMETER_NODE = 109,
896
899
 
897
900
  /** NumberedParametersNode */
898
- PM_NUMBERED_PARAMETERS_NODE = 109,
901
+ PM_NUMBERED_PARAMETERS_NODE = 110,
899
902
 
900
903
  /** NumberedReferenceReadNode */
901
- PM_NUMBERED_REFERENCE_READ_NODE = 110,
904
+ PM_NUMBERED_REFERENCE_READ_NODE = 111,
902
905
 
903
906
  /** OptionalKeywordParameterNode */
904
- PM_OPTIONAL_KEYWORD_PARAMETER_NODE = 111,
907
+ PM_OPTIONAL_KEYWORD_PARAMETER_NODE = 112,
905
908
 
906
909
  /** OptionalParameterNode */
907
- PM_OPTIONAL_PARAMETER_NODE = 112,
910
+ PM_OPTIONAL_PARAMETER_NODE = 113,
908
911
 
909
912
  /** OrNode */
910
- PM_OR_NODE = 113,
913
+ PM_OR_NODE = 114,
911
914
 
912
915
  /** ParametersNode */
913
- PM_PARAMETERS_NODE = 114,
916
+ PM_PARAMETERS_NODE = 115,
914
917
 
915
918
  /** ParenthesesNode */
916
- PM_PARENTHESES_NODE = 115,
919
+ PM_PARENTHESES_NODE = 116,
917
920
 
918
921
  /** PinnedExpressionNode */
919
- PM_PINNED_EXPRESSION_NODE = 116,
922
+ PM_PINNED_EXPRESSION_NODE = 117,
920
923
 
921
924
  /** PinnedVariableNode */
922
- PM_PINNED_VARIABLE_NODE = 117,
925
+ PM_PINNED_VARIABLE_NODE = 118,
923
926
 
924
927
  /** PostExecutionNode */
925
- PM_POST_EXECUTION_NODE = 118,
928
+ PM_POST_EXECUTION_NODE = 119,
926
929
 
927
930
  /** PreExecutionNode */
928
- PM_PRE_EXECUTION_NODE = 119,
931
+ PM_PRE_EXECUTION_NODE = 120,
929
932
 
930
933
  /** ProgramNode */
931
- PM_PROGRAM_NODE = 120,
934
+ PM_PROGRAM_NODE = 121,
932
935
 
933
936
  /** RangeNode */
934
- PM_RANGE_NODE = 121,
937
+ PM_RANGE_NODE = 122,
935
938
 
936
939
  /** RationalNode */
937
- PM_RATIONAL_NODE = 122,
940
+ PM_RATIONAL_NODE = 123,
938
941
 
939
942
  /** RedoNode */
940
- PM_REDO_NODE = 123,
943
+ PM_REDO_NODE = 124,
941
944
 
942
945
  /** RegularExpressionNode */
943
- PM_REGULAR_EXPRESSION_NODE = 124,
946
+ PM_REGULAR_EXPRESSION_NODE = 125,
944
947
 
945
948
  /** RequiredKeywordParameterNode */
946
- PM_REQUIRED_KEYWORD_PARAMETER_NODE = 125,
949
+ PM_REQUIRED_KEYWORD_PARAMETER_NODE = 126,
947
950
 
948
951
  /** RequiredParameterNode */
949
- PM_REQUIRED_PARAMETER_NODE = 126,
952
+ PM_REQUIRED_PARAMETER_NODE = 127,
950
953
 
951
954
  /** RescueModifierNode */
952
- PM_RESCUE_MODIFIER_NODE = 127,
955
+ PM_RESCUE_MODIFIER_NODE = 128,
953
956
 
954
957
  /** RescueNode */
955
- PM_RESCUE_NODE = 128,
958
+ PM_RESCUE_NODE = 129,
956
959
 
957
960
  /** RestParameterNode */
958
- PM_REST_PARAMETER_NODE = 129,
961
+ PM_REST_PARAMETER_NODE = 130,
959
962
 
960
963
  /** RetryNode */
961
- PM_RETRY_NODE = 130,
964
+ PM_RETRY_NODE = 131,
962
965
 
963
966
  /** ReturnNode */
964
- PM_RETURN_NODE = 131,
967
+ PM_RETURN_NODE = 132,
965
968
 
966
969
  /** SelfNode */
967
- PM_SELF_NODE = 132,
970
+ PM_SELF_NODE = 133,
968
971
 
969
972
  /** ShareableConstantNode */
970
- PM_SHAREABLE_CONSTANT_NODE = 133,
973
+ PM_SHAREABLE_CONSTANT_NODE = 134,
971
974
 
972
975
  /** SingletonClassNode */
973
- PM_SINGLETON_CLASS_NODE = 134,
976
+ PM_SINGLETON_CLASS_NODE = 135,
974
977
 
975
978
  /** SourceEncodingNode */
976
- PM_SOURCE_ENCODING_NODE = 135,
979
+ PM_SOURCE_ENCODING_NODE = 136,
977
980
 
978
981
  /** SourceFileNode */
979
- PM_SOURCE_FILE_NODE = 136,
982
+ PM_SOURCE_FILE_NODE = 137,
980
983
 
981
984
  /** SourceLineNode */
982
- PM_SOURCE_LINE_NODE = 137,
985
+ PM_SOURCE_LINE_NODE = 138,
983
986
 
984
987
  /** SplatNode */
985
- PM_SPLAT_NODE = 138,
988
+ PM_SPLAT_NODE = 139,
986
989
 
987
990
  /** StatementsNode */
988
- PM_STATEMENTS_NODE = 139,
991
+ PM_STATEMENTS_NODE = 140,
989
992
 
990
993
  /** StringNode */
991
- PM_STRING_NODE = 140,
994
+ PM_STRING_NODE = 141,
992
995
 
993
996
  /** SuperNode */
994
- PM_SUPER_NODE = 141,
997
+ PM_SUPER_NODE = 142,
995
998
 
996
999
  /** SymbolNode */
997
- PM_SYMBOL_NODE = 142,
1000
+ PM_SYMBOL_NODE = 143,
998
1001
 
999
1002
  /** TrueNode */
1000
- PM_TRUE_NODE = 143,
1003
+ PM_TRUE_NODE = 144,
1001
1004
 
1002
1005
  /** UndefNode */
1003
- PM_UNDEF_NODE = 144,
1006
+ PM_UNDEF_NODE = 145,
1004
1007
 
1005
1008
  /** UnlessNode */
1006
- PM_UNLESS_NODE = 145,
1009
+ PM_UNLESS_NODE = 146,
1007
1010
 
1008
1011
  /** UntilNode */
1009
- PM_UNTIL_NODE = 146,
1012
+ PM_UNTIL_NODE = 147,
1010
1013
 
1011
1014
  /** WhenNode */
1012
- PM_WHEN_NODE = 147,
1015
+ PM_WHEN_NODE = 148,
1013
1016
 
1014
1017
  /** WhileNode */
1015
- PM_WHILE_NODE = 148,
1018
+ PM_WHILE_NODE = 149,
1016
1019
 
1017
1020
  /** XStringNode */
1018
- PM_X_STRING_NODE = 149,
1021
+ PM_X_STRING_NODE = 150,
1019
1022
 
1020
1023
  /** YieldNode */
1021
- PM_YIELD_NODE = 150,
1024
+ PM_YIELD_NODE = 151,
1022
1025
 
1023
1026
  /** A special kind of node used for compilation. */
1024
1027
  PM_SCOPE_NODE
@@ -3015,36 +3018,73 @@ typedef struct pm_for_node {
3015
3018
 
3016
3019
  /**
3017
3020
  * ForNode#index
3021
+ *
3022
+ * The index expression for `for` loops.
3023
+ *
3024
+ * for i in a end
3025
+ * ^
3018
3026
  */
3019
3027
  struct pm_node *index;
3020
3028
 
3021
3029
  /**
3022
3030
  * ForNode#collection
3031
+ *
3032
+ * The collection to iterate over.
3033
+ *
3034
+ * for i in a end
3035
+ * ^
3023
3036
  */
3024
3037
  struct pm_node *collection;
3025
3038
 
3026
3039
  /**
3027
3040
  * ForNode#statements
3041
+ *
3042
+ * Represents the body of statements to execute for each iteration of the loop.
3043
+ *
3044
+ * for i in a
3045
+ * foo(i)
3046
+ * ^^^^^^
3047
+ * end
3028
3048
  */
3029
3049
  struct pm_statements_node *statements;
3030
3050
 
3031
3051
  /**
3032
3052
  * ForNode#for_keyword_loc
3053
+ *
3054
+ * The location of the `for` keyword.
3055
+ *
3056
+ * for i in a end
3057
+ * ^^^
3033
3058
  */
3034
3059
  pm_location_t for_keyword_loc;
3035
3060
 
3036
3061
  /**
3037
3062
  * ForNode#in_keyword_loc
3063
+ *
3064
+ * The location of the `in` keyword.
3065
+ *
3066
+ * for i in a end
3067
+ * ^^
3038
3068
  */
3039
3069
  pm_location_t in_keyword_loc;
3040
3070
 
3041
3071
  /**
3042
3072
  * ForNode#do_keyword_loc
3073
+ *
3074
+ * The location of the `do` keyword, if present.
3075
+ *
3076
+ * for i in a do end
3077
+ * ^^
3043
3078
  */
3044
3079
  pm_location_t do_keyword_loc;
3045
3080
 
3046
3081
  /**
3047
3082
  * ForNode#end_keyword_loc
3083
+ *
3084
+ * The location of the `end` keyword.
3085
+ *
3086
+ * for i in a end
3087
+ * ^^^
3048
3088
  */
3049
3089
  pm_location_t end_keyword_loc;
3050
3090
  } pm_for_node_t;
@@ -4148,6 +4188,18 @@ typedef struct pm_interpolated_x_string_node {
4148
4188
  pm_location_t closing_loc;
4149
4189
  } pm_interpolated_x_string_node_t;
4150
4190
 
4191
+ /**
4192
+ * ItLocalVariableReadNode
4193
+ *
4194
+ * Type: PM_IT_LOCAL_VARIABLE_READ_NODE
4195
+ *
4196
+ * @extends pm_node_t
4197
+ */
4198
+ typedef struct pm_it_local_variable_read_node {
4199
+ /** The embedded base node. */
4200
+ pm_node_t base;
4201
+ } pm_it_local_variable_read_node_t;
4202
+
4151
4203
  /**
4152
4204
  * ItParametersNode
4153
4205
  *
@@ -4389,10 +4441,6 @@ typedef struct pm_local_variable_read_node {
4389
4441
  * Note that this can also be an underscore followed by a number for the default block parameters.
4390
4442
  *
4391
4443
  * _1 # name `:_1`
4392
- *
4393
- * Finally, for the default `it` block parameter, the name is `0it`. This is to distinguish it from an `it` local variable that is explicitly declared.
4394
- *
4395
- * it # name `:0it`
4396
4444
  */
4397
4445
  pm_constant_id_t name;
4398
4446
 
@@ -5238,6 +5286,11 @@ typedef struct pm_range_node {
5238
5286
  * RationalNode
5239
5287
  *
5240
5288
  * Type: PM_RATIONAL_NODE
5289
+ * Flags:
5290
+ * PM_INTEGER_BASE_FLAGS_BINARY
5291
+ * PM_INTEGER_BASE_FLAGS_DECIMAL
5292
+ * PM_INTEGER_BASE_FLAGS_OCTAL
5293
+ * PM_INTEGER_BASE_FLAGS_HEXADECIMAL
5241
5294
  *
5242
5295
  * @extends pm_node_t
5243
5296
  */
@@ -5246,9 +5299,22 @@ typedef struct pm_rational_node {
5246
5299
  pm_node_t base;
5247
5300
 
5248
5301
  /**
5249
- * RationalNode#numeric
5302
+ * RationalNode#numerator
5303
+ *
5304
+ * The numerator of the rational number.
5305
+ *
5306
+ * 1.5r # numerator 3
5250
5307
  */
5251
- struct pm_node *numeric;
5308
+ pm_integer_t numerator;
5309
+
5310
+ /**
5311
+ * RationalNode#denominator
5312
+ *
5313
+ * The denominator of the rational number.
5314
+ *
5315
+ * 1.5r # denominator 2
5316
+ */
5317
+ pm_integer_t denominator;
5252
5318
  } pm_rational_node_t;
5253
5319
 
5254
5320
  /**
@@ -5833,7 +5899,9 @@ typedef struct pm_unless_node {
5833
5899
  * UnlessNode#then_keyword_loc
5834
5900
  *
5835
5901
  * The location of the `then` keyword, if present.
5836
- * unless cond then bar end ^^^^
5902
+ *
5903
+ * unless cond then bar end
5904
+ * ^^^^
5837
5905
  */
5838
5906
  pm_location_t then_keyword_loc;
5839
5907
 
@@ -143,6 +143,7 @@ typedef enum {
143
143
  PM_ERR_EXPRESSION_NOT_WRITABLE_FILE,
144
144
  PM_ERR_EXPRESSION_NOT_WRITABLE_LINE,
145
145
  PM_ERR_EXPRESSION_NOT_WRITABLE_NIL,
146
+ PM_ERR_EXPRESSION_NOT_WRITABLE_NUMBERED,
146
147
  PM_ERR_EXPRESSION_NOT_WRITABLE_SELF,
147
148
  PM_ERR_EXPRESSION_NOT_WRITABLE_TRUE,
148
149
  PM_ERR_FLOAT_PARSE,
@@ -182,6 +183,7 @@ typedef enum {
182
183
  PM_ERR_INVALID_NUMBER_UNDERSCORE_INNER,
183
184
  PM_ERR_INVALID_NUMBER_UNDERSCORE_TRAILING,
184
185
  PM_ERR_INVALID_PERCENT,
186
+ PM_ERR_INVALID_PERCENT_EOF,
185
187
  PM_ERR_INVALID_PRINTABLE_CHARACTER,
186
188
  PM_ERR_INVALID_RETRY_AFTER_ELSE,
187
189
  PM_ERR_INVALID_RETRY_AFTER_ENSURE,
@@ -213,9 +215,10 @@ typedef enum {
213
215
  PM_ERR_NO_LOCAL_VARIABLE,
214
216
  PM_ERR_NOT_EXPRESSION,
215
217
  PM_ERR_NUMBER_LITERAL_UNDERSCORE,
218
+ PM_ERR_NUMBERED_PARAMETER_INNER_BLOCK,
216
219
  PM_ERR_NUMBERED_PARAMETER_IT,
217
220
  PM_ERR_NUMBERED_PARAMETER_ORDINARY,
218
- PM_ERR_NUMBERED_PARAMETER_OUTER_SCOPE,
221
+ PM_ERR_NUMBERED_PARAMETER_OUTER_BLOCK,
219
222
  PM_ERR_OPERATOR_MULTI_ASSIGN,
220
223
  PM_ERR_OPERATOR_WRITE_ARGUMENTS,
221
224
  PM_ERR_OPERATOR_WRITE_BLOCK,
@@ -232,8 +235,8 @@ typedef enum {
232
235
  PM_ERR_PARAMETER_SPLAT_MULTI,
233
236
  PM_ERR_PARAMETER_STAR,
234
237
  PM_ERR_PARAMETER_UNEXPECTED_FWD,
235
- PM_ERR_PARAMETER_WILD_LOOSE_COMMA,
236
238
  PM_ERR_PARAMETER_UNEXPECTED_NO_KW,
239
+ PM_ERR_PARAMETER_WILD_LOOSE_COMMA,
237
240
  PM_ERR_PATTERN_CAPTURE_DUPLICATE,
238
241
  PM_ERR_PATTERN_EXPRESSION_AFTER_BRACKET,
239
242
  PM_ERR_PATTERN_EXPRESSION_AFTER_COMMA,
@@ -262,6 +265,7 @@ typedef enum {
262
265
  PM_ERR_REGEXP_INCOMPAT_CHAR_ENCODING,
263
266
  PM_ERR_REGEXP_INVALID_UNICODE_RANGE,
264
267
  PM_ERR_REGEXP_NON_ESCAPED_MBC,
268
+ PM_ERR_REGEXP_PARSE_ERROR,
265
269
  PM_ERR_REGEXP_TERM,
266
270
  PM_ERR_REGEXP_UNKNOWN_OPTIONS,
267
271
  PM_ERR_REGEXP_UTF8_CHAR_NON_UTF8_REGEXP,
@@ -303,6 +307,7 @@ typedef enum {
303
307
  PM_ERR_XSTRING_TERM,
304
308
 
305
309
  // These are the warning diagnostics.
310
+ PM_WARN_AMBIGUOUS_BINARY_OPERATOR,
306
311
  PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS,
307
312
  PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS,
308
313
  PM_WARN_AMBIGUOUS_PREFIX_AMPERSAND,
data/include/prism/node.h CHANGED
@@ -56,27 +56,6 @@ void pm_node_list_free(pm_node_list_t *list);
56
56
  */
57
57
  PRISM_EXPORTED_FUNCTION void pm_node_destroy(pm_parser_t *parser, struct pm_node *node);
58
58
 
59
- /**
60
- * This struct stores the information gathered by the pm_node_memsize function.
61
- * It contains both the memory footprint and additionally metadata about the
62
- * shape of the tree.
63
- */
64
- typedef struct {
65
- /** The total memory footprint of the node and all of its children. */
66
- size_t memsize;
67
-
68
- /** The number of children the node has. */
69
- size_t node_count;
70
- } pm_memsize_t;
71
-
72
- /**
73
- * Calculates the memory footprint of a given node.
74
- *
75
- * @param node The node to calculate the memory footprint of.
76
- * @param memsize The memory footprint of the node and all of its children.
77
- */
78
- PRISM_EXPORTED_FUNCTION void pm_node_memsize(pm_node_t *node, pm_memsize_t *memsize);
79
-
80
59
  /**
81
60
  * Returns a string representation of the given node type.
82
61
  *
@@ -546,6 +546,17 @@ typedef struct pm_locals {
546
546
  pm_local_t *locals;
547
547
  } pm_locals_t;
548
548
 
549
+ /** The flags about scope parameters that can be set. */
550
+ typedef uint8_t pm_scope_parameters_t;
551
+ static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_NONE = 0x0;
552
+ static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_FORWARDING_POSITIONALS = 0x1;
553
+ static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_FORWARDING_KEYWORDS = 0x2;
554
+ static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_FORWARDING_BLOCK = 0x4;
555
+ static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_FORWARDING_ALL = 0x8;
556
+ static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_IMPLICIT_DISALLOWED = 0x10;
557
+ static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_NUMBERED_INNER = 0x20;
558
+ static const pm_scope_parameters_t PM_SCOPE_PARAMETERS_NUMBERED_FOUND = 0x40;
559
+
549
560
  /**
550
561
  * This struct represents a node in a linked list of scopes. Some scopes can see
551
562
  * into their parent scopes, while others cannot.
@@ -557,10 +568,19 @@ typedef struct pm_scope {
557
568
  /** The IDs of the locals in the given scope. */
558
569
  pm_locals_t locals;
559
570
 
571
+ /**
572
+ * This is a list of the implicit parameters contained within the block.
573
+ * These will be processed after the block is parsed to determine the kind
574
+ * of parameters node that should be used and to check if any errors need to
575
+ * be added.
576
+ */
577
+ pm_node_list_t implicit_parameters;
578
+
560
579
  /**
561
580
  * This is a bitfield that indicates the parameters that are being used in
562
- * this scope. It is a combination of the PM_SCOPE_PARAMS_* constants. There
563
- * are three different kinds of parameters that can be used in a scope:
581
+ * this scope. It is a combination of the PM_SCOPE_PARAMETERS_* constants.
582
+ * There are three different kinds of parameters that can be used in a
583
+ * scope:
564
584
  *
565
585
  * - Ordinary parameters (e.g., def foo(bar); end)
566
586
  * - Numbered parameters (e.g., def foo; _1; end)
@@ -575,15 +595,7 @@ typedef struct pm_scope {
575
595
  * - def foo(&); end
576
596
  * - def foo(...); end
577
597
  */
578
- uint8_t parameters;
579
-
580
- /**
581
- * An integer indicating the number of numbered parameters on this scope.
582
- * This is necessary to determine if child blocks are allowed to use
583
- * numbered parameters, and to pass information to consumers of the AST
584
- * about how many numbered parameters exist.
585
- */
586
- int8_t numbered_parameters;
598
+ pm_scope_parameters_t parameters;
587
599
 
588
600
  /**
589
601
  * The current state of constant shareability for this scope. This is
@@ -598,20 +610,6 @@ typedef struct pm_scope {
598
610
  bool closed;
599
611
  } pm_scope_t;
600
612
 
601
- static const uint8_t PM_SCOPE_PARAMETERS_NONE = 0x0;
602
- static const uint8_t PM_SCOPE_PARAMETERS_ORDINARY = 0x1;
603
- static const uint8_t PM_SCOPE_PARAMETERS_NUMBERED = 0x2;
604
- static const uint8_t PM_SCOPE_PARAMETERS_IT = 0x4;
605
- static const uint8_t PM_SCOPE_PARAMETERS_TYPE_MASK = 0x7;
606
-
607
- static const uint8_t PM_SCOPE_PARAMETERS_FORWARDING_POSITIONALS = 0x8;
608
- static const uint8_t PM_SCOPE_PARAMETERS_FORWARDING_KEYWORDS = 0x10;
609
- static const uint8_t PM_SCOPE_PARAMETERS_FORWARDING_BLOCK = 0x20;
610
- static const uint8_t PM_SCOPE_PARAMETERS_FORWARDING_ALL = 0x40;
611
-
612
- static const int8_t PM_SCOPE_NUMBERED_PARAMETERS_DISALLOWED = -1;
613
- static const int8_t PM_SCOPE_NUMBERED_PARAMETERS_NONE = 0;
614
-
615
613
  /**
616
614
  * A struct that represents a stack of boolean values.
617
615
  */
@@ -10,7 +10,6 @@
10
10
  #include "prism/parser.h"
11
11
  #include "prism/encoding.h"
12
12
  #include "prism/util/pm_memchr.h"
13
- #include "prism/util/pm_string_list.h"
14
13
  #include "prism/util/pm_string.h"
15
14
 
16
15
  #include <stdbool.h>
@@ -18,16 +17,26 @@
18
17
  #include <string.h>
19
18
 
20
19
  /**
21
- * Parse a regular expression and extract the names of all of the named capture
22
- * groups.
20
+ * This callback is called when a named capture group is found.
21
+ */
22
+ typedef void (*pm_regexp_name_callback_t)(const pm_string_t *name, void *data);
23
+
24
+ /**
25
+ * This callback is called when a parse error is found.
26
+ */
27
+ typedef void (*pm_regexp_error_callback_t)(const uint8_t *start, const uint8_t *end, const char *message, void *data);
28
+
29
+ /**
30
+ * Parse a regular expression.
23
31
  *
32
+ * @param parser The parser that is currently being used.
24
33
  * @param source The source code to parse.
25
34
  * @param size The size of the source code.
26
- * @param named_captures The list to add the names of the named capture groups.
27
- * @param encoding_changed Whether or not the encoding changed from the default.
28
- * @param encoding The encoding of the source code.
29
- * @return Whether or not the parsing was successful.
35
+ * @param name_callback The optional callback to call when a named capture group is found.
36
+ * @param name_data The optional data to pass to the name callback.
37
+ * @param error_callback The callback to call when a parse error is found.
38
+ * @param error_data The data to pass to the error callback.
30
39
  */
31
- PRISM_EXPORTED_FUNCTION bool pm_regexp_named_capture_group_names(const uint8_t *source, size_t size, pm_string_list_t *named_captures, bool encoding_changed, const pm_encoding_t *encoding);
40
+ PRISM_EXPORTED_FUNCTION void pm_regexp_parse(pm_parser_t *parser, const uint8_t *source, size_t size, pm_regexp_name_callback_t name_callback, void *name_data, pm_regexp_error_callback_t error_callback, void *error_data);
32
41
 
33
42
  #endif
@@ -95,9 +95,10 @@ typedef struct {
95
95
  * @param start_line The line number that the parser starts on.
96
96
  * @param literals The set of static literals to add the node to.
97
97
  * @param node The node to add to the set.
98
+ * @param replace Whether to replace the previous node if one already exists.
98
99
  * @return A pointer to the node that is being overwritten, if there is one.
99
100
  */
100
- pm_node_t * pm_static_literals_add(const pm_newline_list_t *newline_list, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node);
101
+ pm_node_t * pm_static_literals_add(const pm_newline_list_t *newline_list, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace);
101
102
 
102
103
  /**
103
104
  * Free the internal memory associated with the given static literals set.
@@ -115,6 +116,6 @@ void pm_static_literals_free(pm_static_literals_t *literals);
115
116
  * @param encoding_name The name of the encoding of the source being parsed.
116
117
  * @param node The node to create a string representation of.
117
118
  */
118
- PRISM_EXPORTED_FUNCTION void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, int32_t start_line, const char *encoding_name, const pm_node_t *node);
119
+ void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, int32_t start_line, const char *encoding_name, const pm_node_t *node);
119
120
 
120
121
  #endif
@@ -34,8 +34,7 @@ size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length);
34
34
  * @return The number of characters at the start of the string that are
35
35
  * whitespace.
36
36
  */
37
- size_t
38
- pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list);
37
+ size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list);
39
38
 
40
39
  /**
41
40
  * Returns the number of characters at the start of the string that are inline
@@ -87,14 +87,6 @@ void pm_constant_id_list_insert(pm_constant_id_list_t *list, size_t index, pm_co
87
87
  */
88
88
  bool pm_constant_id_list_includes(pm_constant_id_list_t *list, pm_constant_id_t id);
89
89
 
90
- /**
91
- * Get the memory size of a list of constant ids.
92
- *
93
- * @param list The list to get the memory size of.
94
- * @return The memory size of the list.
95
- */
96
- size_t pm_constant_id_list_memsize(pm_constant_id_list_t *list);
97
-
98
90
  /**
99
91
  * Free the memory associated with a list of constant ids.
100
92
  *