@@ -612,7 +612,7 @@ def on_END(statements)
612
612
# some other content that is not executed by the program
613
613
#
614
614
class EndContent
615
- # [String] the content after the script
615
+ # [Array[ String ] ] the content after the script
616
616
attr_reader :value
617
617
618
618
# [Location] the location of this node
@@ -634,24 +634,26 @@ def child_nodes
634
634
def format ( q )
635
635
q . text ( "__END__" )
636
636
q . breakable ( force : true )
637
- q . text ( value )
637
+
638
+ q . seplist ( value , -> { q . breakable ( literal : true , force : true ) } ) do |line |
639
+ q . text ( line )
640
+ end
638
641
end
639
642
640
643
def pretty_print ( q )
641
644
q . group ( 2 , "(" , ")" ) do
642
645
q . text ( "__end__" )
643
646
644
647
q . breakable
645
- q . pp ( value )
648
+ q . pp ( value . join ( " \n " ) )
646
649
647
650
q . pp ( Comment ::List . new ( comments ) )
648
651
end
649
652
end
650
653
651
654
def to_json ( *opts )
652
- { type : :__end__ , value : value , loc : location , cmts : comments } . to_json (
653
- *opts
654
- )
655
+ { type : :__end__ , value : value . join ( "\n " ) , loc : location , cmts : comments }
656
+ . to_json ( *opts )
655
657
end
656
658
end
657
659
@@ -660,7 +662,7 @@ def to_json(*opts)
660
662
def on___end__ ( value )
661
663
@__end__ =
662
664
EndContent . new (
663
- value : lines [ lineno ..-1 ] . join ( " \n " ) ,
665
+ value : lines [ lineno ..-1 ] ,
664
666
location : Location . token ( line : lineno , char : char_pos , size : value . size )
665
667
)
666
668
end
@@ -9042,7 +9044,11 @@ def child_nodes
9042
9044
9043
9045
def format ( q )
9044
9046
q . format ( statements )
9045
- q . breakable ( force : true )
9047
+
9048
+ # We're going to put a newline on the end so that it always has one unless
9049
+ # it ends with the special __END__ syntax. In that case we want to
9050
+ # replicate the text exactly so we will just let it be.
9051
+ q . breakable ( force : true ) unless statements . body . last . is_a? ( EndContent )
9046
9052
end
9047
9053
9048
9054
def pretty_print ( q )
0 commit comments