prism 0.26.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -1
  3. data/Makefile +3 -2
  4. data/config.yml +305 -20
  5. data/docs/configuration.md +1 -0
  6. data/ext/prism/api_node.c +884 -879
  7. data/ext/prism/extconf.rb +23 -4
  8. data/ext/prism/extension.c +16 -9
  9. data/ext/prism/extension.h +1 -1
  10. data/include/prism/ast.h +298 -9
  11. data/include/prism/diagnostic.h +15 -5
  12. data/include/prism/options.h +2 -2
  13. data/include/prism/parser.h +10 -0
  14. data/include/prism/static_literals.h +8 -6
  15. data/include/prism/version.h +2 -2
  16. data/lib/prism/dot_visitor.rb +22 -6
  17. data/lib/prism/dsl.rb +8 -8
  18. data/lib/prism/ffi.rb +4 -4
  19. data/lib/prism/inspect_visitor.rb +2156 -0
  20. data/lib/prism/lex_compat.rb +18 -1
  21. data/lib/prism/mutation_compiler.rb +2 -2
  22. data/lib/prism/node.rb +2345 -1964
  23. data/lib/prism/node_ext.rb +34 -5
  24. data/lib/prism/parse_result/newlines.rb +0 -2
  25. data/lib/prism/parse_result.rb +137 -13
  26. data/lib/prism/pattern.rb +12 -6
  27. data/lib/prism/polyfill/byteindex.rb +13 -0
  28. data/lib/prism/polyfill/unpack1.rb +14 -0
  29. data/lib/prism/reflection.rb +21 -31
  30. data/lib/prism/serialize.rb +27 -17
  31. data/lib/prism/translation/parser/compiler.rb +34 -15
  32. data/lib/prism/translation/parser.rb +6 -6
  33. data/lib/prism/translation/ripper.rb +72 -68
  34. data/lib/prism/translation/ruby_parser.rb +69 -31
  35. data/lib/prism.rb +3 -2
  36. data/prism.gemspec +36 -38
  37. data/rbi/prism/compiler.rbi +3 -5
  38. data/rbi/prism/inspect_visitor.rbi +12 -0
  39. data/rbi/prism/node.rbi +359 -321
  40. data/rbi/prism/parse_result.rbi +85 -34
  41. data/rbi/prism/reflection.rbi +7 -13
  42. data/rbi/prism/translation/ripper.rbi +1 -11
  43. data/rbi/prism.rbi +9 -9
  44. data/sig/prism/dsl.rbs +3 -3
  45. data/sig/prism/inspect_visitor.rbs +22 -0
  46. data/sig/prism/node.rbs +68 -48
  47. data/sig/prism/parse_result.rbs +42 -10
  48. data/sig/prism/reflection.rbs +2 -8
  49. data/sig/prism/serialize.rbs +2 -3
  50. data/sig/prism.rbs +9 -9
  51. data/src/diagnostic.c +44 -24
  52. data/src/node.c +41 -16
  53. data/src/options.c +2 -2
  54. data/src/prettyprint.c +61 -18
  55. data/src/prism.c +623 -188
  56. data/src/serialize.c +5 -2
  57. data/src/static_literals.c +120 -34
  58. data/src/token_type.c +4 -4
  59. data/src/util/pm_integer.c +9 -2
  60. metadata +7 -9
  61. data/lib/prism/node_inspector.rb +0 -68
  62. data/lib/prism/polyfill/string.rb +0 -12
  63. data/rbi/prism/desugar_compiler.rbi +0 -5
  64. data/rbi/prism/mutation_compiler.rbi +0 -5
  65. data/rbi/prism/translation/parser/compiler.rbi +0 -13
  66. data/rbi/prism/translation/ripper/ripper_compiler.rbi +0 -5
  67. data/rbi/prism/translation/ruby_parser.rbi +0 -11
@@ -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.
@@ -844,7 +861,7 @@ module Prism
844
861
  # We sort by location to compare against Ripper's output
845
862
  tokens.sort_by!(&:location)
846
863
 
847
- ParseResult.new(tokens, result.comments, result.magic_comments, result.data_loc, result.errors, result.warnings, Source.new(source))
864
+ Result.new(tokens, result.comments, result.magic_comments, result.data_loc, result.errors, result.warnings, Source.for(source))
848
865
  end
849
866
  end
850
867
 
@@ -193,7 +193,7 @@ module Prism
193
193
 
194
194
  # Copy a ConstantPathNode node
195
195
  def visit_constant_path_node(node)
196
- node.copy(parent: visit(node.parent), child: visit(node.child))
196
+ node.copy(parent: visit(node.parent))
197
197
  end
198
198
 
199
199
  # Copy a ConstantPathOperatorWriteNode node
@@ -208,7 +208,7 @@ module Prism
208
208
 
209
209
  # Copy a ConstantPathTargetNode node
210
210
  def visit_constant_path_target_node(node)
211
- node.copy(parent: visit(node.parent), child: visit(node.child))
211
+ node.copy(parent: visit(node.parent))
212
212
  end
213
213
 
214
214
  # Copy a ConstantPathWriteNode node