jruby-prism-parser 0.24.0-java → 1.4.0-java

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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +269 -1
  4. data/CONTRIBUTING.md +0 -4
  5. data/Makefile +25 -18
  6. data/README.md +57 -6
  7. data/config.yml +1724 -140
  8. data/docs/build_system.md +39 -11
  9. data/docs/configuration.md +4 -0
  10. data/docs/cruby_compilation.md +1 -1
  11. data/docs/fuzzing.md +1 -1
  12. data/docs/parser_translation.md +14 -9
  13. data/docs/parsing_rules.md +4 -1
  14. data/docs/releasing.md +8 -10
  15. data/docs/relocation.md +34 -0
  16. data/docs/ripper_translation.md +72 -0
  17. data/docs/ruby_api.md +2 -1
  18. data/docs/serialization.md +29 -5
  19. data/ext/prism/api_node.c +3395 -1999
  20. data/ext/prism/api_pack.c +9 -0
  21. data/ext/prism/extconf.rb +55 -34
  22. data/ext/prism/extension.c +597 -346
  23. data/ext/prism/extension.h +6 -5
  24. data/include/prism/ast.h +2612 -455
  25. data/include/prism/defines.h +160 -2
  26. data/include/prism/diagnostic.h +188 -76
  27. data/include/prism/encoding.h +22 -4
  28. data/include/prism/node.h +89 -17
  29. data/include/prism/options.h +224 -12
  30. data/include/prism/pack.h +11 -0
  31. data/include/prism/parser.h +267 -66
  32. data/include/prism/prettyprint.h +8 -0
  33. data/include/prism/regexp.h +18 -8
  34. data/include/prism/static_literals.h +121 -0
  35. data/include/prism/util/pm_buffer.h +75 -2
  36. data/include/prism/util/pm_char.h +1 -2
  37. data/include/prism/util/pm_constant_pool.h +18 -9
  38. data/include/prism/util/pm_integer.h +126 -0
  39. data/include/prism/util/pm_list.h +1 -1
  40. data/include/prism/util/pm_newline_list.h +19 -0
  41. data/include/prism/util/pm_string.h +48 -8
  42. data/include/prism/version.h +3 -3
  43. data/include/prism.h +99 -5
  44. data/jruby-prism.jar +0 -0
  45. data/lib/prism/compiler.rb +11 -1
  46. data/lib/prism/desugar_compiler.rb +113 -74
  47. data/lib/prism/dispatcher.rb +45 -1
  48. data/lib/prism/dot_visitor.rb +201 -77
  49. data/lib/prism/dsl.rb +673 -461
  50. data/lib/prism/ffi.rb +233 -45
  51. data/lib/prism/inspect_visitor.rb +2389 -0
  52. data/lib/prism/lex_compat.rb +35 -16
  53. data/lib/prism/mutation_compiler.rb +24 -8
  54. data/lib/prism/node.rb +7731 -8460
  55. data/lib/prism/node_ext.rb +328 -32
  56. data/lib/prism/pack.rb +4 -0
  57. data/lib/prism/parse_result/comments.rb +34 -24
  58. data/lib/prism/parse_result/errors.rb +65 -0
  59. data/lib/prism/parse_result/newlines.rb +102 -12
  60. data/lib/prism/parse_result.rb +448 -44
  61. data/lib/prism/pattern.rb +28 -10
  62. data/lib/prism/polyfill/append_as_bytes.rb +15 -0
  63. data/lib/prism/polyfill/byteindex.rb +13 -0
  64. data/lib/prism/polyfill/unpack1.rb +14 -0
  65. data/lib/prism/reflection.rb +413 -0
  66. data/lib/prism/relocation.rb +504 -0
  67. data/lib/prism/serialize.rb +1940 -1198
  68. data/lib/prism/string_query.rb +30 -0
  69. data/lib/prism/translation/parser/builder.rb +61 -0
  70. data/lib/prism/translation/parser/compiler.rb +569 -195
  71. data/lib/prism/translation/parser/lexer.rb +516 -39
  72. data/lib/prism/translation/parser.rb +177 -12
  73. data/lib/prism/translation/parser33.rb +1 -1
  74. data/lib/prism/translation/parser34.rb +1 -1
  75. data/lib/prism/translation/parser35.rb +12 -0
  76. data/lib/prism/translation/ripper/sexp.rb +125 -0
  77. data/lib/prism/translation/ripper/shim.rb +5 -0
  78. data/lib/prism/translation/ripper.rb +3224 -462
  79. data/lib/prism/translation/ruby_parser.rb +194 -69
  80. data/lib/prism/translation.rb +4 -1
  81. data/lib/prism/version.rb +1 -1
  82. data/lib/prism/visitor.rb +13 -0
  83. data/lib/prism.rb +17 -27
  84. data/prism.gemspec +57 -17
  85. data/rbi/prism/compiler.rbi +12 -0
  86. data/rbi/prism/dsl.rbi +524 -0
  87. data/rbi/prism/inspect_visitor.rbi +12 -0
  88. data/rbi/prism/node.rbi +8722 -0
  89. data/rbi/prism/node_ext.rbi +107 -0
  90. data/rbi/prism/parse_result.rbi +404 -0
  91. data/rbi/prism/reflection.rbi +58 -0
  92. data/rbi/prism/string_query.rbi +12 -0
  93. data/rbi/prism/translation/parser.rbi +11 -0
  94. data/rbi/prism/translation/parser33.rbi +6 -0
  95. data/rbi/prism/translation/parser34.rbi +6 -0
  96. data/rbi/prism/translation/parser35.rbi +6 -0
  97. data/rbi/prism/translation/ripper.rbi +15 -0
  98. data/rbi/prism/visitor.rbi +473 -0
  99. data/rbi/prism.rbi +44 -7745
  100. data/sig/prism/compiler.rbs +9 -0
  101. data/sig/prism/dispatcher.rbs +16 -0
  102. data/sig/prism/dot_visitor.rbs +6 -0
  103. data/sig/prism/dsl.rbs +351 -0
  104. data/sig/prism/inspect_visitor.rbs +22 -0
  105. data/sig/prism/lex_compat.rbs +10 -0
  106. data/sig/prism/mutation_compiler.rbs +159 -0
  107. data/sig/prism/node.rbs +3614 -0
  108. data/sig/prism/node_ext.rbs +82 -0
  109. data/sig/prism/pack.rbs +43 -0
  110. data/sig/prism/parse_result.rbs +192 -0
  111. data/sig/prism/pattern.rbs +13 -0
  112. data/sig/prism/reflection.rbs +50 -0
  113. data/sig/prism/relocation.rbs +185 -0
  114. data/sig/prism/serialize.rbs +8 -0
  115. data/sig/prism/string_query.rbs +11 -0
  116. data/sig/prism/visitor.rbs +169 -0
  117. data/sig/prism.rbs +248 -4767
  118. data/src/diagnostic.c +672 -230
  119. data/src/encoding.c +211 -108
  120. data/src/node.c +7541 -1653
  121. data/src/options.c +135 -20
  122. data/src/pack.c +33 -17
  123. data/src/prettyprint.c +1543 -1485
  124. data/src/prism.c +7813 -3050
  125. data/src/regexp.c +225 -73
  126. data/src/serialize.c +101 -77
  127. data/src/static_literals.c +617 -0
  128. data/src/token_type.c +14 -13
  129. data/src/util/pm_buffer.c +187 -20
  130. data/src/util/pm_char.c +5 -5
  131. data/src/util/pm_constant_pool.c +39 -19
  132. data/src/util/pm_integer.c +670 -0
  133. data/src/util/pm_list.c +1 -1
  134. data/src/util/pm_newline_list.c +43 -5
  135. data/src/util/pm_string.c +213 -33
  136. data/src/util/pm_strncasecmp.c +13 -1
  137. data/src/util/pm_strpbrk.c +32 -6
  138. metadata +55 -19
  139. data/docs/ripper.md +0 -36
  140. data/include/prism/util/pm_state_stack.h +0 -42
  141. data/include/prism/util/pm_string_list.h +0 -44
  142. data/lib/prism/debug.rb +0 -206
  143. data/lib/prism/node_inspector.rb +0 -68
  144. data/lib/prism/translation/parser/rubocop.rb +0 -45
  145. data/rbi/prism_static.rbi +0 -207
  146. data/sig/prism_static.rbs +0 -201
  147. data/src/util/pm_state_stack.c +0 -25
  148. data/src/util/pm_string_list.c +0 -28
@@ -10,6 +10,23 @@ module Prism
10
10
  # generally lines up. However, there are a few cases that require special
11
11
  # handling.
12
12
  class LexCompat # :nodoc:
13
+ # A result class specialized for holding tokens produced by the lexer.
14
+ class Result < Prism::Result
15
+ # The list of tokens that were produced by the lexer.
16
+ attr_reader :value
17
+
18
+ # Create a new lex compat result object with the given values.
19
+ def initialize(value, comments, magic_comments, data_loc, errors, warnings, source)
20
+ @value = value
21
+ super(comments, magic_comments, data_loc, errors, warnings, source)
22
+ end
23
+
24
+ # Implement the hash pattern matching interface for Result.
25
+ def deconstruct_keys(keys)
26
+ super.merge!(value: value)
27
+ end
28
+ end
29
+
13
30
  # This is a mapping of prism token types to Ripper token types. This is a
14
31
  # many-to-one mapping because we split up our token types, whereas Ripper
15
32
  # tends to group them.
@@ -185,6 +202,8 @@ module Prism
185
202
  # However, we add a couple of convenience methods onto them to make them a
186
203
  # little easier to work with. We delegate all other methods to the array.
187
204
  class Token < SimpleDelegator
205
+ # @dynamic initialize, each, []
206
+
188
207
  # The location of the token in the source.
189
208
  def location
190
209
  self[0]
@@ -241,10 +260,10 @@ module Prism
241
260
  def ==(other) # :nodoc:
242
261
  return false unless self[0...-1] == other[0...-1]
243
262
 
244
- if self[4] == Ripper::EXPR_ARG | Ripper::EXPR_LABELED
245
- other[4] & Ripper::EXPR_ARG | Ripper::EXPR_LABELED > 0
263
+ if self[3] == Ripper::EXPR_ARG | Ripper::EXPR_LABELED
264
+ other[3] & Ripper::EXPR_ARG | Ripper::EXPR_LABELED != 0
246
265
  else
247
- self[4] == other[4]
266
+ self[3] == other[3]
248
267
  end
249
268
  end
250
269
  end
@@ -308,7 +327,7 @@ module Prism
308
327
  def to_a
309
328
  embexpr_balance = 0
310
329
 
311
- tokens.each_with_object([]) do |token, results|
330
+ tokens.each_with_object([]) do |token, results| #$ Array[Token]
312
331
  case token.event
313
332
  when :on_embexpr_beg
314
333
  embexpr_balance += 1
@@ -409,7 +428,7 @@ module Prism
409
428
  # If every line in the heredoc is blank, we still need to split up the
410
429
  # string content token into multiple tokens.
411
430
  if dedent.nil?
412
- results = []
431
+ results = [] #: Array[Token]
413
432
  embexpr_balance = 0
414
433
 
415
434
  tokens.each do |token|
@@ -444,7 +463,7 @@ module Prism
444
463
  # If the minimum common whitespace is 0, then we need to concatenate
445
464
  # string nodes together that are immediately adjacent.
446
465
  if dedent == 0
447
- results = []
466
+ results = [] #: Array[Token]
448
467
  embexpr_balance = 0
449
468
 
450
469
  index = 0
@@ -462,7 +481,7 @@ module Prism
462
481
  embexpr_balance -= 1
463
482
  when :on_tstring_content
464
483
  if embexpr_balance == 0
465
- while index < max_index && tokens[index].event == :on_tstring_content
484
+ while index < max_index && tokens[index].event == :on_tstring_content && !token.value.match?(/\\\r?\n\z/)
466
485
  token.value << tokens[index].value
467
486
  index += 1
468
487
  end
@@ -477,7 +496,7 @@ module Prism
477
496
  # insert on_ignored_sp tokens for the amount of dedent that we need to
478
497
  # perform. We also need to remove the dedent from the beginning of
479
498
  # each line of plain string content tokens.
480
- results = []
499
+ results = [] #: Array[Token]
481
500
  dedent_next = true
482
501
  embexpr_balance = 0
483
502
 
@@ -526,7 +545,7 @@ module Prism
526
545
  # dedent from the beginning of the line.
527
546
  if (dedent > 0) && (dedent_next || index > 0)
528
547
  deleting = 0
529
- deleted_chars = []
548
+ deleted_chars = [] #: Array[String]
530
549
 
531
550
  # Gather up all of the characters that we're going to
532
551
  # delete, stopping when you hit a character that would put
@@ -603,15 +622,15 @@ module Prism
603
622
  end
604
623
 
605
624
  def result
606
- tokens = []
625
+ tokens = [] #: Array[LexCompat::Token]
607
626
 
608
627
  state = :default
609
- heredoc_stack = [[]]
628
+ heredoc_stack = [[]] #: Array[Array[Heredoc::PlainHeredoc | Heredoc::DashHeredoc | Heredoc::DedentingHeredoc]]
610
629
 
611
630
  result = Prism.lex(source, **options)
612
631
  result_value = result.value
613
- previous_state = nil
614
- last_heredoc_end = nil
632
+ previous_state = nil #: Ripper::Lexer::State?
633
+ last_heredoc_end = nil #: Integer?
615
634
 
616
635
  # In previous versions of Ruby, Ripper wouldn't flush the bom before the
617
636
  # first token, so we had to have a hack in place to account for that. This
@@ -842,7 +861,7 @@ module Prism
842
861
  # We sort by location to compare against Ripper's output
843
862
  tokens.sort_by!(&:location)
844
863
 
845
- ParseResult.new(tokens, result.comments, result.magic_comments, result.data_loc, result.errors, result.warnings, [])
864
+ Result.new(tokens, result.comments, result.magic_comments, result.data_loc, result.errors, result.warnings, Source.for(source))
846
865
  end
847
866
  end
848
867
 
@@ -858,8 +877,8 @@ module Prism
858
877
  end
859
878
 
860
879
  def result
861
- previous = []
862
- results = []
880
+ previous = [] #: [[Integer, Integer], Symbol, String, untyped] | []
881
+ results = [] #: Array[[[Integer, Integer], Symbol, String, untyped]]
863
882
 
864
883
  lex(source).each do |token|
865
884
  case token[1]
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  =begin
3
4
  This file is generated by the templates/template.rb script and should not be
4
5
  modified manually. See templates/lib/prism/mutation_compiler.rb.erb
@@ -127,12 +128,12 @@ module Prism
127
128
 
128
129
  # Copy a CaseMatchNode node
129
130
  def visit_case_match_node(node)
130
- node.copy(predicate: visit(node.predicate), conditions: visit_all(node.conditions), consequent: visit(node.consequent))
131
+ node.copy(predicate: visit(node.predicate), conditions: visit_all(node.conditions), else_clause: visit(node.else_clause))
131
132
  end
132
133
 
133
134
  # Copy a CaseNode node
134
135
  def visit_case_node(node)
135
- node.copy(predicate: visit(node.predicate), conditions: visit_all(node.conditions), consequent: visit(node.consequent))
136
+ node.copy(predicate: visit(node.predicate), conditions: visit_all(node.conditions), else_clause: visit(node.else_clause))
136
137
  end
137
138
 
138
139
  # Copy a ClassNode node
@@ -192,7 +193,7 @@ module Prism
192
193
 
193
194
  # Copy a ConstantPathNode node
194
195
  def visit_constant_path_node(node)
195
- node.copy(parent: visit(node.parent), child: visit(node.child))
196
+ node.copy(parent: visit(node.parent))
196
197
  end
197
198
 
198
199
  # Copy a ConstantPathOperatorWriteNode node
@@ -207,7 +208,7 @@ module Prism
207
208
 
208
209
  # Copy a ConstantPathTargetNode node
209
210
  def visit_constant_path_target_node(node)
210
- node.copy(parent: visit(node.parent), child: visit(node.child))
211
+ node.copy(parent: visit(node.parent))
211
212
  end
212
213
 
213
214
  # Copy a ConstantPathWriteNode node
@@ -342,7 +343,7 @@ module Prism
342
343
 
343
344
  # Copy a IfNode node
344
345
  def visit_if_node(node)
345
- node.copy(predicate: visit(node.predicate), statements: visit(node.statements), consequent: visit(node.consequent))
346
+ node.copy(predicate: visit(node.predicate), statements: visit(node.statements), subsequent: visit(node.subsequent))
346
347
  end
347
348
 
348
349
  # Copy a ImaginaryNode node
@@ -445,6 +446,16 @@ module Prism
445
446
  node.copy(parts: visit_all(node.parts))
446
447
  end
447
448
 
449
+ # Copy a ItLocalVariableReadNode node
450
+ def visit_it_local_variable_read_node(node)
451
+ node.copy
452
+ end
453
+
454
+ # Copy a ItParametersNode node
455
+ def visit_it_parameters_node(node)
456
+ node.copy
457
+ end
458
+
448
459
  # Copy a KeywordHashNode node
449
460
  def visit_keyword_hash_node(node)
450
461
  node.copy(elements: visit_all(node.elements))
@@ -612,7 +623,7 @@ module Prism
612
623
 
613
624
  # Copy a RationalNode node
614
625
  def visit_rational_node(node)
615
- node.copy(numeric: visit(node.numeric))
626
+ node.copy
616
627
  end
617
628
 
618
629
  # Copy a RedoNode node
@@ -642,7 +653,7 @@ module Prism
642
653
 
643
654
  # Copy a RescueNode node
644
655
  def visit_rescue_node(node)
645
- node.copy(exceptions: visit_all(node.exceptions), reference: visit(node.reference), statements: visit(node.statements), consequent: visit(node.consequent))
656
+ node.copy(exceptions: visit_all(node.exceptions), reference: visit(node.reference), statements: visit(node.statements), subsequent: visit(node.subsequent))
646
657
  end
647
658
 
648
659
  # Copy a RestParameterNode node
@@ -665,6 +676,11 @@ module Prism
665
676
  node.copy
666
677
  end
667
678
 
679
+ # Copy a ShareableConstantNode node
680
+ def visit_shareable_constant_node(node)
681
+ node.copy(write: visit(node.write))
682
+ end
683
+
668
684
  # Copy a SingletonClassNode node
669
685
  def visit_singleton_class_node(node)
670
686
  node.copy(expression: visit(node.expression), body: visit(node.body))
@@ -722,7 +738,7 @@ module Prism
722
738
 
723
739
  # Copy a UnlessNode node
724
740
  def visit_unless_node(node)
725
- node.copy(predicate: visit(node.predicate), statements: visit(node.statements), consequent: visit(node.consequent))
741
+ node.copy(predicate: visit(node.predicate), statements: visit(node.statements), else_clause: visit(node.else_clause))
726
742
  end
727
743
 
728
744
  # Copy a UntilNode node