Skip to content

Add support for parsing Ruby code

Stan Hu requested to merge sh-parse-ruby-code into main

This adds a tree_dfs method to walk the tree-sitter graph with a pre-order tree traversal. It's easier to debug the output of the cursor this way, as the existing tree_bfs can be confusing when parsing a Ruby syntax tree.

tree_bfs also appears to bail out early for Ruby classes inside a module with the default max_depth of 0.

Since all nodes are visited, the number of comments and function definitions have increased, and the tests need to reflect that.

This commit only updates the new CodeParser in treesitter.py since Ruby has some specific logic that is easier implemented in the refactored CodeParser. #232 (closed) is an open issue to switch to this new CodeParser.

Closes #178 (closed)

Edited by Alexander Chueshev

Merge request reports