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
@@ -129,6 +131,24 @@ To change the print width that you are checking against, specify the `--print-wi
129
131
stree check --print-width=100 path/to/file.rb
130
132
```
131
133
134
+
### expr
135
+
136
+
This command will output a Ruby case-match expression that would match correctly against the first expression of the input.
137
+
138
+
```sh
139
+
stree expr path/to/file.rb
140
+
```
141
+
142
+
For a file that contains `1 + 1`, you will receive:
143
+
144
+
```ruby
145
+
SyntaxTree::Binary[
146
+
left:SyntaxTree::Int[value:"1"],
147
+
operator::+,
148
+
right:SyntaxTree::Int[value:"1"]
149
+
]
150
+
```
151
+
132
152
### format
133
153
134
154
This command will output the formatted version of each of the listed files. Importantly, it will not write that content back to the source files. It is meant to display the formatted version only.
@@ -312,6 +332,10 @@ This function takes an input string containing Ruby code and returns the syntax
312
332
313
333
This function takes an input string containing Ruby code, parses it into its underlying syntax tree, and formats it back out to a string. You can optionally pass a second argument to this method as well that is the maximum width to print. It defaults to `80`.
314
334
335
+
### SyntaxTree.search(source, query, &block)
336
+
337
+
This function takes an input string containing Ruby code, an input string containing a valid Ruby `in` clause expression that can be used to match against nodes in the tree (can be generated using `stree expr`, `stree match`, or `Node#construct_keys`), and a block. Each node that matches the given query will be yielded to the block. The block will receive the node as its only argument.
338
+
315
339
## Nodes
316
340
317
341
There are many different node types in the syntax tree. They are meant to be treated as immutable structs containing links to child nodes with minimal logic contained within their implementation. However, for the most part they all respond to a certain set of APIs, listed below.
0 commit comments