prism 0.19.0 → 0.24.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +102 -1
  3. data/Makefile +5 -0
  4. data/README.md +9 -6
  5. data/config.yml +236 -38
  6. data/docs/build_system.md +19 -2
  7. data/docs/cruby_compilation.md +27 -0
  8. data/docs/parser_translation.md +34 -0
  9. data/docs/parsing_rules.md +19 -0
  10. data/docs/releasing.md +84 -16
  11. data/docs/ruby_api.md +1 -1
  12. data/docs/ruby_parser_translation.md +19 -0
  13. data/docs/serialization.md +19 -5
  14. data/ext/prism/api_node.c +1989 -1525
  15. data/ext/prism/extension.c +130 -30
  16. data/ext/prism/extension.h +2 -2
  17. data/include/prism/ast.h +1700 -505
  18. data/include/prism/defines.h +8 -0
  19. data/include/prism/diagnostic.h +49 -7
  20. data/include/prism/encoding.h +17 -0
  21. data/include/prism/options.h +40 -14
  22. data/include/prism/parser.h +34 -18
  23. data/include/prism/util/pm_buffer.h +9 -0
  24. data/include/prism/util/pm_constant_pool.h +18 -0
  25. data/include/prism/util/pm_newline_list.h +4 -14
  26. data/include/prism/util/pm_strpbrk.h +4 -1
  27. data/include/prism/version.h +2 -2
  28. data/include/prism.h +19 -2
  29. data/lib/prism/debug.rb +11 -5
  30. data/lib/prism/desugar_compiler.rb +225 -80
  31. data/lib/prism/dot_visitor.rb +36 -14
  32. data/lib/prism/dsl.rb +302 -299
  33. data/lib/prism/ffi.rb +107 -76
  34. data/lib/prism/lex_compat.rb +17 -1
  35. data/lib/prism/node.rb +4580 -2607
  36. data/lib/prism/node_ext.rb +27 -4
  37. data/lib/prism/parse_result.rb +75 -29
  38. data/lib/prism/serialize.rb +633 -305
  39. data/lib/prism/translation/parser/compiler.rb +1838 -0
  40. data/lib/prism/translation/parser/lexer.rb +335 -0
  41. data/lib/prism/translation/parser/rubocop.rb +45 -0
  42. data/lib/prism/translation/parser.rb +190 -0
  43. data/lib/prism/translation/parser33.rb +12 -0
  44. data/lib/prism/translation/parser34.rb +12 -0
  45. data/lib/prism/translation/ripper.rb +696 -0
  46. data/lib/prism/translation/ruby_parser.rb +1521 -0
  47. data/lib/prism/translation.rb +11 -0
  48. data/lib/prism.rb +1 -1
  49. data/prism.gemspec +18 -7
  50. data/rbi/prism.rbi +150 -88
  51. data/rbi/prism_static.rbi +15 -3
  52. data/sig/prism.rbs +996 -961
  53. data/sig/prism_static.rbs +123 -46
  54. data/src/diagnostic.c +264 -219
  55. data/src/encoding.c +21 -26
  56. data/src/node.c +2 -6
  57. data/src/options.c +29 -5
  58. data/src/prettyprint.c +176 -44
  59. data/src/prism.c +1499 -564
  60. data/src/serialize.c +35 -21
  61. data/src/token_type.c +353 -4
  62. data/src/util/pm_buffer.c +11 -0
  63. data/src/util/pm_constant_pool.c +37 -11
  64. data/src/util/pm_newline_list.c +6 -15
  65. data/src/util/pm_string.c +0 -7
  66. data/src/util/pm_strpbrk.c +122 -14
  67. metadata +16 -5
  68. data/docs/building.md +0 -29
  69. data/lib/prism/ripper_compat.rb +0 -207
data/docs/releasing.md CHANGED
@@ -8,23 +8,91 @@ To release a new version of Prism, perform the following steps:
8
8
  * Add a new section for the new version at the top of the file.
9
9
  * Fill in the relevant changes — it may be easiest to click the link for the `Unreleased` heading to find the commits.
10
10
  * Update the links at the bottom of the file.
11
- * Update the version in the following files:
12
- * `prism.gemspec` in the `Gem::Specification#version=` method call
13
- * `ext/prism/extension.h` in the `EXPECTED_PRISM_VERSION` macro
14
- * `include/prism/version.h` in the version macros
15
- * `javascript/package.json` in the `version` field
16
- * `rust/prism-sys/tests/utils_tests.rs` in the `version_test` function
17
- * `templates/java/org/prism/Loader.java.erb` in the `load` function
18
- * `templates/javascript/src/deserialize.js.erb` in the version constants
19
- * `templates/lib/prism/serialize.rb.erb` in the version constants
20
- * Run `bundle install` to update the `Gemfile.lock` file.
21
- * Update `rust/prism-sys/Cargo.toml` to match the new version and run `cargo build`
22
- * Update `rust/prism/Cargo.toml` to match the new version and run `cargo build`
23
- * Commit all of the updated files.
11
+ * Update the version numbers in the various files that reference them:
12
+
13
+ ```sh
14
+ export PRISM_MAJOR="x"
15
+ export PRISM_MINOR="y"
16
+ export PRISM_PATCH="z"
17
+ export PRISM_VERSION="$PRISM_MAJOR.$PRISM_MINOR.$PRISM_PATCH"
18
+ ruby -pi -e 'gsub(/spec\.version = ".+?"/, %Q{spec.version = "#{ENV["PRISM_VERSION"]}"})' prism.gemspec
19
+ ruby -pi -e 'gsub(/EXPECTED_PRISM_VERSION ".+?"/, %Q{EXPECTED_PRISM_VERSION "#{ENV["PRISM_VERSION"]}"})' ext/prism/extension.h
20
+ ruby -pi -e 'gsub(/PRISM_VERSION_MAJOR \d+/, %Q{PRISM_VERSION_MAJOR #{ENV["PRISM_MAJOR"]}})' include/prism/version.h
21
+ ruby -pi -e 'gsub(/PRISM_VERSION_MINOR \d+/, %Q{PRISM_VERSION_MINOR #{ENV["PRISM_MINOR"]}})' include/prism/version.h
22
+ ruby -pi -e 'gsub(/PRISM_VERSION_PATCH \d+/, %Q{PRISM_VERSION_PATCH #{ENV["PRISM_PATCH"]}})' include/prism/version.h
23
+ ruby -pi -e 'gsub(/PRISM_VERSION ".+?"/, %Q{PRISM_VERSION "#{ENV["PRISM_VERSION"]}"})' include/prism/version.h
24
+ ruby -pi -e 'gsub(/"version": ".+?"/, %Q{"version": "#{ENV["PRISM_VERSION"]}"})' javascript/package.json
25
+ ruby -pi -e 'gsub(/lossy\(\), ".+?"/, %Q{lossy(), "#{ENV["PRISM_VERSION"]}"})' rust/ruby-prism-sys/tests/utils_tests.rs
26
+ ruby -pi -e 'gsub(/\d+, "prism major/, %Q{#{ENV["PRISM_MAJOR"]}, "prism major})' templates/java/org/prism/Loader.java.erb
27
+ ruby -pi -e 'gsub(/\d+, "prism minor/, %Q{#{ENV["PRISM_MINOR"]}, "prism minor})' templates/java/org/prism/Loader.java.erb
28
+ ruby -pi -e 'gsub(/\d+, "prism patch/, %Q{#{ENV["PRISM_PATCH"]}, "prism patch})' templates/java/org/prism/Loader.java.erb
29
+ ruby -pi -e 'gsub(/MAJOR_VERSION = \d+/, %Q{MAJOR_VERSION = #{ENV["PRISM_MAJOR"]}})' templates/javascript/src/deserialize.js.erb
30
+ ruby -pi -e 'gsub(/MINOR_VERSION = \d+/, %Q{MINOR_VERSION = #{ENV["PRISM_MINOR"]}})' templates/javascript/src/deserialize.js.erb
31
+ ruby -pi -e 'gsub(/PATCH_VERSION = \d+/, %Q{PATCH_VERSION = #{ENV["PRISM_PATCH"]}})' templates/javascript/src/deserialize.js.erb
32
+ ruby -pi -e 'gsub(/MAJOR_VERSION = \d+/, %Q{MAJOR_VERSION = #{ENV["PRISM_MAJOR"]}})' templates/lib/prism/serialize.rb.erb
33
+ ruby -pi -e 'gsub(/MINOR_VERSION = \d+/, %Q{MINOR_VERSION = #{ENV["PRISM_MINOR"]}})' templates/lib/prism/serialize.rb.erb
34
+ ruby -pi -e 'gsub(/PATCH_VERSION = \d+/, %Q{PATCH_VERSION = #{ENV["PRISM_PATCH"]}})' templates/lib/prism/serialize.rb.erb
35
+ ruby -pi -e 'gsub(/^version = ".+?"/, %Q{version = "#{ENV["PRISM_VERSION"]}"})' rust/ruby-prism-sys/Cargo.toml
36
+ ruby -pi -e 'gsub(/^version = ".+?"/, %Q{version = "#{ENV["PRISM_VERSION"]}"})' rust/ruby-prism/Cargo.toml
37
+ ruby -pi -e 'gsub(/^ruby-prism-sys = \{ version = ".+?"/, %Q{ruby-prism-sys = \{ version = "#{ENV["PRISM_VERSION"]}"})' rust/ruby-prism/Cargo.toml
38
+ ```
39
+
40
+ * Update the `Gemfile.lock` file:
41
+
42
+ ```sh
43
+ chruby ruby-3.4.0-dev
44
+ bundle install
45
+ ```
46
+
47
+ * Update the version-specific lockfiles:
48
+
49
+ ```sh
50
+ chruby ruby-2.7.8 && BUNDLE_GEMFILE=gemfiles/2.7/Gemfile bundle install
51
+ chruby ruby-3.0.6 && BUNDLE_GEMFILE=gemfiles/3.0/Gemfile bundle install
52
+ chruby ruby-3.1.4 && BUNDLE_GEMFILE=gemfiles/3.1/Gemfile bundle install
53
+ chruby ruby-3.2.3 && BUNDLE_GEMFILE=gemfiles/3.2/Gemfile bundle install
54
+ chruby ruby-3.3.0 && BUNDLE_GEMFILE=gemfiles/3.3/Gemfile bundle install
55
+ chruby ruby-3.4.0-dev && BUNDLE_GEMFILE=gemfiles/3.4/Gemfile bundle install
56
+ chruby jruby-9.4.5.0 && BUNDLE_GEMFILE=gemfiles/jruby/Gemfile bundle install
57
+ chruby truffleruby-23.1.2 && BUNDLE_GEMFILE=gemfiles/truffleruby/Gemfile bundle install
58
+ chruby ruby-3.4.0-dev
59
+ ```
60
+
61
+ * Update the cargo lockfiles:
62
+
63
+ ```sh
64
+ bundle exec rake cargo:build
65
+ ```
66
+
67
+ * Commit all of the updated files:
68
+
69
+ ```sh
70
+ git commit -am "Bump to v$PRISM_VERSION"
71
+ ```
24
72
 
25
73
  ## Publishing
26
74
 
27
75
  * Update the GitHub release page with a copy of the latest entry in the `CHANGELOG.md` file.
28
- * Run `bundle exec rake release` to publish the gem to [rubygems.org](rubygems.org). Note that you must have access to the `prism` gem to do this.
29
- * Either download the `wasm` artifact from GitHub actions or generate it yourself with `make wasm`.
30
- * Run `npm publish` to publish the JavaScript package to [npmjs.com](npmjs.com). Note that you must have access to the `ruby-prism` package to do this.
76
+ * Publish the gem to [rubygems.org](rubygems.org). Note that you must have access to the `prism` gem to do this.
77
+
78
+ ```sh
79
+ bundle exec rake release
80
+ ```
81
+
82
+ * Generate the `wasm` artifact (or download it from GitHub actions and put it in `javascript/src/prism.wasm`).
83
+
84
+ ```sh
85
+ make wasm
86
+ ```
87
+
88
+ * Publish the JavaScript package to [npmjs.com](npmjs.com). Note that you must have access to the `@ruby/prism` package to do this.
89
+
90
+ ```sh
91
+ npm publish
92
+ ```
93
+
94
+ * Publish the rust crate to [crates.io](crates.io). Note that you must have access to the `ruby-prism-sys` and `ruby-prism` crates to do this.
95
+
96
+ ```sh
97
+ bundle exec rake cargo:publish:real
98
+ ```
data/docs/ruby_api.md CHANGED
@@ -14,7 +14,7 @@ The full API is documented below.
14
14
 
15
15
  ## API
16
16
 
17
- * `Prism.dump(source, filepath)` - parse the syntax tree corresponding to the given source string and filepath, and serialize it to a string. Filepath can be nil.
17
+ * `Prism.dump(source)` - parse the syntax tree corresponding to the given source string, and serialize it to a string
18
18
  * `Prism.dump_file(filepath)` - parse the syntax tree corresponding to the given source file and serialize it to a string
19
19
  * `Prism.lex(source)` - parse the tokens corresponding to the given source string and return them as an array within a parse result
20
20
  * `Prism.lex_file(filepath)` - parse the tokens corresponding to the given source file and return them as an array within a parse result
@@ -0,0 +1,19 @@
1
+ # ruby_parser translation
2
+
3
+ Prism ships with the ability to translate its syntax tree into the syntax tree used by the [seattlerb/ruby_parser](https://github.com/seattlerb/ruby_parser) gem. This allows you to use tools built on top of the `ruby_parser` gem with the `prism` parser.
4
+
5
+ ## Usage
6
+
7
+ You can call the `parse` and `parse_file` methods on the `Prism::Translation::RubyParser` module:
8
+
9
+ ```ruby
10
+ filepath = "path/to/file.rb"
11
+ Prism::Translation::RubyParser.parse_file(filepath)
12
+ ```
13
+
14
+ This will return to you `Sexp` objects that mirror the result of calling `RubyParser` methods, as in:
15
+
16
+ ```ruby
17
+ filepath = "path/to/file.rb"
18
+ RubyParser.new.parse(File.read(filepath), filepath)
19
+ ```
@@ -51,12 +51,21 @@ The comment type is one of:
51
51
  | location | the location of the key of the magic comment |
52
52
  | location | the location of the value of the magic comment |
53
53
 
54
- ### diagnostic
54
+ ### error
55
55
 
56
56
  | # bytes | field |
57
57
  | --- | --- |
58
- | string | diagnostic message (ASCII-only characters) |
59
- | location | the location in the source this diagnostic applies to |
58
+ | string | error message (ASCII-only characters) |
59
+ | location | the location in the source this error applies to |
60
+ | `1` | the level of the error: `0` for `fatal` |
61
+
62
+ ## warning
63
+
64
+ | # bytes | field |
65
+ | --- | --- |
66
+ | string | warning message (ASCII-only characters) |
67
+ | location | the location in the source this warning applies to |
68
+ | `1` | the level of the warning: `0` for `default` and `1` for `verbose` |
60
69
 
61
70
  ## Structure
62
71
 
@@ -76,15 +85,17 @@ The header is structured like the following table:
76
85
  | `1` | 1 indicates only semantics fields were serialized, 0 indicates all fields were serialized (including location fields) |
77
86
  | string | the encoding name |
78
87
  | varsint | the start line |
88
+ | varuint | number of newline offsets |
89
+ | varuint* | newline offsets |
79
90
  | varuint | number of comments |
80
91
  | comment* | comments |
81
92
  | varuint | number of magic comments |
82
93
  | magic comment* | magic comments |
83
94
  | location? | the optional location of the `__END__` keyword and its contents |
84
95
  | varuint | number of errors |
85
- | diagnostic* | errors |
96
+ | error* | errors |
86
97
  | varuint | number of warnings |
87
- | diagnostic* | warnings |
98
+ | warning* | warnings |
88
99
  | `4` | content pool offset |
89
100
  | varuint | content pool size |
90
101
 
@@ -175,9 +186,12 @@ The final argument to `pm_serialize_parse` is an optional string that controls t
175
186
  | ... | the encoding bytes |
176
187
  | `1` | frozen string literal |
177
188
  | `1` | suppress warnings |
189
+ | `1` | syntax version, see [pm_options_version_t](https://github.com/ruby/prism/blob/main/include/prism/options.h) for valid values |
178
190
  | `4` | the number of scopes |
179
191
  | ... | the scopes |
180
192
 
193
+ Scopes are ordered from the outermost scope to the innermost one.
194
+
181
195
  Each scope is layed out as follows:
182
196
 
183
197
  | # bytes | field |