Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8e2e0c8

Browse files
committed
Document the new visitors
1 parent 7bc0242 commit 8e2e0c8

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,73 @@ For a file that contains `1 + 1`, you will receive:
122122
1 + 1
123123
```
124124

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+
125192
### write
126193

127194
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

Comments
 (0)