@@ -606,12 +606,14 @@ def format(q)
606
606
private
607
607
608
608
def trailing_comma?
609
- case arguments
610
- in Args [ parts : [ *, ArgBlock ] ]
609
+ return false unless arguments . is_a? ( Args )
610
+ parts = arguments . parts
611
+
612
+ if parts . last &.is_a? ( ArgBlock )
611
613
# If the last argument is a block, then we can't put a trailing comma
612
614
# after it without resulting in a syntax error.
613
615
false
614
- in Args [ parts : [ Command | CommandCall ] ]
616
+ elsif parts . length == 1 && ( part = parts . first ) && ( part . is_a? ( Command ) || part . is_a? ( CommandCall ) )
615
617
# If the only argument is a command or command call, then a trailing
616
618
# comma would be parsed as part of that expression instead of on this
617
619
# one, so we don't want to add a trailing comma.
@@ -1668,13 +1670,11 @@ def format(q)
1668
1670
q . text ( " " ) unless power
1669
1671
1670
1672
if operator == :<<
1671
- q . text ( operator . to_s )
1672
- q . text ( " " )
1673
+ q . text ( "<< " )
1673
1674
q . format ( right )
1674
1675
else
1675
1676
q . group do
1676
- q . text ( operator . to_s )
1677
-
1677
+ q . text ( operator . name )
1678
1678
q . indent do
1679
1679
power ? q . breakable_empty : q . breakable_space
1680
1680
q . format ( right )
@@ -1974,12 +1974,11 @@ def format(q)
1974
1974
# If the receiver of this block a Command or CommandCall node, then there
1975
1975
# are no parentheses around the arguments to that command, so we need to
1976
1976
# break the block.
1977
- case q . parent
1978
- in { call : Command | CommandCall }
1977
+ case q . parent . call
1978
+ when Command , CommandCall
1979
1979
q . break_parent
1980
1980
format_break ( q , break_opening , break_closing )
1981
1981
return
1982
- else
1983
1982
end
1984
1983
1985
1984
q . group do
@@ -1999,9 +1998,9 @@ def unchangeable_bounds?(q)
1999
1998
# know for certain we're going to get split over multiple lines
2000
1999
# anyway.
2001
2000
case parent
2002
- in Statements | ArgParen
2001
+ when Statements , ArgParen
2003
2002
break false
2004
- in Command | CommandCall
2003
+ when Command , CommandCall
2005
2004
true
2006
2005
else
2007
2006
false
@@ -2012,8 +2011,8 @@ def unchangeable_bounds?(q)
2012
2011
# If we're a sibling of a control-flow keyword, then we're going to have to
2013
2012
# use the do..end bounds.
2014
2013
def forced_do_end_bounds? ( q )
2015
- case q . parent
2016
- in { call : Break | Next | Return | Super }
2014
+ case q . parent . call
2015
+ when Break , Next , Return , Super
2017
2016
true
2018
2017
else
2019
2018
false
@@ -2997,15 +2996,31 @@ def format(q)
2997
2996
private
2998
2997
2999
2998
def align ( q , node , &block )
3000
- case node . arguments
3001
- in Args [ parts : [ Def | Defs | DefEndless ] ]
3002
- q . text ( " " )
3003
- yield
3004
- in Args [ parts : [ IfOp ] ]
3005
- q . if_flat { q . text ( " " ) }
3006
- yield
3007
- in Args [ parts : [ Command => command ] ]
3008
- align ( q , command , &block )
2999
+ arguments = node . arguments
3000
+
3001
+ if arguments . is_a? ( Args )
3002
+ parts = arguments . parts
3003
+
3004
+ if parts . size == 1
3005
+ part = parts . first
3006
+
3007
+ case part
3008
+ when Def , Defs , DefEndless
3009
+ q . text ( " " )
3010
+ yield
3011
+ when IfOp
3012
+ q . if_flat { q . text ( " " ) }
3013
+ yield
3014
+ when Command
3015
+ align ( q , part , &block )
3016
+ else
3017
+ q . text ( " " )
3018
+ q . nest ( message . value . length + 1 ) { yield }
3019
+ end
3020
+ else
3021
+ q . text ( " " )
3022
+ q . nest ( message . value . length + 1 ) { yield }
3023
+ end
3009
3024
else
3010
3025
q . text ( " " )
3011
3026
q . nest ( message . value . length + 1 ) { yield }
@@ -3092,13 +3107,16 @@ def format(q)
3092
3107
end
3093
3108
end
3094
3109
3095
- case arguments
3096
- in Args [ parts : [ IfOp ] ]
3097
- q . if_flat { q . text ( " " ) }
3098
- q . format ( arguments )
3099
- in Args
3100
- q . text ( " " )
3101
- q . nest ( argument_alignment ( q , doc ) ) { q . format ( arguments ) }
3110
+ if arguments
3111
+ parts = arguments . parts
3112
+
3113
+ if parts . length == 1 && parts . first . is_a? ( IfOp )
3114
+ q . if_flat { q . text ( " " ) }
3115
+ q . format ( arguments )
3116
+ else
3117
+ q . text ( " " )
3118
+ q . nest ( argument_alignment ( q , doc ) ) { q . format ( arguments ) }
3119
+ end
3102
3120
else
3103
3121
# If there are no arguments, print nothing.
3104
3122
end
@@ -5861,11 +5879,15 @@ class Kw < Node
5861
5879
# [String] the value of the keyword
5862
5880
attr_reader :value
5863
5881
5882
+ # [Symbol] the symbol version of the value
5883
+ attr_reader :name
5884
+
5864
5885
# [Array[ Comment | EmbDoc ]] the comments attached to this node
5865
5886
attr_reader :comments
5866
5887
5867
5888
def initialize ( value :, location :, comments : [ ] )
5868
5889
@value = value
5890
+ @name = value . to_sym
5869
5891
@location = location
5870
5892
@comments = comments
5871
5893
end
@@ -6645,11 +6667,15 @@ class Op < Node
6645
6667
# [String] the operator
6646
6668
attr_reader :value
6647
6669
6670
+ # [Symbol] the symbol version of the value
6671
+ attr_reader :name
6672
+
6648
6673
# [Array[ Comment | EmbDoc ]] the comments attached to this node
6649
6674
attr_reader :comments
6650
6675
6651
6676
def initialize ( value :, location :, comments : [ ] )
6652
6677
@value = value
6678
+ @name = value . to_sym
6653
6679
@location = location
6654
6680
@comments = comments
6655
6681
end
0 commit comments