Class: SyntaxTree::MatchVisitor
- Inherits:
-
FieldVisitor
- Object
- BasicVisitor
- FieldVisitor
- SyntaxTree::MatchVisitor
- Defined in:
- lib/syntax_tree/match_visitor.rb
Overview
This visitor transforms the AST into a Ruby pattern matching expression that would match correctly against the AST.
Instance Attribute Summary collapse
-
#q ⇒ Object
readonly
Returns the value of attribute q.
Instance Method Summary collapse
-
#initialize(q) ⇒ MatchVisitor
constructor
A new instance of MatchVisitor.
- #visit(node) ⇒ Object
Methods inherited from BasicVisitor
valid_visit_methods, #visit_all, #visit_child_nodes, visit_method, visit_methods
Constructor Details
#initialize(q) ⇒ MatchVisitor
Returns a new instance of MatchVisitor.
9 10 11 |
# File 'lib/syntax_tree/match_visitor.rb', line 9 def initialize(q) @q = q end |
Instance Attribute Details
#q ⇒ Object (readonly)
Returns the value of attribute q.
7 8 9 |
# File 'lib/syntax_tree/match_visitor.rb', line 7 def q @q end |
Instance Method Details
#visit(node) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/syntax_tree/match_visitor.rb', line 13 def visit(node) case node when Node super when String # pp will split up a string on newlines and concat them together using a # "+" operator. This breaks the pattern matching expression. So instead # we're going to check here for strings and manually put the entire # value into the output buffer. q.text(node.inspect) else node.pretty_print(q) end end |