@@ -2131,13 +2131,18 @@ def ===(other)
21312131 end
21322132 end
21332133
2134- # BlockVar represents the parameters being declared for a block. Effectively
2135- # this node is everything contained within the pipes. This includes all of the
2136- # various parameter types, as well as block-local variable declarations.
2134+ # BlockVar represents the parameters being declared for a block or lambda.
2135+ # This includes all of the various parameter types, as well as
2136+ # block-local/lambda -local variable declarations.
21372137 #
21382138 # method do |positional, optional = value, keyword:, █ local|
21392139 # end
21402140 #
2141+ # OR
2142+ #
2143+ # -> (positional, optional = value, keyword:, █ local) do
2144+ # end
2145+ #
21412146 class BlockVar < Node
21422147 # [Params] the parameters being declared with the block
21432148 attr_reader :params
@@ -2148,10 +2153,15 @@ class BlockVar < Node
21482153 # [Array[ Comment | EmbDoc ]] the comments attached to this node
21492154 attr_reader :comments
21502155
2151- def initialize ( params :, locals :, location :)
2156+ # [boolean] whether or not the variables are within pipes
2157+ attr_reader :pipe
2158+ alias pipe? pipe
2159+
2160+ def initialize ( params :, locals :, location :, pipe :)
21522161 @params = params
21532162 @locals = locals
21542163 @location = location
2164+ @pipe = pipe
21552165 @comments = [ ]
21562166 end
21572167
@@ -2163,12 +2173,13 @@ def child_nodes
21632173 [ params , *locals ]
21642174 end
21652175
2166- def copy ( params : nil , locals : nil , location : nil )
2176+ def copy ( params : nil , locals : nil , location : nil , pipe : nil )
21672177 node =
21682178 BlockVar . new (
21692179 params : params || self . params ,
21702180 locals : locals || self . locals ,
2171- location : location || self . location
2181+ location : location || self . location ,
2182+ pipe : pipe || self . pipe
21722183 )
21732184
21742185 node . comments . concat ( comments . map ( &:copy ) )
@@ -2178,7 +2189,13 @@ def copy(params: nil, locals: nil, location: nil)
21782189 alias deconstruct child_nodes
21792190
21802191 def deconstruct_keys ( _keys )
2181- { params : params , locals : locals , location : location , comments : comments }
2192+ {
2193+ params : params ,
2194+ locals : locals ,
2195+ location : location ,
2196+ comments : comments ,
2197+ pipe : pipe
2198+ }
21822199 end
21832200
21842201 # Within the pipes of the block declaration, we don't want any spaces. So
@@ -2194,23 +2211,23 @@ def call(q)
21942211 SEPARATOR = Separator . new . freeze
21952212
21962213 def format ( q )
2197- q . text ( "|" )
2198- q . group do
2199- q . remove_breaks ( q . format ( params ) )
2214+ pipe? ? q . remove_breaks ( q . format ( params ) ) : q . format ( params )
22002215
2201- if locals . any?
2202- q . text ( "; " )
2203- q . seplist ( locals , SEPARATOR ) { |local | q . format ( local ) }
2204- end
2216+ if locals . any?
2217+ q . text ( "; " )
2218+ q . seplist ( locals , SEPARATOR ) { |local | q . format ( local ) }
22052219 end
2206- q . text ( "|" )
22072220 end
22082221
22092222 def ===( other )
22102223 other . is_a? ( BlockVar ) && params === other . params &&
22112224 ArrayMatch . call ( locals , other . locals )
22122225 end
22132226
2227+ def empty?
2228+ params . empty? && locals . empty?
2229+ end
2230+
22142231 # When a single required parameter is declared for a block, it gets
22152232 # automatically expanded if the values being yielded into it are an array.
22162233 def arg0?
@@ -4486,8 +4503,9 @@ def format_break(q, break_opening, break_closing)
44864503 q . format ( BlockOpenFormatter . new ( break_opening , opening ) , stackable : false )
44874504
44884505 if block_var
4489- q . text ( " " )
4490- q . format ( block_var )
4506+ q . text ( " |" )
4507+ q . group { q . format ( block_var ) }
4508+ q . text ( "|" )
44914509 end
44924510
44934511 unless bodystmt . empty?
@@ -4507,7 +4525,9 @@ def format_flat(q, flat_opening, flat_closing)
45074525
45084526 if block_var
45094527 q . breakable_space
4510- q . format ( block_var )
4528+ q . text ( "|" )
4529+ q . group { q . format ( block_var ) }
4530+ q . text ( "|" )
45114531 q . breakable_space
45124532 end
45134533
@@ -7140,7 +7160,7 @@ def ===(other)
71407160 # ->(value) { value * 2 }
71417161 #
71427162 class Lambda < Node
7143- # [LambdaVar | Paren] the parameter declaration for this lambda
7163+ # [BlockVar | Paren] the parameter declaration for this lambda
71447164 attr_reader :params
71457165
71467166 # [BodyStmt | Statements] the expressions to be executed in this lambda
@@ -7258,76 +7278,6 @@ def ===(other)
72587278 end
72597279 end
72607280
7261- # LambdaVar represents the parameters being declared for a lambda. Effectively
7262- # this node is everything contained within the parentheses. This includes all
7263- # of the various parameter types, as well as block-local variable
7264- # declarations.
7265- #
7266- # -> (positional, optional = value, keyword:, █ local) do
7267- # end
7268- #
7269- class LambdaVar < Node
7270- # [Params] the parameters being declared with the block
7271- attr_reader :params
7272-
7273- # [Array[ Ident ]] the list of block-local variable declarations
7274- attr_reader :locals
7275-
7276- # [Array[ Comment | EmbDoc ]] the comments attached to this node
7277- attr_reader :comments
7278-
7279- def initialize ( params :, locals :, location :)
7280- @params = params
7281- @locals = locals
7282- @location = location
7283- @comments = [ ]
7284- end
7285-
7286- def accept ( visitor )
7287- visitor . visit_lambda_var ( self )
7288- end
7289-
7290- def child_nodes
7291- [ params , *locals ]
7292- end
7293-
7294- def copy ( params : nil , locals : nil , location : nil )
7295- node =
7296- LambdaVar . new (
7297- params : params || self . params ,
7298- locals : locals || self . locals ,
7299- location : location || self . location
7300- )
7301-
7302- node . comments . concat ( comments . map ( &:copy ) )
7303- node
7304- end
7305-
7306- alias deconstruct child_nodes
7307-
7308- def deconstruct_keys ( _keys )
7309- { params : params , locals : locals , location : location , comments : comments }
7310- end
7311-
7312- def empty?
7313- params . empty? && locals . empty?
7314- end
7315-
7316- def format ( q )
7317- q . format ( params )
7318-
7319- if locals . any?
7320- q . text ( "; " )
7321- q . seplist ( locals , BlockVar ::SEPARATOR ) { |local | q . format ( local ) }
7322- end
7323- end
7324-
7325- def ===( other )
7326- other . is_a? ( LambdaVar ) && params === other . params &&
7327- ArrayMatch . call ( locals , other . locals )
7328- end
7329- end
7330-
73317281 # LBrace represents the use of a left brace, i.e., {.
73327282 class LBrace < Node
73337283 # [String] the left brace
0 commit comments