diff --git a/lib/pgFormatter/Beautify.pm b/lib/pgFormatter/Beautify.pm index 4a636f3..d5f5a6b 100755 --- a/lib/pgFormatter/Beautify.pm +++ b/lib/pgFormatter/Beautify.pm @@ -4751,7 +4751,12 @@ sub _add_token { { if ( $token !~ /^['"].*['"]$/ or $last_token ne ':' ) { if ( $token =~ /AAKEYWCONST\d+AA\s+AAKEYWCONST\d+AA/ ) { - $token =~ s/(AAKEYWCONST\d+AA)/$sp$1/gs; + # Rebuild the separators, the tokenizer kept them verbatim + my $nl_sp = $self->{'space'} x + ( $self->{'spaces'} * ( $self->{'_level'} // 0 ) ); + $token =~ s/[ \t]+(AAKEYWCONST\d+AA)/ $1/gs; + $token =~ s/ ?\n ?(AAKEYWCONST\d+AA)/\n$nl_sp$1/gs; + $token =~ s/^(AAKEYWCONST\d+AA)/$sp$1/s; } else { $self->{'content'} .= $sp diff --git a/t/test-files/ex85.sql b/t/test-files/ex85.sql index 73f82ae..dc1be03 100644 --- a/t/test-files/ex85.sql +++ b/t/test-files/ex85.sql @@ -1,3 +1,20 @@ +SELECT 'a' +'b' AS lit +FROM t; + +SELECT concat('CLOTURE AVGLI PROP LOCATAIRE ' , l.imme_no , ' AU ' +'2024-12-31') AS libelle +FROM locataires l; + +SELECT 'one' +'two' +'three' AS parts +FROM t; + +SELECT * +FROM t +WHERE t.code = 'pre' +'fix'; INSERT INTO labo.peri_budgets WITH bud AS -- CBT selection des soldes des budgets ( diff --git a/t/test-files/expected/ex85.sql b/t/test-files/expected/ex85.sql index e69ca80..2de29f1 100644 --- a/t/test-files/expected/ex85.sql +++ b/t/test-files/expected/ex85.sql @@ -1,3 +1,29 @@ +SELECT + 'a' + 'b' AS lit +FROM + t; + +SELECT + concat('CLOTURE AVGLI PROP LOCATAIRE ', l.imme_no, ' AU ' + '2024-12-31') AS libelle +FROM + locataires l; + +SELECT + 'one' + 'two' + 'three' AS parts +FROM + t; + +SELECT + * +FROM + t +WHERE + t.code = 'pre' + 'fix'; INSERT INTO labo.peri_budgets WITH bud AS -- CBT selection des soldes des budgets (