summaryrefslogtreecommitdiff
path: root/lib/prism/parse_result
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2023-10-30 14:43:45 -0400
committerKevin Newton <[email protected]>2023-11-01 13:10:29 -0400
commit79034fbd503769ed2742003e31920733e9300909 ()
tree3d2ec4007a132ed4a36ca3c30da7f31c6e1dda90 /lib/prism/parse_result
parent953138698e4c2ba7a698ee133fbdc5d075556a5d (diff)
[ruby/prism] More Ruby docs
https://.com/ruby/prism/commit/ca9a660f52
-rw-r--r--lib/prism/parse_result/comments.rb9
-rw-r--r--lib/prism/parse_result/newlines.rb4
2 files changed, 11 insertions, 2 deletions
@@ -19,7 +19,7 @@ module Prism
class Comments
# A target for attaching comments that is based on a specific node's
# location.
- class NodeTarget
attr_reader :node
def initialize(node)
@@ -46,7 +46,7 @@ module Prism
# A target for attaching comments that is based on a location field on a
# node. For example, the `end` token of a ClassNode.
- class LocationTarget
attr_reader :location
def initialize(location)
@@ -70,12 +70,17 @@ module Prism
end
end
attr_reader :parse_result
def initialize(parse_result)
@parse_result = parse_result
end
def attach!
parse_result.comments.each do |comment|
preceding, enclosing, following = nearest_targets(parse_result.value, comment)
@@ -18,10 +18,12 @@ module Prism
# MarkNewlinesVisitor, since that visitor is responsible for marking the
# newlines for JRuby/TruffleRuby.
class Newlines < Visitor
def initialize(newline_marked)
@newline_marked = newline_marked
end
def visit_block_node(node)
old_newline_marked = @newline_marked
@newline_marked = Array.new(old_newline_marked.size, false)
@@ -35,6 +37,7 @@ module Prism
alias_method :visit_lambda_node, :visit_block_node
def visit_if_node(node)
node.set_newline_flag(@newline_marked)
super(node)
@@ -42,6 +45,7 @@ module Prism
alias_method :visit_unless_node, :visit_if_node
def visit_statements_node(node)
node.body.each do |child|
child.set_newline_flag(@newline_marked)