prism 0.19.0 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +102 -1
- data/Makefile +5 -0
- data/README.md +9 -6
- data/config.yml +236 -38
- data/docs/build_system.md +19 -2
- data/docs/cruby_compilation.md +27 -0
- data/docs/parser_translation.md +34 -0
- data/docs/parsing_rules.md +19 -0
- data/docs/releasing.md +84 -16
- data/docs/ruby_api.md +1 -1
- data/docs/ruby_parser_translation.md +19 -0
- data/docs/serialization.md +19 -5
- data/ext/prism/api_node.c +1989 -1525
- data/ext/prism/extension.c +130 -30
- data/ext/prism/extension.h +2 -2
- data/include/prism/ast.h +1700 -505
- data/include/prism/defines.h +8 -0
- data/include/prism/diagnostic.h +49 -7
- data/include/prism/encoding.h +17 -0
- data/include/prism/options.h +40 -14
- data/include/prism/parser.h +34 -18
- data/include/prism/util/pm_buffer.h +9 -0
- data/include/prism/util/pm_constant_pool.h +18 -0
- data/include/prism/util/pm_newline_list.h +4 -14
- data/include/prism/util/pm_strpbrk.h +4 -1
- data/include/prism/version.h +2 -2
- data/include/prism.h +19 -2
- data/lib/prism/debug.rb +11 -5
- data/lib/prism/desugar_compiler.rb +225 -80
- data/lib/prism/dot_visitor.rb +36 -14
- data/lib/prism/dsl.rb +302 -299
- data/lib/prism/ffi.rb +107 -76
- data/lib/prism/lex_compat.rb +17 -1
- data/lib/prism/node.rb +4580 -2607
- data/lib/prism/node_ext.rb +27 -4
- data/lib/prism/parse_result.rb +75 -29
- data/lib/prism/serialize.rb +633 -305
- data/lib/prism/translation/parser/compiler.rb +1838 -0
- data/lib/prism/translation/parser/lexer.rb +335 -0
- data/lib/prism/translation/parser/rubocop.rb +45 -0
- data/lib/prism/translation/parser.rb +190 -0
- data/lib/prism/translation/parser33.rb +12 -0
- data/lib/prism/translation/parser34.rb +12 -0
- data/lib/prism/translation/ripper.rb +696 -0
- data/lib/prism/translation/ruby_parser.rb +1521 -0
- data/lib/prism/translation.rb +11 -0
- data/lib/prism.rb +1 -1
- data/prism.gemspec +18 -7
- data/rbi/prism.rbi +150 -88
- data/rbi/prism_static.rbi +15 -3
- data/sig/prism.rbs +996 -961
- data/sig/prism_static.rbs +123 -46
- data/src/diagnostic.c +264 -219
- data/src/encoding.c +21 -26
- data/src/node.c +2 -6
- data/src/options.c +29 -5
- data/src/prettyprint.c +176 -44
- data/src/prism.c +1499 -564
- data/src/serialize.c +35 -21
- data/src/token_type.c +353 -4
- data/src/util/pm_buffer.c +11 -0
- data/src/util/pm_constant_pool.c +37 -11
- data/src/util/pm_newline_list.c +6 -15
- data/src/util/pm_string.c +0 -7
- data/src/util/pm_strpbrk.c +122 -14
- metadata +16 -5
- data/docs/building.md +0 -29
- 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
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
*
|
29
|
-
|
30
|
-
|
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
|
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
|
+
```
|
data/docs/serialization.md
CHANGED
@@ -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
|
-
###
|
54
|
+
### error
|
55
55
|
|
56
56
|
| # bytes | field |
|
57
57
|
| --- | --- |
|
58
|
-
| string |
|
59
|
-
| location | the location in the source this
|
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
|
-
|
|
96
|
+
| error* | errors |
|
86
97
|
| varuint | number of warnings |
|
87
|
-
|
|
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 |
|