prism 0.29.0 → 1.1.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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +77 -1
  3. data/CONTRIBUTING.md +0 -4
  4. data/README.md +4 -0
  5. data/config.yml +498 -145
  6. data/docs/fuzzing.md +1 -1
  7. data/docs/parsing_rules.md +4 -1
  8. data/docs/ripper_translation.md +22 -0
  9. data/docs/serialization.md +3 -0
  10. data/ext/prism/api_node.c +2858 -2082
  11. data/ext/prism/extconf.rb +1 -1
  12. data/ext/prism/extension.c +203 -421
  13. data/ext/prism/extension.h +2 -2
  14. data/include/prism/ast.h +1732 -453
  15. data/include/prism/defines.h +36 -0
  16. data/include/prism/diagnostic.h +23 -6
  17. data/include/prism/node.h +0 -21
  18. data/include/prism/options.h +94 -3
  19. data/include/prism/parser.h +57 -28
  20. data/include/prism/regexp.h +18 -8
  21. data/include/prism/static_literals.h +3 -2
  22. data/include/prism/util/pm_char.h +1 -2
  23. data/include/prism/util/pm_constant_pool.h +0 -8
  24. data/include/prism/util/pm_integer.h +22 -15
  25. data/include/prism/util/pm_newline_list.h +11 -0
  26. data/include/prism/util/pm_string.h +28 -12
  27. data/include/prism/version.h +3 -3
  28. data/include/prism.h +0 -11
  29. data/lib/prism/compiler.rb +3 -0
  30. data/lib/prism/desugar_compiler.rb +111 -74
  31. data/lib/prism/dispatcher.rb +16 -1
  32. data/lib/prism/dot_visitor.rb +45 -34
  33. data/lib/prism/dsl.rb +660 -468
  34. data/lib/prism/ffi.rb +64 -6
  35. data/lib/prism/inspect_visitor.rb +294 -64
  36. data/lib/prism/lex_compat.rb +1 -1
  37. data/lib/prism/mutation_compiler.rb +11 -6
  38. data/lib/prism/node.rb +2469 -4973
  39. data/lib/prism/node_ext.rb +91 -14
  40. data/lib/prism/parse_result/comments.rb +0 -7
  41. data/lib/prism/parse_result/errors.rb +65 -0
  42. data/lib/prism/parse_result/newlines.rb +101 -11
  43. data/lib/prism/parse_result.rb +43 -3
  44. data/lib/prism/reflection.rb +10 -8
  45. data/lib/prism/serialize.rb +484 -609
  46. data/lib/prism/translation/parser/compiler.rb +152 -132
  47. data/lib/prism/translation/parser/lexer.rb +26 -4
  48. data/lib/prism/translation/parser.rb +9 -4
  49. data/lib/prism/translation/ripper.rb +22 -20
  50. data/lib/prism/translation/ruby_parser.rb +73 -13
  51. data/lib/prism/visitor.rb +3 -0
  52. data/lib/prism.rb +0 -4
  53. data/prism.gemspec +3 -5
  54. data/rbi/prism/dsl.rbi +521 -0
  55. data/rbi/prism/node.rbi +744 -4837
  56. data/rbi/prism/visitor.rbi +3 -0
  57. data/rbi/prism.rbi +36 -30
  58. data/sig/prism/dsl.rbs +190 -303
  59. data/sig/prism/mutation_compiler.rbs +1 -0
  60. data/sig/prism/node.rbs +759 -628
  61. data/sig/prism/parse_result.rbs +2 -0
  62. data/sig/prism/visitor.rbs +1 -0
  63. data/sig/prism.rbs +103 -64
  64. data/src/diagnostic.c +62 -28
  65. data/src/node.c +499 -1754
  66. data/src/options.c +76 -27
  67. data/src/prettyprint.c +156 -112
  68. data/src/prism.c +2773 -2081
  69. data/src/regexp.c +202 -69
  70. data/src/serialize.c +170 -50
  71. data/src/static_literals.c +63 -84
  72. data/src/token_type.c +4 -4
  73. data/src/util/pm_constant_pool.c +0 -8
  74. data/src/util/pm_integer.c +53 -25
  75. data/src/util/pm_newline_list.c +29 -0
  76. data/src/util/pm_string.c +130 -80
  77. data/src/util/pm_strpbrk.c +32 -6
  78. metadata +4 -6
  79. data/include/prism/util/pm_string_list.h +0 -44
  80. data/lib/prism/debug.rb +0 -249
  81. data/lib/prism/translation/parser/rubocop.rb +0 -73
  82. data/src/util/pm_string_list.c +0 -28
@@ -909,10 +909,10 @@ module Prism
909
909
  table.field("conditions", "[]")
910
910
  end
911
911
 
912
- # consequent
913
- unless (consequent = node.consequent).nil?
914
- table.field("consequent", port: true)
915
- digraph.edge("#{id}:consequent -> #{node_id(consequent)};")
912
+ # else_clause
913
+ unless (else_clause = node.else_clause).nil?
914
+ table.field("else_clause", port: true)
915
+ digraph.edge("#{id}:else_clause -> #{node_id(else_clause)};")
916
916
  end
917
917
 
918
918
  # case_keyword_loc
@@ -954,10 +954,10 @@ module Prism
954
954
  table.field("conditions", "[]")
955
955
  end
956
956
 
957
- # consequent
958
- unless (consequent = node.consequent).nil?
959
- table.field("consequent", port: true)
960
- digraph.edge("#{id}:consequent -> #{node_id(consequent)};")
957
+ # else_clause
958
+ unless (else_clause = node.else_clause).nil?
959
+ table.field("else_clause", port: true)
960
+ digraph.edge("#{id}:else_clause -> #{node_id(else_clause)};")
961
961
  end
962
962
 
963
963
  # case_keyword_loc
@@ -2130,10 +2130,10 @@ module Prism
2130
2130
  digraph.edge("#{id}:statements -> #{node_id(statements)};")
2131
2131
  end
2132
2132
 
2133
- # consequent
2134
- unless (consequent = node.consequent).nil?
2135
- table.field("consequent", port: true)
2136
- digraph.edge("#{id}:consequent -> #{node_id(consequent)};")
2133
+ # subsequent
2134
+ unless (subsequent = node.subsequent).nil?
2135
+ table.field("subsequent", port: true)
2136
+ digraph.edge("#{id}:subsequent -> #{node_id(subsequent)};")
2137
2137
  end
2138
2138
 
2139
2139
  # end_keyword_loc
@@ -2780,6 +2780,20 @@ module Prism
2780
2780
  super
2781
2781
  end
2782
2782
 
2783
+ # Visit a ItLocalVariableReadNode node.
2784
+ def visit_it_local_variable_read_node(node)
2785
+ table = Table.new("ItLocalVariableReadNode")
2786
+ id = node_id(node)
2787
+
2788
+ digraph.nodes << <<~DOT
2789
+ #{id} [
2790
+ label=<#{table.to_dot.gsub(/\n/, "\n ")}>
2791
+ ];
2792
+ DOT
2793
+
2794
+ super
2795
+ end
2796
+
2783
2797
  # Visit a ItParametersNode node.
2784
2798
  def visit_it_parameters_node(node)
2785
2799
  table = Table.new("ItParametersNode")
@@ -3779,9 +3793,14 @@ module Prism
3779
3793
  table = Table.new("RationalNode")
3780
3794
  id = node_id(node)
3781
3795
 
3782
- # numeric
3783
- table.field("numeric", port: true)
3784
- digraph.edge("#{id}:numeric -> #{node_id(node.numeric)};")
3796
+ # flags
3797
+ table.field("flags", integer_base_flags_inspect(node))
3798
+
3799
+ # numerator
3800
+ table.field("numerator", node.numerator.inspect)
3801
+
3802
+ # denominator
3803
+ table.field("denominator", node.denominator.inspect)
3785
3804
 
3786
3805
  digraph.nodes << <<~DOT
3787
3806
  #{id} [
@@ -3941,10 +3960,10 @@ module Prism
3941
3960
  digraph.edge("#{id}:statements -> #{node_id(statements)};")
3942
3961
  end
3943
3962
 
3944
- # consequent
3945
- unless (consequent = node.consequent).nil?
3946
- table.field("consequent", port: true)
3947
- digraph.edge("#{id}:consequent -> #{node_id(consequent)};")
3963
+ # subsequent
3964
+ unless (subsequent = node.subsequent).nil?
3965
+ table.field("subsequent", port: true)
3966
+ digraph.edge("#{id}:subsequent -> #{node_id(subsequent)};")
3948
3967
  end
3949
3968
 
3950
3969
  digraph.nodes << <<~DOT
@@ -4003,9 +4022,6 @@ module Prism
4003
4022
  table = Table.new("ReturnNode")
4004
4023
  id = node_id(node)
4005
4024
 
4006
- # flags
4007
- table.field("flags", return_node_flags_inspect(node))
4008
-
4009
4025
  # keyword_loc
4010
4026
  table.field("keyword_loc", location_inspect(node.keyword_loc))
4011
4027
 
@@ -4367,10 +4383,10 @@ module Prism
4367
4383
  digraph.edge("#{id}:statements -> #{node_id(statements)};")
4368
4384
  end
4369
4385
 
4370
- # consequent
4371
- unless (consequent = node.consequent).nil?
4372
- table.field("consequent", port: true)
4373
- digraph.edge("#{id}:consequent -> #{node_id(consequent)};")
4386
+ # else_clause
4387
+ unless (else_clause = node.else_clause).nil?
4388
+ table.field("else_clause", port: true)
4389
+ digraph.edge("#{id}:else_clause -> #{node_id(else_clause)};")
4374
4390
  end
4375
4391
 
4376
4392
  # end_keyword_loc
@@ -4576,8 +4592,11 @@ module Prism
4576
4592
  # comma-separated list.
4577
4593
  def arguments_node_flags_inspect(node)
4578
4594
  flags = [] #: Array[String]
4595
+ flags << "contains_forwarding" if node.contains_forwarding?
4579
4596
  flags << "contains_keywords" if node.contains_keywords?
4580
4597
  flags << "contains_keyword_splat" if node.contains_keyword_splat?
4598
+ flags << "contains_splat" if node.contains_splat?
4599
+ flags << "contains_multiple_splats" if node.contains_multiple_splats?
4581
4600
  flags.join(", ")
4582
4601
  end
4583
4602
 
@@ -4679,14 +4698,6 @@ module Prism
4679
4698
  flags.join(", ")
4680
4699
  end
4681
4700
 
4682
- # Inspect a node that has return_node_flags flags to display the flags as a
4683
- # comma-separated list.
4684
- def return_node_flags_inspect(node)
4685
- flags = [] #: Array[String]
4686
- flags << "redundant" if node.redundant?
4687
- flags.join(", ")
4688
- end
4689
-
4690
4701
  # Inspect a node that has shareable_constant_node_flags flags to display the flags as a
4691
4702
  # comma-separated list.
4692
4703
  def shareable_constant_node_flags_inspect(node)