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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prism
4
- class ParseResult
4
+ class ParseResult < Result
5
5
  # The :line tracepoint event gets fired whenever the Ruby VM encounters an
6
6
  # expression on a new line. The types of expressions that can trigger this
7
7
  # event are:
@@ -17,21 +17,27 @@ module Prism
17
17
  # Note that the logic in this file should be kept in sync with the Java
18
18
  # MarkNewlinesVisitor, since that visitor is responsible for marking the
19
19
  # newlines for JRuby/TruffleRuby.
20
+ #
21
+ # This file is autoloaded only when `mark_newlines!` is called, so the
22
+ # re-opening of the various nodes in this file will only be performed in
23
+ # that case. We do that to avoid storing the extra `@newline` instance
24
+ # variable on every node if we don't need it.
20
25
  class Newlines < Visitor
21
26
  # Create a new Newlines visitor with the given newline offsets.
22
- def initialize(newline_marked)
23
- @newline_marked = newline_marked
27
+ def initialize(lines)
28
+ # @type var lines: Integer
29
+ @lines = Array.new(1 + lines, false)
24
30
  end
25
31
 
26
32
  # Permit block/lambda nodes to mark newlines within themselves.
27
33
  def visit_block_node(node)
28
- old_newline_marked = @newline_marked
29
- @newline_marked = Array.new(old_newline_marked.size, false)
34
+ old_lines = @lines
35
+ @lines = Array.new(old_lines.size, false)
30
36
 
31
37
  begin
32
38
  super(node)
33
39
  ensure
34
- @newline_marked = old_newline_marked
40
+ @lines = old_lines
35
41
  end
36
42
  end
37
43
 
@@ -39,7 +45,7 @@ module Prism
39
45
 
40
46
  # Mark if/unless nodes as newlines.
41
47
  def visit_if_node(node)
42
- node.set_newline_flag(@newline_marked)
48
+ node.newline_flag!(@lines)
43
49
  super(node)
44
50
  end
45
51
 
@@ -48,17 +54,101 @@ module Prism
48
54
  # Permit statements lists to mark newlines within themselves.
49
55
  def visit_statements_node(node)
50
56
  node.body.each do |child|
51
- child.set_newline_flag(@newline_marked)
57
+ child.newline_flag!(@lines)
52
58
  end
53
59
  super(node)
54
60
  end
55
61
  end
62
+ end
63
+
64
+ class Node
65
+ def newline_flag? # :nodoc:
66
+ !!defined?(@newline_flag)
67
+ end
68
+
69
+ def newline_flag!(lines) # :nodoc:
70
+ line = location.start_line
71
+ unless lines[line]
72
+ lines[line] = true
73
+ @newline_flag = true
74
+ end
75
+ end
76
+ end
77
+
78
+ class BeginNode < Node
79
+ def newline_flag!(lines) # :nodoc:
80
+ # Never mark BeginNode with a newline flag, mark children instead.
81
+ end
82
+ end
83
+
84
+ class ParenthesesNode < Node
85
+ def newline_flag!(lines) # :nodoc:
86
+ # Never mark ParenthesesNode with a newline flag, mark children instead.
87
+ end
88
+ end
89
+
90
+ class IfNode < Node
91
+ def newline_flag!(lines) # :nodoc:
92
+ predicate.newline_flag!(lines)
93
+ end
94
+ end
95
+
96
+ class UnlessNode < Node
97
+ def newline_flag!(lines) # :nodoc:
98
+ predicate.newline_flag!(lines)
99
+ end
100
+ end
101
+
102
+ class UntilNode < Node
103
+ def newline_flag!(lines) # :nodoc:
104
+ predicate.newline_flag!(lines)
105
+ end
106
+ end
107
+
108
+ class WhileNode < Node
109
+ def newline_flag!(lines) # :nodoc:
110
+ predicate.newline_flag!(lines)
111
+ end
112
+ end
113
+
114
+ class RescueModifierNode < Node
115
+ def newline_flag!(lines) # :nodoc:
116
+ expression.newline_flag!(lines)
117
+ end
118
+ end
119
+
120
+ class InterpolatedMatchLastLineNode < Node
121
+ def newline_flag!(lines) # :nodoc:
122
+ first = parts.first
123
+ first.newline_flag!(lines) if first
124
+ end
125
+ end
126
+
127
+ class InterpolatedRegularExpressionNode < Node
128
+ def newline_flag!(lines) # :nodoc:
129
+ first = parts.first
130
+ first.newline_flag!(lines) if first
131
+ end
132
+ end
133
+
134
+ class InterpolatedStringNode < Node
135
+ def newline_flag!(lines) # :nodoc:
136
+ first = parts.first
137
+ first.newline_flag!(lines) if first
138
+ end
139
+ end
56
140
 
57
- private_constant :Newlines
141
+ class InterpolatedSymbolNode < Node
142
+ def newline_flag!(lines) # :nodoc:
143
+ first = parts.first
144
+ first.newline_flag!(lines) if first
145
+ end
146
+ end
58
147
 
59
- # Walk the tree and mark nodes that are on a new line.
60
- def mark_newlines!
61
- value.accept(Newlines.new(Array.new(1 + source.offsets.size, false)))
148
+ class InterpolatedXStringNode < Node
149
+ def newline_flag!(lines) # :nodoc:
150
+ first = parts.first
151
+ first.newline_flag!(lines) if first
62
152
  end
63
153
  end
64
154
  end