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
Copy file name to clipboardExpand all lines: README.md
+67Lines changed: 67 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -122,6 +122,73 @@ For a file that contains `1 + 1`, you will receive:
122
122
1+1
123
123
```
124
124
125
+
### json
126
+
127
+
This command will output a JSON representation of the syntax tree that is functionally equivalent to the input. This is mostly used in contexts where you need to access the tree from JavaScript or serialize it over a network.
128
+
129
+
```sh
130
+
stree json path/to/file.rb
131
+
```
132
+
133
+
For a file that contains `1 + 1`, you will receive:
134
+
135
+
```json
136
+
{
137
+
"type": "program",
138
+
"location": [1, 0, 1, 6],
139
+
"statements": {
140
+
"type": "statements",
141
+
"location": [1, 0, 1, 6],
142
+
"body": [
143
+
{
144
+
"type": "binary",
145
+
"location": [1, 0, 1, 5],
146
+
"left": {
147
+
"type": "int",
148
+
"location": [1, 0, 1, 1],
149
+
"value": "1",
150
+
"comments": []
151
+
},
152
+
"operator": "+",
153
+
"right": {
154
+
"type": "int",
155
+
"location": [1, 4, 1, 5],
156
+
"value": "1",
157
+
"comments": []
158
+
},
159
+
"comments": []
160
+
}
161
+
],
162
+
"comments": []
163
+
},
164
+
"comments": []
165
+
}
166
+
```
167
+
168
+
### match
169
+
170
+
This command will output a Ruby case-match expression that would match correctly against the input.
171
+
172
+
```sh
173
+
stree match path/to/file.rb
174
+
```
175
+
176
+
For a file that contains `1 + 1`, you will receive:
177
+
178
+
```ruby
179
+
SyntaxTree::Program[
180
+
statements:SyntaxTree::Statements[
181
+
body: [
182
+
SyntaxTree::Binary[
183
+
left:SyntaxTree::Int[value:"1"],
184
+
operator::+,
185
+
right:SyntaxTree::Int[value:"1"]
186
+
]
187
+
]
188
+
]
189
+
]
190
+
```
191
+
125
192
### write
126
193
127
194
This command will format the listed files and write that formatted version back to the source files. Note that this overwrites the original content, to be sure to be using a version control system.
0 commit comments