VCall < Node def accept(visitor) visitor.visit_vcall(self) end end class Visitor def visit(node) node&.accept(self) end def visit_child_nodes(node) node.child_nodes.map do |node| visit(node) end end end
VCall < Node def accept(visitor) visitor.visit_vcall(self) end end # Visit an ARef node. alias visit_aref visit_child_nodes # Visit an ARefField node. alias visit_aref_field visit_child_nodes # Visit an Alias node. alias visit_alias visit_child_nodes # Visit an ArgBlock node. alias visit_arg_block visit_child_nodes # Visit an ArgParen node. alias visit_arg_paren visit_child_nodes # Visit an ArgStar node. alias visit_arg_star visit_child_nodes # Visit an Args node. alias visit_args visit_child_nodes # Visit an ArgsForward node. alias visit_args_forward visit_child_nodes # Visit an ArrayLiteral node. alias visit_array visit_child_nodes # Visit an AryPtn node. alias visit_aryptn visit_child_nodes # Visit an Assign node. alias visit_assign visit_child_nodes # Visit an Assoc node. alias visit_assoc visit_child_nodes # Visit an AssocSplat node. alias visit_assoc_splat visit_child_nodes # Visit a Backref node. alias visit_backref visit_child_nodes class Visitor def visit(node) node&.accept(self) end def visit_child_nodes(node) node.child_nodes.map do |node| visit(node) end end end
VCall < Node def accept(visitor) visitor.visit_vcall(self) end end alias visit_vcall visit_child_nodes # Visit a VoidStmt node. alias visit_void_stmt visit_child_nodes # Visit a When node. alias visit_when visit_child_nodes # Visit a While node. alias visit_while visit_child_nodes # Visit a WhileMod node. alias visit_while_mod visit_child_nodes # Visit a Word node. alias visit_word visit_child_nodes # Visit a Words node. alias visit_words visit_child_nodes # Visit a WordsBeg node. alias visit_words_beg visit_child_nodes # Visit a XString node. alias visit_xstring visit_child_nodes # Visit a XStringLiteral node. alias visit_xstring_literal visit_child_nodes # Visit a Yield node. alias visit_yield visit_child_nodes # Visit a Yield0 node. alias visit_yield0 visit_child_nodes # Visit a ZSuper node. alias visit_zsuper visit_child_nodes # Visit an EndContent node. alias visit___end__ visit_child_nodes class Visitor def visit(node) node&.accept(self) end def visit_child_nodes(node) node.child_nodes.map do |node| visit(node) end end end
RegexpVisitor < Visitor def visit_regexp_literal(node) # do something with regexp literal node here node.options # call super to continue walking the tree super end end
JSONVisitor < Visitor def visit_aref(node) node(node, "aref") do field("collection", node.collection) field("index", node.index) comments(node) end end def visit_aref_field(node) node(node, "aref_field") do field("collection", node.collection) field("index", node.index) comments(node) end end def visit_alias(node) node(node, "alias") do field("left", node.left) field("right", node.right) comments(node) end end
If < Node def format(q) if node.consequent || node.statements.empty? q.group { format_break(q, force: true) } else q.group do q .if_break { format_break(q, force: false) } .if_flat do Parentheses.flat(q) do q.format(node.statements) q.text(" if ") q.format(node.predicate) end end end end end end
If < Node def format(q) if node.consequent || node.statements.empty? q.group { format_break(q, force: true) } else q.group do q .if_break { format_break(q, force: false) } .if_flat do Parentheses.flat(q) do q.format(node.statements) q.text(" if ") q.format(node.predicate) end end end end end end
ast [OPTIONS] [FILE] Print out the AST corresponding to the given files stree check [OPTIONS] [FILE] Check that the given files are formatted as syntax tree would format them stree debug [OPTIONS] [FILE] Check that the given files can be formatted idempotently stree doc [OPTIONS] [FILE] Print out the doc tree that would be used to format the given files stree format [OPTIONS] [FILE] Print out the formatted version of the given files stree json [OPTIONS] [FILE] Print out the JSON representation of the given files stree match [OPTIONS] [FILE] Print out a pattern-matching Ruby expression that would match the given files stree help Display this help message stree lsp Run syntax tree in language server mode stree version Output the current version of syntax tree stree write [OPTIONS] [FILE] Read, format, and write back the source of the given files
ast [OPTIONS] [FILE] Print out the AST corresponding to the given files stree check [OPTIONS] [FILE] Check that the given files are formatted as syntax tree would format them stree debug [OPTIONS] [FILE] Check that the given files can be formatted idempotently stree doc [OPTIONS] [FILE] Print out the doc tree that would be used to format the given files stree format [OPTIONS] [FILE] Print out the formatted version of the given files stree json [OPTIONS] [FILE] Print out the JSON representation of the given files stree match [OPTIONS] [FILE] Print out a pattern-matching Ruby expression that would match the given files stree help Display this help message stree lsp Run syntax tree in language server mode stree version Output the current version of syntax tree stree write [OPTIONS] [FILE] Read, format, and write back the source of the given files
ast [OPTIONS] [FILE] Print out the AST corresponding to the given files stree check [OPTIONS] [FILE] Check that the given files are formatted as syntax tree would format them stree debug [OPTIONS] [FILE] Check that the given files can be formatted idempotently stree doc [OPTIONS] [FILE] Print out the doc tree that would be used to format the given files stree format [OPTIONS] [FILE] Print out the formatted version of the given files stree json [OPTIONS] [FILE] Print out the JSON representation of the given files stree match [OPTIONS] [FILE] Print out a pattern-matching Ruby expression that would match the given files stree help Display this help message stree lsp Run syntax tree in language server mode stree version Output the current version of syntax tree stree write [OPTIONS] [FILE] Read, format, and write back the source of the given files
ast [OPTIONS] [FILE] Print out the AST corresponding to the given files stree check [OPTIONS] [FILE] Check that the given files are formatted as syntax tree would format them stree debug [OPTIONS] [FILE] Check that the given files can be formatted idempotently stree doc [OPTIONS] [FILE] Print out the doc tree that would be used to format the given files stree format [OPTIONS] [FILE] Print out the formatted version of the given files stree json [OPTIONS] [FILE] Print out the JSON representation of the given files stree match [OPTIONS] [FILE] Print out a pattern-matching Ruby expression that would match the given files stree help Display this help message stree lsp Run syntax tree in language server mode stree version Output the current version of syntax tree stree write [OPTIONS] [FILE] Read, format, and write back the source of the given files
ast [OPTIONS] [FILE] Print out the AST corresponding to the given files stree check [OPTIONS] [FILE] Check that the given files are formatted as syntax tree would format them stree debug [OPTIONS] [FILE] Check that the given files can be formatted idempotently stree doc [OPTIONS] [FILE] Print out the doc tree that would be used to format the given files stree format [OPTIONS] [FILE] Print out the formatted version of the given files stree json [OPTIONS] [FILE] Print out the JSON representation of the given files stree match [OPTIONS] [FILE] Print out a pattern-matching Ruby expression that would match the given files stree help Display this help message stree lsp Run syntax tree in language server mode stree version Output the current version of syntax tree stree write [OPTIONS] [FILE] Read, format, and write back the source of the given files
ast [OPTIONS] [FILE] Print out the AST corresponding to the given files stree check [OPTIONS] [FILE] Check that the given files are formatted as syntax tree would format them stree debug [OPTIONS] [FILE] Check that the given files can be formatted idempotently stree doc [OPTIONS] [FILE] Print out the doc tree that would be used to format the given files stree format [OPTIONS] [FILE] Print out the formatted version of the given files stree json [OPTIONS] [FILE] Print out the JSON representation of the given files stree match [OPTIONS] [FILE] Print out a pattern-matching Ruby expression that would match the given files stree help Display this help message stree lsp Run syntax tree in language server mode stree version Output the current version of syntax tree stree write [OPTIONS] [FILE] Read, format, and write back the source of the given files
ast [OPTIONS] [FILE] Print out the AST corresponding to the given files stree check [OPTIONS] [FILE] Check that the given files are formatted as syntax tree would format them stree debug [OPTIONS] [FILE] Check that the given files can be formatted idempotently stree doc [OPTIONS] [FILE] Print out the doc tree that would be used to format the given files stree format [OPTIONS] [FILE] Print out the formatted version of the given files stree json [OPTIONS] [FILE] Print out the JSON representation of the given files stree match [OPTIONS] [FILE] Print out a pattern-matching Ruby expression that would match the given files stree help Display this help message stree lsp Run syntax tree in language server mode stree version Output the current version of syntax tree stree write [OPTIONS] [FILE] Read, format, and write back the source of the given files