ruby-next 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +27 -8
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e404053f4c0ea48bfed4dca7cd28446c912b3371f2a318dae6da890ff0764be4
|
4
|
+
data.tar.gz: 4f520ce514d2a4d1b9ec5491e3d47fedf821ecb0841038e4f49b96f44ea7ddfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17e38527a8ba3423c0c7f0605d0bdf76e32fbbed8c95608b1af708bba5ed00f8292d5e863a6a96af05a73e3217b168ce6c2508be033e52e6caeb0f0847962f29
|
7
|
+
data.tar.gz: 71b6e39a4b334728d96c5f62170bd80675475d10280b200da743dde105473ea52571c41a8e52504ac80065ec0e24e69b5a999d53601750736cec5d51ac3e750b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.0.3 (2024-04-18)
|
6
|
+
|
7
|
+
- Fix RuboCop compatibility.
|
8
|
+
|
9
|
+
## 1.0.2 (2024-02-23)
|
10
|
+
|
11
|
+
- Automatically mark context as dirty if `#safe_rewrite` modifies source code. ([@palkan][])
|
12
|
+
|
13
|
+
- Add `context.path` to rewriters to access the current file path (if any). ([@palkan][])
|
14
|
+
|
5
15
|
## 1.0.1 (2024-01-28)
|
6
16
|
|
7
17
|
- Fix using Data with inheritance (`class X < Data.define(...)`). ([@palkan][])
|
data/README.md
CHANGED
@@ -170,7 +170,7 @@ Ruby 3.2 has introduced a new core class—[Data](https://bugs.ruby-lang.org/iss
|
|
170
170
|
|
171
171
|
If you want to opt-out from loading Data backport, you must set the `RUBY_NEXT_DISABLE_DATA` env variable to `true`.
|
172
172
|
|
173
|
-
#### Known limitations
|
173
|
+
#### Known limitations when using Data
|
174
174
|
|
175
175
|
Currently, passing Hash as a last positional argument to `Data.new` is not supported in Ruby <3.0 (due to the difference in keyword arguments handling). We recommend always using keyword arguments when initializing Data objects.
|
176
176
|
|
@@ -565,6 +565,9 @@ Wonder what would happen if Ruby get a null coalescing operator (`??=`) or some
|
|
565
565
|
|
566
566
|
Ruby Next allows you to write your own syntax rewriters. Full-featured rewriters (used by Ruby Next itself) operate on AST and usually require parser modifications. However, we also support text-based rewriters which can be used to experiment with new syntax much quicker without dealing with grammars, parsers and syntax trees.
|
567
567
|
|
568
|
+
> [!TIP]
|
569
|
+
> You can experiment with Ruby Next rewriters at our [online playground][playground]!
|
570
|
+
|
568
571
|
To implement a text-based rewriter, you need to create a new class inherited from `RubyNext::Language::Rewriters::Text` and implementing either `#rewrite` or `#safe_rewrite` method. For example, the method reference operator (`.:`) could be implemented as follows:
|
569
572
|
|
570
573
|
```ruby
|
@@ -576,11 +579,7 @@ class MethodReferenceRewriter < RubyNext::Language::Rewriters::Text
|
|
576
579
|
MIN_SUPPORTED_VERSION = Gem::Version.new(RubyNext::NEXT_VERSION)
|
577
580
|
|
578
581
|
def safe_rewrite(source)
|
579
|
-
source.gsub(/\.:([\w_]+)
|
580
|
-
context.track! self
|
581
|
-
|
582
|
-
".method(:#{$1})"
|
583
|
-
end
|
582
|
+
source.gsub(/\.:([\w_]+)/, '.method(:\1)')
|
584
583
|
end
|
585
584
|
end
|
586
585
|
|
@@ -588,9 +587,28 @@ end
|
|
588
587
|
RubyNext::Language.rewriters << MethodReferenceRewriter
|
589
588
|
```
|
590
589
|
|
591
|
-
The `
|
590
|
+
The `#safe_rewrite` method operates on the normalized source code (i.e., without comments and string literals). It's useful when you want to avoid transpiling inside strings or comments. If you want to transpile the original contents, you can use the `#rewrite` method instead. For example, if you want to rewrite comments:
|
591
|
+
|
592
|
+
```ruby
|
593
|
+
|
594
|
+
class NoteDateRewriter < RubyNext::Language::Rewriters::Text
|
595
|
+
NAME = "note-comment-date"
|
596
|
+
MIN_SUPPORTED_VERSION = Gem::Version.new(RubyNext::NEXT_VERSION)
|
597
|
+
|
598
|
+
def rewrite(source)
|
599
|
+
source.gsub("# NOTE:") do |_match|
|
600
|
+
context.track!(self)
|
601
|
+
"# NOTE (#{Date.today}):"
|
602
|
+
end
|
603
|
+
end
|
604
|
+
end
|
605
|
+
|
606
|
+
RubyNext::Language.rewriters << NoteDateRewriter
|
607
|
+
```
|
608
|
+
|
609
|
+
Note that we use the `context` object in the example above. It is responsible for tracking if the rewriter was used for the current file. You must call the `context.track!` method to mark the file as _dirty_ (i.e., it should be transpiled). The input parameter (`source`) is the Ruby source code of the file being transpiled and the output must be the transpiled source code. When using `#safe_rewrite`, marking content as dirty explicitly is not necessary.
|
592
610
|
|
593
|
-
|
611
|
+
### Using parser combinators (Paco)
|
594
612
|
|
595
613
|
Under the hood, `#safe_rewrite` uses [Paco][] to parse the source and separate string literals from the rest of the code. You can also leverage [Paco][] in your text rewriters, if you want more control on the parsing process. For better experience, we provide a DSL to define a custom parser and the `#parse` method to use it. Here is an example of implementing the `.:` operator using a Paco parser:
|
596
614
|
|
@@ -689,3 +707,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
689
707
|
[require-hooks]: https://github.com/ruby-next/require-hooks
|
690
708
|
[Natalie]: https://natalie-lang.org
|
691
709
|
[Paco]: https://github.com/ruby-next/paco
|
710
|
+
[playground]: https://ruby-next.github.io
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-next
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-next-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.
|
19
|
+
version: 1.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0.
|
26
|
+
version: 1.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: ruby-next-parser
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +101,7 @@ metadata:
|
|
101
101
|
documentation_uri: https://github.com/ruby-next/ruby-next/blob/master/README.md
|
102
102
|
homepage_uri: https://github.com/ruby-next/ruby-next
|
103
103
|
source_code_uri: https://github.com/ruby-next/ruby-next
|
104
|
-
post_install_message:
|
104
|
+
post_install_message:
|
105
105
|
rdoc_options: []
|
106
106
|
require_paths:
|
107
107
|
- lib
|
@@ -116,8 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
|
-
rubygems_version: 3.4.
|
120
|
-
signing_key:
|
119
|
+
rubygems_version: 3.4.19
|
120
|
+
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: Make older Rubies quack like edge Ruby
|
123
123
|
test_files: []
|