From: Peter Rabbitson Date: Tue, 4 Jun 2013 17:11:20 +0000 (+0200) Subject: Stop unknown token processing early in case a potential unknown function lies ahead X-Git-Tag: v1.74~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e2a120ce3ad02e0a555048e9ec97553e5c799416;p=dbsrgits%2FSQL-Abstract.git Stop unknown token processing early in case a potential unknown function lies ahead --- diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index c3e1555..5c887db 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -449,11 +449,18 @@ sub _recurse_parse { # we're now in "unknown token" land - start eating tokens until # we see something familiar, OR in the case of RHS (binop) stop # after the first token + # Also stop processing when we could end up with an unknown func else { my @lits = [ -LITERAL => [$token] ]; unless ( $state == PARSE_RHS ) { - while (@$tokens and $tokens->[0] !~ $all_std_keywords_re) { + while ( + @$tokens + and + $tokens->[0] !~ $all_std_keywords_re + and + ! ( @$tokens > 1 and $tokens->[1] eq '(' ) + ) { push @lits, [ -LITERAL => [ shift @$tokens ] ]; } } diff --git a/t/11parser.t b/t/11parser.t index 8e1ee05..8735ffe 100644 --- a/t/11parser.t +++ b/t/11parser.t @@ -800,7 +800,7 @@ is_deeply($sqlat->parse('SELECT foo FROM bar ORDER BY x + ? DESC, oomph, y - ? D ] ], 'Crazy ORDER BY parsed correctly'); -is_deeply( $sqlat->parse("META SELECT * * FROM (SELECT *, FROM foobar baz buzz) foo bar WHERE NOT NOT NOT EXISTS (SELECT 'cr,ap') AND foo.a = ? STUFF and not (foo.b LIKE 'station') and x = y and a = b and GROUP BY , ORDER BY x x1 x2 y asc, max(y) desc x z desc"), [ +is_deeply( $sqlat->parse("META SELECT * * FROM (SELECT *, FROM foobar baz buzz) foo bar WHERE NOT NOT NOT EXISTS (SELECT 'cr,ap') AND foo.a = ? STUFF moar(stuff) and not (foo.b LIKE 'station') and x = y and a = b and GROUP BY , ORDER BY x x1 x2 y asc, max(y) desc x z desc"), [ [ "-LITERAL", [ @@ -972,6 +972,22 @@ is_deeply( $sqlat->parse("META SELECT * * FROM (SELECT *, FROM foobar baz buzz) ] ] ], + ], + [ + 'moar', + [ + [ + '-PAREN', + [ + [ + '-LITERAL', + [ + 'stuff' + ] + ] + ] + ] + ] ] ] ],