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

Commit 6e0e53e

Browse files
authored
Merge pull request #43 from ruby-syntax-tree/pretty-print-visitor
Pretty print within a visitor
2 parents ce0cc1e + 2960034 commit 6e0e53e

File tree

8 files changed

+2596
-3471
lines changed

8 files changed

+2596
-3471
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ With visitors, you only define handlers for the nodes that you need. You can fin
249249
* call `visit(child)` with each child that you want to visit
250250
* call nothing if you're sure you don't want to descend further
251251

252+
There are a couple of visitors that ship with Syntax Tree that can be used as examples. They live in the [lib/syntax_tree/visitor](lib/syntax_tree/visitor) directory.
253+
252254
### visit_method
253255

254256
When you're creating a visitor, it's very easy to accidentally mistype a visit method. Unfortunately, there's no way to tell Ruby to explicitly override a parent method, so it would then be easy to define a method that never gets called. To mitigate this risk, there's `Visitor.visit_method(name)`. This method accepts a symbol that is checked against the list of known visit methods. If it's not in the list, then an error will be raised. It's meant to be used like:

lib/syntax_tree.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
require_relative "syntax_tree/parser"
1212
require_relative "syntax_tree/version"
1313
require_relative "syntax_tree/visitor"
14-
15-
require_relative "syntax_tree/json_visitor"
14+
require_relative "syntax_tree/visitor/json_visitor"
15+
require_relative "syntax_tree/visitor/pretty_print_visitor"
1616

1717
# If PrettyPrint::Align isn't defined, then we haven't gotten the updated
1818
# version of prettyprint. In that case we'll define our own. This is going to

0 commit comments

Comments
 (0)