[Bast-commits] r9670 -
SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract
frew at dev.catalyst.perl.org
frew at dev.catalyst.perl.org
Thu Sep 2 04:03:05 GMT 2010
Author: frew
Date: 2010-09-02 05:03:05 +0100 (Thu, 02 Sep 2010)
New Revision: 9670
Modified:
SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm
Log:
rearrange things, looks almost good
Modified: SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm
===================================================================
--- SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm 2010-09-02 03:08:36 UTC (rev 9669)
+++ SQL-Abstract/1.x/branches/sqla-tree/lib/SQL/Abstract/Tree.pm 2010-09-02 04:03:05 UTC (rev 9670)
@@ -183,12 +183,22 @@
return $keyword
}
+
+my %ghetto_whitespacemap = (
+ select => 0,
+ where => 1,
+ from => 1,
+);
+
sub whitespace {
my ($self, $keyword, $depth) = @_;
- if (lc $keyword eq 'from') {
- return ['', "\n"];
+
+ my $before = '';
+ my $after = '';
+ if (defined $ghetto_whitespacemap{lc $keyword}) {
+ $before = $self->newline . $self->indent($depth + $ghetto_whitespacemap{lc $keyword});
}
- return ['', ''];
+ return [$before, $after];
}
sub newline { "\n" }
@@ -198,7 +208,7 @@
sub unparse {
my ($self, $tree, $depth) = @_;
- $depth ||= 1;
+ $depth ||= 0;
if (not $tree ) {
return '';
@@ -208,23 +218,23 @@
my $cdr = $tree->[1];
if (ref $car) {
- return join (" ", map $self->unparse($_), @$tree);
+ return join ('', map $self->unparse($_, $depth), @$tree);
}
elsif ($car eq 'LITERAL') {
return $cdr->[0];
}
elsif ($car eq 'PAREN') {
- return '(' . $self->newline .
+ return '(' .
join(' ',
- map $self->indent($depth) . $self->unparse($_, $depth + 1), @{$cdr})
- . $self->newline . ')';
+ map $self->unparse($_, $depth + 1), @{$cdr})
+ . ')';
}
elsif ($car eq 'OR' or $car eq 'AND' or (grep { $car =~ /^ $_ $/xi } @binary_op_keywords ) ) {
- return join (" $car ", map $self->unparse($_), @{$cdr});
+ return join (" $car ", map $self->unparse($_, $depth), @{$cdr});
}
else {
my ($l, $r) = @{$self->whitespace($car, $depth)};
- return sprintf "%s %s$r", $self->format_keyword($car), $self->unparse($cdr);
+ return sprintf "$l%s %s$r", $self->format_keyword($car), $self->unparse($cdr, $depth);
}
}
More information about the Bast-commits
mailing list