prism 0.24.0 → 0.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +69 -1
  4. data/Makefile +22 -16
  5. data/README.md +45 -6
  6. data/config.yml +510 -4
  7. data/docs/build_system.md +31 -0
  8. data/docs/configuration.md +3 -0
  9. data/docs/cruby_compilation.md +1 -1
  10. data/docs/parser_translation.md +14 -9
  11. data/docs/releasing.md +7 -9
  12. data/docs/ripper_translation.md +50 -0
  13. data/docs/ruby_api.md +1 -0
  14. data/docs/serialization.md +26 -5
  15. data/ext/prism/api_node.c +911 -815
  16. data/ext/prism/api_pack.c +9 -0
  17. data/ext/prism/extconf.rb +34 -13
  18. data/ext/prism/extension.c +341 -68
  19. data/ext/prism/extension.h +5 -4
  20. data/include/prism/ast.h +213 -64
  21. data/include/prism/defines.h +106 -2
  22. data/include/prism/diagnostic.h +146 -72
  23. data/include/prism/encoding.h +22 -4
  24. data/include/prism/node.h +93 -0
  25. data/include/prism/options.h +82 -7
  26. data/include/prism/pack.h +11 -0
  27. data/include/prism/parser.h +203 -54
  28. data/include/prism/prettyprint.h +8 -0
  29. data/include/prism/static_literals.h +118 -0
  30. data/include/prism/util/pm_buffer.h +65 -2
  31. data/include/prism/util/pm_constant_pool.h +18 -1
  32. data/include/prism/util/pm_integer.h +119 -0
  33. data/include/prism/util/pm_list.h +1 -1
  34. data/include/prism/util/pm_newline_list.h +8 -0
  35. data/include/prism/util/pm_string.h +26 -2
  36. data/include/prism/version.h +2 -2
  37. data/include/prism.h +59 -1
  38. data/lib/prism/compiler.rb +8 -1
  39. data/lib/prism/debug.rb +46 -3
  40. data/lib/prism/desugar_compiler.rb +4 -2
  41. data/lib/prism/dispatcher.rb +29 -0
  42. data/lib/prism/dot_visitor.rb +87 -16
  43. data/lib/prism/dsl.rb +24 -12
  44. data/lib/prism/ffi.rb +77 -12
  45. data/lib/prism/lex_compat.rb +17 -15
  46. data/lib/prism/mutation_compiler.rb +11 -0
  47. data/lib/prism/node.rb +2112 -2499
  48. data/lib/prism/node_ext.rb +77 -29
  49. data/lib/prism/pack.rb +4 -0
  50. data/lib/prism/parse_result/comments.rb +34 -17
  51. data/lib/prism/parse_result/newlines.rb +3 -1
  52. data/lib/prism/parse_result.rb +83 -32
  53. data/lib/prism/pattern.rb +16 -4
  54. data/lib/prism/polyfill/string.rb +12 -0
  55. data/lib/prism/reflection.rb +421 -0
  56. data/lib/prism/serialize.rb +450 -102
  57. data/lib/prism/translation/parser/compiler.rb +189 -50
  58. data/lib/prism/translation/parser/lexer.rb +103 -22
  59. data/lib/prism/translation/parser/rubocop.rb +41 -13
  60. data/lib/prism/translation/parser.rb +119 -7
  61. data/lib/prism/translation/parser33.rb +1 -1
  62. data/lib/prism/translation/parser34.rb +1 -1
  63. data/lib/prism/translation/ripper/sexp.rb +125 -0
  64. data/lib/prism/translation/ripper/shim.rb +5 -0
  65. data/lib/prism/translation/ripper.rb +3212 -462
  66. data/lib/prism/translation/ruby_parser.rb +35 -18
  67. data/lib/prism/translation.rb +3 -1
  68. data/lib/prism/visitor.rb +10 -0
  69. data/lib/prism.rb +9 -18
  70. data/prism.gemspec +39 -6
  71. data/rbi/prism/compiler.rbi +14 -0
  72. data/rbi/prism/desugar_compiler.rbi +5 -0
  73. data/rbi/prism/mutation_compiler.rbi +5 -0
  74. data/rbi/prism/node.rbi +8674 -0
  75. data/rbi/prism/node_ext.rbi +102 -0
  76. data/rbi/prism/parse_result.rbi +307 -0
  77. data/rbi/prism/reflection.rbi +64 -0
  78. data/rbi/prism/translation/parser/compiler.rbi +13 -0
  79. data/rbi/prism/translation/parser.rbi +11 -0
  80. data/rbi/prism/translation/parser33.rbi +6 -0
  81. data/rbi/prism/translation/parser34.rbi +6 -0
  82. data/rbi/prism/translation/ripper/ripper_compiler.rbi +5 -0
  83. data/rbi/prism/translation/ripper.rbi +25 -0
  84. data/rbi/prism/translation/ruby_parser.rbi +11 -0
  85. data/rbi/prism/visitor.rbi +470 -0
  86. data/rbi/prism.rbi +38 -7748
  87. data/sig/prism/compiler.rbs +9 -0
  88. data/sig/prism/dispatcher.rbs +16 -0
  89. data/sig/prism/dot_visitor.rbs +6 -0
  90. data/sig/prism/dsl.rbs +462 -0
  91. data/sig/prism/mutation_compiler.rbs +158 -0
  92. data/sig/prism/node.rbs +3538 -0
  93. data/sig/prism/node_ext.rbs +78 -0
  94. data/sig/prism/pack.rbs +43 -0
  95. data/sig/prism/parse_result.rbs +128 -0
  96. data/sig/prism/pattern.rbs +13 -0
  97. data/sig/prism/reflection.rbs +56 -0
  98. data/sig/prism/serialize.rbs +7 -0
  99. data/sig/prism/visitor.rbs +168 -0
  100. data/sig/prism.rbs +188 -4767
  101. data/src/diagnostic.c +597 -230
  102. data/src/encoding.c +211 -108
  103. data/src/node.c +7526 -447
  104. data/src/options.c +66 -31
  105. data/src/pack.c +33 -17
  106. data/src/prettyprint.c +1294 -1385
  107. data/src/prism.c +4015 -1149
  108. data/src/regexp.c +17 -2
  109. data/src/serialize.c +47 -28
  110. data/src/static_literals.c +552 -0
  111. data/src/token_type.c +4 -3
  112. data/src/util/pm_buffer.c +147 -20
  113. data/src/util/pm_char.c +4 -4
  114. data/src/util/pm_constant_pool.c +35 -11
  115. data/src/util/pm_integer.c +635 -0
  116. data/src/util/pm_list.c +1 -1
  117. data/src/util/pm_newline_list.c +14 -5
  118. data/src/util/pm_string.c +134 -5
  119. data/src/util/pm_string_list.c +2 -2
  120. metadata +41 -8
  121. data/docs/ripper.md +0 -36
  122. data/include/prism/util/pm_state_stack.h +0 -42
  123. data/rbi/prism_static.rbi +0 -207
  124. data/sig/prism_static.rbs +0 -201
  125. data/src/util/pm_state_stack.c +0 -25
data/ext/prism/api_pack.c CHANGED
@@ -1,5 +1,12 @@
1
1
  #include "prism/extension.h"
2
2
 
3
+ #ifdef PRISM_EXCLUDE_PACK
4
+
5
+ void
6
+ Init_prism_pack(void) {}
7
+
8
+ #else
9
+
3
10
  static VALUE rb_cPrism;
4
11
  static VALUE rb_cPrismPack;
5
12
  static VALUE rb_cPrismPackDirective;
@@ -265,3 +272,5 @@ Init_prism_pack(void) {
265
272
  pack_symbol = ID2SYM(rb_intern("pack"));
266
273
  unpack_symbol = ID2SYM(rb_intern("unpack"));
267
274
  }
275
+
276
+ #endif
data/ext/prism/extconf.rb CHANGED
@@ -6,17 +6,24 @@ if ARGV.delete("--help")
6
6
 
7
7
  Flags that are always valid:
8
8
 
9
- --enable-debug-mode-build
10
- Enable debug mode build.
11
- You may also use set PRISM_DEBUG_MODE_BUILD environment variable.
9
+ --enable-build-debug
10
+ Enable debug build.
11
+ You may also set the PRISM_BUILD_DEBUG environment variable.
12
+
13
+ --enable-build-minimal
14
+ Enable minimal build.
15
+ You may also set the PRISM_BUILD_MINIMAL environment variable.
12
16
 
13
17
  --help
14
18
  Display this message.
15
19
 
16
20
  Environment variables used:
17
21
 
18
- PRISM_DEBUG_MODE_BUILD
19
- Equivalent to `--enable-debug-mode-build` when set, even if nil or blank.
22
+ PRISM_BUILD_DEBUG
23
+ Equivalent to `--enable-build-debug` when set, even if nil or blank.
24
+
25
+ PRISM_BUILD_MINIMAL
26
+ Equivalent to `--enable-build-minimal` when set, even if nil or blank.
20
27
 
21
28
  TEXT
22
29
  exit!(0)
@@ -33,17 +40,22 @@ def generate_templates
33
40
  end
34
41
  end
35
42
 
43
+ require "rbconfig"
44
+
36
45
  # Runs `make` in the root directory of the project. Note that this is the
37
46
  # `Makefile` for the overall project, not the `Makefile` that is being generated
38
47
  # by this script.`
39
48
  def make(target)
40
49
  Dir.chdir(File.expand_path("../..", __dir__)) do
41
- system("make", target, exception: true)
50
+ system(
51
+ RbConfig::CONFIG.slice(*%w[SOEXT CPPFLAGS CFLAGS CC AR ARFLAGS MAKEDIRS RMALL]), # env
52
+ RUBY_PLATFORM.include?("openbsd") ? "gmake" : "make",
53
+ target,
54
+ exception: true
55
+ )
42
56
  end
43
57
  end
44
58
 
45
- require "rbconfig"
46
-
47
59
  # On non-CRuby we only need the shared library since we'll interface with it
48
60
  # through FFI, so we'll build only that and not the C extension. We also avoid
49
61
  # `require "mkmf"` as that prepends the LLVM toolchain to PATH on TruffleRuby,
@@ -71,13 +83,22 @@ unless find_header("prism/extension.h", File.expand_path("..", __dir__))
71
83
  raise "prism/extension.h is required"
72
84
  end
73
85
 
74
- # If `--enable-debug-mode-build` is passed to this script or the
75
- # `PRISM_DEBUG_MODE_BUILD` environment variable is defined, we'll build with the
76
- # `PRISM_DEBUG_MODE_BUILD` macro defined. This causes parse functions to
86
+ # If `--enable-build-debug` is passed to this script or the
87
+ # `PRISM_BUILD_DEBUG` environment variable is defined, we'll build with the
88
+ # `PRISM_BUILD_DEBUG` macro defined. This causes parse functions to
77
89
  # duplicate their input so that they have clearly set bounds, which is useful
78
90
  # for finding bugs that cause the parser to read off the end of the input.
79
- if enable_config("debug-mode-build", ENV["PRISM_DEBUG_MODE_BUILD"] || false)
80
- append_cflags("-DPRISM_DEBUG_MODE_BUILD")
91
+ if enable_config("build-debug", ENV["PRISM_BUILD_DEBUG"] || false)
92
+ append_cflags("-DPRISM_BUILD_DEBUG")
93
+ end
94
+
95
+ # If `--enable-build-minimal` is passed to this script or the
96
+ # `PRISM_BUILD_MINIMAL` environment variable is defined, we'll build with the
97
+ # set of defines that comprise the minimal set. This causes the parser to be
98
+ # built with minimal features, necessary for stripping out functionality when
99
+ # the size of the final built artifact is a concern.
100
+ if enable_config("build-minimal", ENV["PRISM_BUILD_MINIMAL"] || false)
101
+ append_cflags("-DPRISM_BUILD_MINIMAL")
81
102
  end
82
103
 
83
104
  # By default, all symbols are hidden in the shared library.