-
Notifications
You must be signed in to change notification settings - Fork 26
change node inspect to output ruby (sexp)code that recreates the node #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -188,18 +188,21 @@ def to_a | |
| end | ||
|
|
||
| # Converts `self` to a pretty-printed s-expression. | ||
| # Using the Sexp module the output can be used as ruby code to | ||
| # generate the expressions (handy for tests) | ||
| # | ||
| # @param [Integer] indent Base indentation level. | ||
| # @return [String] | ||
| def to_sexp(indent=0) | ||
| indented = " " * indent | ||
| sexp = "#{indented}(#{fancy_type}" | ||
| sexp = "#{indented}s(:#{@type}" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Er. This is not at all what I described in #6 (comment). The convention in Ruby is for |
||
|
|
||
| first_node_child = children.index do |child| | ||
| child.is_a?(Node) || child.is_a?(Array) | ||
| end || children.count | ||
|
|
||
| children.each_with_index do |child, idx| | ||
| sexp << ", " | ||
| if child.is_a?(Node) && idx >= first_node_child | ||
| sexp << "\n#{child.to_sexp(indent + 1)}" | ||
| else | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obsolete comment