prism 0.29.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +115 -1
  3. data/CONTRIBUTING.md +0 -4
  4. data/Makefile +1 -1
  5. data/README.md +4 -0
  6. data/config.yml +920 -148
  7. data/docs/build_system.md +8 -11
  8. data/docs/fuzzing.md +1 -1
  9. data/docs/parsing_rules.md +4 -1
  10. data/docs/relocation.md +34 -0
  11. data/docs/ripper_translation.md +22 -0
  12. data/docs/serialization.md +3 -0
  13. data/ext/prism/api_node.c +2863 -2079
  14. data/ext/prism/extconf.rb +14 -37
  15. data/ext/prism/extension.c +241 -391
  16. data/ext/prism/extension.h +2 -2
  17. data/include/prism/ast.h +2156 -453
  18. data/include/prism/defines.h +58 -7
  19. data/include/prism/diagnostic.h +24 -6
  20. data/include/prism/node.h +0 -21
  21. data/include/prism/options.h +94 -3
  22. data/include/prism/parser.h +82 -40
  23. data/include/prism/regexp.h +18 -8
  24. data/include/prism/static_literals.h +3 -2
  25. data/include/prism/util/pm_char.h +1 -2
  26. data/include/prism/util/pm_constant_pool.h +0 -8
  27. data/include/prism/util/pm_integer.h +22 -15
  28. data/include/prism/util/pm_newline_list.h +11 -0
  29. data/include/prism/util/pm_string.h +28 -12
  30. data/include/prism/version.h +3 -3
  31. data/include/prism.h +47 -11
  32. data/lib/prism/compiler.rb +3 -0
  33. data/lib/prism/desugar_compiler.rb +111 -74
  34. data/lib/prism/dispatcher.rb +16 -1
  35. data/lib/prism/dot_visitor.rb +55 -34
  36. data/lib/prism/dsl.rb +660 -468
  37. data/lib/prism/ffi.rb +113 -8
  38. data/lib/prism/inspect_visitor.rb +296 -64
  39. data/lib/prism/lex_compat.rb +1 -1
  40. data/lib/prism/mutation_compiler.rb +11 -6
  41. data/lib/prism/node.rb +4262 -5023
  42. data/lib/prism/node_ext.rb +91 -14
  43. data/lib/prism/parse_result/comments.rb +0 -7
  44. data/lib/prism/parse_result/errors.rb +65 -0
  45. data/lib/prism/parse_result/newlines.rb +101 -11
  46. data/lib/prism/parse_result.rb +183 -6
  47. data/lib/prism/reflection.rb +12 -10
  48. data/lib/prism/relocation.rb +504 -0
  49. data/lib/prism/serialize.rb +496 -609
  50. data/lib/prism/string_query.rb +30 -0
  51. data/lib/prism/translation/parser/compiler.rb +185 -155
  52. data/lib/prism/translation/parser/lexer.rb +26 -4
  53. data/lib/prism/translation/parser.rb +9 -4
  54. data/lib/prism/translation/ripper.rb +23 -25
  55. data/lib/prism/translation/ruby_parser.rb +86 -17
  56. data/lib/prism/visitor.rb +3 -0
  57. data/lib/prism.rb +6 -8
  58. data/prism.gemspec +9 -5
  59. data/rbi/prism/dsl.rbi +521 -0
  60. data/rbi/prism/node.rbi +1115 -1120
  61. data/rbi/prism/parse_result.rbi +29 -0
  62. data/rbi/prism/string_query.rbi +12 -0
  63. data/rbi/prism/visitor.rbi +3 -0
  64. data/rbi/prism.rbi +36 -30
  65. data/sig/prism/dsl.rbs +190 -303
  66. data/sig/prism/mutation_compiler.rbs +1 -0
  67. data/sig/prism/node.rbs +678 -632
  68. data/sig/prism/parse_result.rbs +22 -0
  69. data/sig/prism/relocation.rbs +185 -0
  70. data/sig/prism/string_query.rbs +11 -0
  71. data/sig/prism/visitor.rbs +1 -0
  72. data/sig/prism.rbs +103 -64
  73. data/src/diagnostic.c +64 -28
  74. data/src/node.c +502 -1739
  75. data/src/options.c +76 -27
  76. data/src/prettyprint.c +188 -112
  77. data/src/prism.c +3376 -2293
  78. data/src/regexp.c +208 -71
  79. data/src/serialize.c +182 -50
  80. data/src/static_literals.c +64 -85
  81. data/src/token_type.c +4 -4
  82. data/src/util/pm_char.c +1 -1
  83. data/src/util/pm_constant_pool.c +0 -8
  84. data/src/util/pm_integer.c +53 -25
  85. data/src/util/pm_newline_list.c +29 -0
  86. data/src/util/pm_string.c +131 -80
  87. data/src/util/pm_strpbrk.c +32 -6
  88. metadata +11 -7
  89. data/include/prism/util/pm_string_list.h +0 -44
  90. data/lib/prism/debug.rb +0 -249
  91. data/lib/prism/translation/parser/rubocop.rb +0 -73
  92. data/src/util/pm_string_list.c +0 -28
data/ext/prism/extconf.rb CHANGED
@@ -50,7 +50,7 @@ def make(env, target)
50
50
  Dir.chdir(File.expand_path("../..", __dir__)) do
51
51
  system(
52
52
  env,
53
- RUBY_PLATFORM.include?("openbsd") ? "gmake" : "make",
53
+ RUBY_PLATFORM.match?(/openbsd|freebsd/) ? "gmake" : "make",
54
54
  target,
55
55
  exception: true
56
56
  )
@@ -70,26 +70,6 @@ if RUBY_ENGINE != "ruby"
70
70
  return
71
71
  end
72
72
 
73
- # We're going to need to run `make` using prism's `Makefile`.
74
- # We want to use the same toolchain (compiler, flags, etc) to compile libprism.a and
75
- # the C extension since they will be linked together.
76
- # The C extension uses RbConfig, which contains values from the toolchain that built the running Ruby.
77
- env = RbConfig::CONFIG.slice("SOEXT", "CPPFLAGS", "CFLAGS", "CC", "AR", "ARFLAGS", "MAKEDIRS", "RMALL")
78
-
79
- # It's possible that the Ruby that is being run wasn't actually compiled on this
80
- # machine, in which case parts of RbConfig might be incorrect. In this case
81
- # we'll need to do some additional checks and potentially fall back to defaults.
82
- if env.key?("CC") && !File.exist?(env["CC"])
83
- env.delete("CC")
84
- env.delete("CFLAGS")
85
- env.delete("CPPFLAGS")
86
- end
87
-
88
- if env.key?("AR") && !File.exist?(env["AR"])
89
- env.delete("AR")
90
- env.delete("ARFLAGS")
91
- end
92
-
93
73
  require "mkmf"
94
74
 
95
75
  # First, ensure that we can find the header for the prism library.
@@ -127,24 +107,21 @@ end
127
107
  # By default, all symbols are hidden in the shared library.
128
108
  append_cflags("-fvisibility=hidden")
129
109
 
130
- # We need to link against the libprism.a archive, which is built by the
131
- # project's `Makefile`. We'll build it if it doesn't exist yet, and then add it
132
- # to `mkmf`'s list of local libraries.
133
- archive_target = "build/libprism.a"
134
- archive_path = File.expand_path("../../#{archive_target}", __dir__)
110
+ def src_list(path)
111
+ srcdir = path.dup
112
+ RbConfig.expand(srcdir) # mutates srcdir :-/
113
+ Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
114
+ end
135
115
 
136
- make(env, archive_target) unless File.exist?(archive_path)
137
- $LOCAL_LIBS << " #{archive_path}"
116
+ def add_libprism_source(path)
117
+ $VPATH << path
118
+ src_list path
119
+ end
120
+
121
+ $srcs = src_list("$(srcdir)") +
122
+ add_libprism_source("$(srcdir)/../../src") +
123
+ add_libprism_source("$(srcdir)/../../src/util")
138
124
 
139
125
  # Finally, we'll create the `Makefile` that is going to be used to configure and
140
126
  # build the C extension.
141
127
  create_makefile("prism/prism")
142
-
143
- # Now that the `Makefile` for the C extension is built, we'll append on an extra
144
- # rule that dictates that the extension should be rebuilt if the archive is
145
- # updated.
146
- File.open("Makefile", "a") do |mf|
147
- mf.puts
148
- mf.puts("# Automatically rebuild the extension if libprism.a changed")
149
- mf.puts("$(TARGET_SO): $(LOCAL_LIBS)")
150
- end