Skip to content

Commit 0acd285

Browse files
committed
Add detailed comment about NestingParse internal
1 parent a10f35b commit 0acd285

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎lib/irb/nesting_parser.rb‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ module NestingParser
88

99
class NestingVisitor < Prism::Visitor
1010
def initialize
11+
# Array of [column, priority(+1/-1), NestingElem(open) or nil(close)] per line.
12+
# priority is +1 for open, -1 for close so that close comes before open when sorted.
13+
# Example:
14+
# if cond
15+
# else
16+
# end
17+
# `else` closes `if` at column 0 first and then opens `else` at column 0 next.
1118
@lines = []
19+
20+
# Array of open heredoc NestingElem per line
1221
@heredocs = []
1322
end
1423

@@ -43,6 +52,8 @@ def close(line, column)
4352
(@lines[line - 1] ||= []) << [column, -1]
4453
end
4554

55+
# Checks if a node (if, while, etc) is a modifier form that does not need `end` closing.
56+
# modifier node: `a if b`, non-modifier node: `if a; b; end`
4657
def modifier_node?(node, keyword_loc)
4758
!(keyword_loc && node.location.start_line == keyword_loc.start_line && node.location.start_column == keyword_loc.start_column)
4859
end

0 commit comments

Comments
 (0)