From: Arthur Axel "fREW" Schmidt Date: Mon, 6 Sep 2010 23:26:04 +0000 (+0000) Subject: add more keywords, colors, and indentation rules X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7853a1772fcb52f9292653a566d599d4fa60a2a3;p=scpubgit%2FQ-Branch.git add more keywords, colors, and indentation rules --- diff --git a/lib/SQL/Abstract/Test.pm b/lib/SQL/Abstract/Test.pm index c511eee..3484dde 100644 --- a/lib/SQL/Abstract/Test.pm +++ b/lib/SQL/Abstract/Test.pm @@ -257,6 +257,7 @@ sub _parenthesis_unroll { } +sub parse { $sqlat->parse(@_) } 1; diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 0110fc5..10b0455 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -24,7 +24,10 @@ use constant PARSE_RHS => 3; # anchored to word boundaries to match the whole token). my @expression_terminator_sql_keywords = ( 'SELECT', - 'FROM', + 'UPDATE', + 'INSERT \s+ INTO', + 'DELETE \s+ FROM', + 'SET', '(?: (?: (?: \b (?: LEFT | RIGHT | FULL ) \s+ )? @@ -34,6 +37,7 @@ my @expression_terminator_sql_keywords = ( )', 'ON', 'WHERE', + 'VALUES', 'EXISTS', 'GROUP \s+ BY', 'HAVING', @@ -79,13 +83,19 @@ my $tokenizer_re = qr/ \s* ( $tokenizer_re_str | \( | \) | \? ) \s* /xi; sub _binary_op_keywords { @binary_op_keywords } my %indents = ( - select => 0, - where => 1, - from => 1, - join => 1, - on => 2, - 'group by' => 1, - 'order by' => 1, + select => 0, + update => 0, + 'insert into' => 0, + 'delete from' => 0, + where => 1, + join => 1, + 'left join' => 1, + on => 2, + 'group by' => 1, + 'order by' => 1, + set => 1, + into => 1, + values => 2, ); my %profiles = ( @@ -108,12 +118,19 @@ my %profiles = ( indent_amount => 2, newline => "
\n", colormap => { - select => ['' , ''], - where => ['' , ''], - from => ['' , ''], - join => ['' , ''], - on => ['' , ''], - 'group by' => ['', ''], + select => ['' , ''], + 'insert into' => ['' , ''], + update => ['' , ''], + 'delete from' => ['' , ''], + where => ['' , ''], + from => ['' , ''], + join => ['' , ''], + on => ['' , ''], + 'group by' => ['', ''], + 'order by' => ['', ''], + set => ['', ''], + into => ['', ''], + values => ['', ''], }, indentmap => { %indents }, }, @@ -126,13 +143,22 @@ my %profiles = ( eval { require Term::ANSIColor; $profiles{console}->{colormap} = { - select => [Term::ANSIColor::color('red'), Term::ANSIColor::color('reset')], - where => [Term::ANSIColor::color('green'), Term::ANSIColor::color('reset')], - from => [Term::ANSIColor::color('cyan'), Term::ANSIColor::color('reset')], - join => [Term::ANSIColor::color('magenta'), Term::ANSIColor::color('reset')], - on => [Term::ANSIColor::color('blue'), Term::ANSIColor::color('reset')], - 'group by' => [Term::ANSIColor::color('cyan'), Term::ANSIColor::color('reset')], - 'order by' => [Term::ANSIColor::color('yellow'), Term::ANSIColor::color('reset')], + select => [Term::ANSIColor::color('red'), Term::ANSIColor::color('reset')], + 'insert into' => [Term::ANSIColor::color('red'), Term::ANSIColor::color('reset')], + update => [Term::ANSIColor::color('red'), Term::ANSIColor::color('reset')], + 'delete from' => [Term::ANSIColor::color('red'), Term::ANSIColor::color('reset')], + + set => [Term::ANSIColor::color('cyan'), Term::ANSIColor::color('reset')], + + where => [Term::ANSIColor::color('green'), Term::ANSIColor::color('reset')], + values => [Term::ANSIColor::color('yellow'), Term::ANSIColor::color('reset')], + + join => [Term::ANSIColor::color('magenta'), Term::ANSIColor::color('reset')], + 'left join' => [Term::ANSIColor::color('magenta'), Term::ANSIColor::color('reset')], + on => [Term::ANSIColor::color('blue'), Term::ANSIColor::color('reset')], + + 'group by' => [Term::ANSIColor::color('yellow'), Term::ANSIColor::color('reset')], + 'order by' => [Term::ANSIColor::color('yellow'), Term::ANSIColor::color('reset')], }; };