prism 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/README.md +2 -1
  4. data/config.yml +188 -55
  5. data/docs/building.md +9 -2
  6. data/docs/configuration.md +10 -9
  7. data/docs/encoding.md +24 -56
  8. data/docs/local_variable_depth.md +229 -0
  9. data/docs/ruby_api.md +2 -0
  10. data/docs/serialization.md +18 -13
  11. data/ext/prism/api_node.c +337 -195
  12. data/ext/prism/extconf.rb +13 -7
  13. data/ext/prism/extension.c +96 -32
  14. data/ext/prism/extension.h +1 -1
  15. data/include/prism/ast.h +340 -137
  16. data/include/prism/defines.h +17 -0
  17. data/include/prism/diagnostic.h +11 -5
  18. data/include/prism/encoding.h +248 -0
  19. data/include/prism/options.h +2 -2
  20. data/include/prism/parser.h +62 -42
  21. data/include/prism/regexp.h +2 -2
  22. data/include/prism/util/pm_buffer.h +9 -1
  23. data/include/prism/util/pm_memchr.h +2 -2
  24. data/include/prism/util/pm_strpbrk.h +3 -3
  25. data/include/prism/version.h +2 -2
  26. data/include/prism.h +13 -15
  27. data/lib/prism/compiler.rb +12 -0
  28. data/lib/prism/debug.rb +9 -4
  29. data/lib/prism/desugar_compiler.rb +3 -3
  30. data/lib/prism/dispatcher.rb +56 -0
  31. data/lib/prism/dot_visitor.rb +476 -198
  32. data/lib/prism/dsl.rb +66 -46
  33. data/lib/prism/ffi.rb +16 -3
  34. data/lib/prism/lex_compat.rb +19 -9
  35. data/lib/prism/mutation_compiler.rb +20 -0
  36. data/lib/prism/node.rb +1173 -450
  37. data/lib/prism/node_ext.rb +41 -16
  38. data/lib/prism/parse_result.rb +12 -15
  39. data/lib/prism/ripper_compat.rb +49 -34
  40. data/lib/prism/serialize.rb +242 -212
  41. data/lib/prism/visitor.rb +12 -0
  42. data/lib/prism.rb +20 -4
  43. data/prism.gemspec +4 -10
  44. data/rbi/prism.rbi +605 -230
  45. data/rbi/prism_static.rbi +3 -0
  46. data/sig/prism.rbs +379 -124
  47. data/sig/prism_static.rbs +1 -0
  48. data/src/diagnostic.c +228 -222
  49. data/src/encoding.c +5137 -0
  50. data/src/node.c +66 -0
  51. data/src/options.c +21 -2
  52. data/src/prettyprint.c +806 -406
  53. data/src/prism.c +1092 -700
  54. data/src/regexp.c +3 -3
  55. data/src/serialize.c +227 -157
  56. data/src/util/pm_buffer.c +10 -1
  57. data/src/util/pm_memchr.c +1 -1
  58. data/src/util/pm_strpbrk.c +4 -4
  59. metadata +5 -11
  60. data/include/prism/enc/pm_encoding.h +0 -227
  61. data/src/enc/pm_big5.c +0 -116
  62. data/src/enc/pm_cp51932.c +0 -57
  63. data/src/enc/pm_euc_jp.c +0 -69
  64. data/src/enc/pm_gbk.c +0 -65
  65. data/src/enc/pm_shift_jis.c +0 -57
  66. data/src/enc/pm_tables.c +0 -2073
  67. data/src/enc/pm_unicode.c +0 -2369
  68. data/src/enc/pm_windows_31j.c +0 -57
data/lib/prism/visitor.rb CHANGED
@@ -111,6 +111,9 @@ module Prism
111
111
  # Visit a CallOrWriteNode node
112
112
  alias visit_call_or_write_node visit_child_nodes
113
113
 
114
+ # Visit a CallTargetNode node
115
+ alias visit_call_target_node visit_child_nodes
116
+
114
117
  # Visit a CapturePatternNode node
115
118
  alias visit_capture_pattern_node visit_child_nodes
116
119
 
@@ -252,6 +255,9 @@ module Prism
252
255
  # Visit a ImplicitNode node
253
256
  alias visit_implicit_node visit_child_nodes
254
257
 
258
+ # Visit a ImplicitRestNode node
259
+ alias visit_implicit_rest_node visit_child_nodes
260
+
255
261
  # Visit a InNode node
256
262
  alias visit_in_node visit_child_nodes
257
263
 
@@ -264,6 +270,9 @@ module Prism
264
270
  # Visit a IndexOrWriteNode node
265
271
  alias visit_index_or_write_node visit_child_nodes
266
272
 
273
+ # Visit a IndexTargetNode node
274
+ alias visit_index_target_node visit_child_nodes
275
+
267
276
  # Visit a InstanceVariableAndWriteNode node
268
277
  alias visit_instance_variable_and_write_node visit_child_nodes
269
278
 
@@ -360,6 +369,9 @@ module Prism
360
369
  # Visit a NoKeywordsParameterNode node
361
370
  alias visit_no_keywords_parameter_node visit_child_nodes
362
371
 
372
+ # Visit a NumberedParametersNode node
373
+ alias visit_numbered_parameters_node visit_child_nodes
374
+
363
375
  # Visit a NumberedReferenceReadNode node
364
376
  alias visit_numbered_reference_read_node visit_child_nodes
365
377
 
data/lib/prism.rb CHANGED
@@ -36,11 +36,11 @@ module Prism
36
36
  private_constant :LexRipper
37
37
 
38
38
  # :call-seq:
39
- # Prism::lex_compat(source, **options) -> Array
39
+ # Prism::lex_compat(source, **options) -> ParseResult
40
40
  #
41
- # Returns an array of tokens that closely resembles that of the Ripper lexer.
42
- # The only difference is that since we don't keep track of lexer state in the
43
- # same way, it's going to always return the NONE state.
41
+ # Returns a parse result whose value is an array of tokens that closely
42
+ # resembles the return value of Ripper::lex. The main difference is that the
43
+ # `:on_sp` token is not emitted.
44
44
  #
45
45
  # For supported options, see Prism::parse.
46
46
  def self.lex_compat(source, **options)
@@ -64,6 +64,22 @@ module Prism
64
64
  def self.load(source, serialized)
65
65
  Serialize.load(source, serialized)
66
66
  end
67
+
68
+ # :call-seq:
69
+ # Prism::parse_failure?(source, **options) -> bool
70
+ #
71
+ # Returns true if the source parses with errors.
72
+ def self.parse_failure?(source, **options)
73
+ !parse_success?(source, **options)
74
+ end
75
+
76
+ # :call-seq:
77
+ # Prism::parse_file_failure?(filepath, **options) -> bool
78
+ #
79
+ # Returns true if the file at filepath parses with errors.
80
+ def self.parse_file_failure?(filepath, **options)
81
+ !parse_file_success?(filepath, **options)
82
+ end
67
83
  end
68
84
 
69
85
  require_relative "prism/node"
data/prism.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prism"
5
- spec.version = "0.18.0"
5
+ spec.version = "0.19.0"
6
6
  spec.authors = ["Shopify"]
7
7
  spec.email = ["ruby@shopify.com"]
8
8
 
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  "docs/fuzzing.md",
30
30
  "docs/heredocs.md",
31
31
  "docs/javascript.md",
32
+ "docs/local_variable_depth.md",
32
33
  "docs/mapping.md",
33
34
  "docs/releasing.md",
34
35
  "docs/ripper.md",
@@ -43,7 +44,7 @@ Gem::Specification.new do |spec|
43
44
  "include/prism/ast.h",
44
45
  "include/prism/defines.h",
45
46
  "include/prism/diagnostic.h",
46
- "include/prism/enc/pm_encoding.h",
47
+ "include/prism/encoding.h",
47
48
  "include/prism/node.h",
48
49
  "include/prism/options.h",
49
50
  "include/prism/pack.h",
@@ -84,14 +85,7 @@ Gem::Specification.new do |spec|
84
85
  "lib/prism/parse_result/newlines.rb",
85
86
  "lib/prism/visitor.rb",
86
87
  "src/diagnostic.c",
87
- "src/enc/pm_big5.c",
88
- "src/enc/pm_cp51932.c",
89
- "src/enc/pm_euc_jp.c",
90
- "src/enc/pm_gbk.c",
91
- "src/enc/pm_shift_jis.c",
92
- "src/enc/pm_tables.c",
93
- "src/enc/pm_unicode.c",
94
- "src/enc/pm_windows_31j.c",
88
+ "src/encoding.c",
95
89
  "src/node.c",
96
90
  "src/pack.c",
97
91
  "src/prettyprint.c",