You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A fast ripper subclass used for generating syntax trees from Ruby code.
6
+
A fast ripper subclass used for parsing and formatting Ruby code.
7
7
8
8
## Installation
9
9
10
10
Add this line to your application's Gemfile:
11
11
12
12
```ruby
13
-
gem 'syntax_tree'
13
+
gem "syntax_tree"
14
14
```
15
15
16
16
And then execute:
@@ -26,25 +26,29 @@ Or install it yourself as:
26
26
From code:
27
27
28
28
```ruby
29
-
require'syntax_tree'
29
+
require"syntax_tree"
30
30
31
-
parser =SyntaxTree.new(source)
32
-
33
-
node = parser.parse
34
-
raiseif parser.error?
35
-
36
-
pp node
31
+
pp SyntaxTree.parse(source) # print out the AST
32
+
putsSyntaxTree.format(source) # format the AST
37
33
```
38
34
39
35
From the CLI:
40
36
41
37
```sh
42
-
$ stree program.rb
38
+
$ stree ast program.rb
43
39
(program
44
40
(statements
45
41
...
46
42
```
47
43
44
+
or
45
+
46
+
```sh
47
+
$ stree format program.rb
48
+
class MyClass
49
+
...
50
+
```
51
+
48
52
## Development
49
53
50
54
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console`for an interactive prompt that will allow you to experiment.
0 commit comments