Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Sep 19, 2023
1 parent 7e57c97 commit 018beb1
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023-present Kevin Newton

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
59 changes: 56 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,62 @@
# parser-yarp

An experiment in translating the YARP AST into the whitequark/parser AST.
This is an early experiment in building the [whitequark/parser](https://github.com/whitequark/parser) gem's syntax tree using the [YARP](https://github.com/ruby/yarp) parser.

You can run RuboCop with:
## Installation

Add this line to your application's Gemfile:

```ruby
gem "parser-yarp"
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install parser-yarp

## Usage

The `parser` gem provides multiple parsers to support different versions of the Ruby grammar. This includes all of the Ruby versions going back to 1.8, as well as third-party parsers like MacRuby and RubyMotion. The `parser-yarp` gem provides another parser that uses the `YARP` parser to build the syntax tree.

You can use the `YARP` parser like you would any other. After requiring the parser, you should be able to call any of the regular `Parser::Base` APIs that you would normally use.

```ruby
require "parser/yarp"

Parser::YARP.parse_file("path/to/file.rb")
```

### RuboCop

To run RuboCop using the `parser-yarp` gem as the parser, you will need to require the `parser/yarp/rubocop` file. This file injects `YARP` into the known options for both `rubocop` and `rubocop-ast`, such that you can specify it in your `.rubocop.yml` file. Unfortunately `rubocop` doesn't support any direct way to do this, so we have to get a bit hacky.

First, set the `TargetRubyVersion` in your RuboCop configuration file to `89_65_82_80.33`. This is the version of Ruby that `YARP` reports itself as. (The leading numbers are the ASCII values for `YARP`.)

```yaml
AllCops:
TargetRubyVersion: 89_65_82_80.33
```
bundle exec ruby -rparser/yarp/rubocop $(bundle show rubocop)/exe/rubocop
Now when you run `rubocop` you will need to require the `parser/yarp/rubocop` file before executing so that it can inject the `YARP` parser into the known options.

```
bundle exec ruby -rparser/yarp/rubocop $(bundle exec which rubocop)
```
This should run RuboCop using the `YARP` parser.
## Development
Run `rake test` to run the tests. This runs tests exported from the `parser` gem into their own fixture files.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/kddnewton/parser-yarp.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
2 changes: 1 addition & 1 deletion lib/parser/yarp/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module Parser
class YARP < Base
VERSION_3_3 = 24_00_17_15.33
VERSION_3_3 = 89_65_82_80.33
end
end

Expand Down

0 comments on commit 018beb1

Please sign in to comment.