Commit graph

170 commits

Author SHA1 Message Date
Nickolay Ponomarev
7bbf69f513 Further simplify parse_compound_identifier (5/8)
This part changes behavior:
- Fail when no identifier is found.
- Avoid rewinding if EOF was hit right after the identifier.
2019-01-31 03:57:17 +03:00
Nickolay Ponomarev
991fd19b87 Stop nesting match in parse_compound_identifier (4/8) 2019-01-31 03:57:16 +03:00
Nickolay Ponomarev
8c3479969f Simplify by using expect_keyword / expect_token (3/8)
...instead of parse_keyword / consume_token - to reduce nesting of `if`s.

(Follow-up to PR #35)
2019-01-31 03:57:16 +03:00
Nickolay Ponomarev
f87230553e Remove dialect-specific keyword lists (2/8)
Now populating SQLWord.keyword based on the list of globally supported
keywords.
2019-01-31 03:57:16 +03:00
Nickolay Ponomarev
9a8b6a8e64 Rework keyword/identifier parsing (1/8)
Fold Token::{Keyword, Identifier, DoubleQuotedString} into one
Token::SQLWord, which has the necessary information (was it a
known keyword and/or was it quoted).

This lets the parser easily accept DoubleQuotedString (a quoted
identifier) everywhere it expects an Identifier in the same match
arm. (To complete support of quoted identifiers, or "delimited
identifiers" as the spec calls them, a TODO in parse_tablename()
ought to be addressed.)

    As an aside, per <https://en.wikibooks.org/wiki/SQL_Dialects_Reference/Data_structure_definition/Delimited_identifiers>
    sqlite seems to be the only one supporting 'identifier'
    (which is rather hairy, since it can also be a string
    literal), and `identifier` seems only to be supported by
    MySQL. I didn't implement either one.

This also allows the use of `parse`/`expect_keyword` machinery
for non-reserved keywords: previously they relied on the keyword
being a Token::Keyword, which wasn't a Token::Identifier, and so
wasn't accepted as one.

Now whether a keyword can be used as an identifier can be decided
by the parser. (I didn't add a blacklist of "reserved" keywords,
so that any keyword which doesn't have a special meaning in the
parser could be used as an identifier. The list of keywords in
the dialect could be re-used for that purpose at a later stage.)
2019-01-31 03:57:16 +03:00
Nickolay Ponomarev
eb4b5bc686 Stop returning Option from parse_infix
This reduces amount of boilerplate and avoids cloning the `expr` param.
2019-01-30 04:10:55 +03:00
Nickolay Ponomarev
d73a1e0e1d Join match arms for Keyword and binary ops
because they share implementation.
2019-01-30 04:10:55 +03:00
Nickolay Ponomarev
3de2a0952c Make SQLOrderByExpr::asc tri-state
i.e. ASC/DESC/unspecified - so that we don't lose information about
source code.

Also don't take any keyword other than ASC/DESC or Comma to mean
'ascending'.
2019-01-30 04:10:55 +03:00
Nickolay Ponomarev
12b9f5aafc Merge branches 'strings' and 'remove-duplicate-tests' 2019-01-20 19:30:36 +03:00
Nickolay Ponomarev
70c799e21d Use verified() in the remaining PG-specific tests 2019-01-20 19:30:13 +03:00
Nickolay Ponomarev
9441f9c5d8 Move tests for "LIKE '%'" to sqlparser_generic.rs
...as this syntax is not specific to the PostgreSQL dialect.

Also use verified() to assert that parsing + serializing results in the
original SQL string.
2019-01-20 19:30:12 +03:00
Nickolay Ponomarev
d5109a2880 Remove duplicate tests from sqlparser_postgres.rs
These have identical copies in sqlparser_generic.rs
2019-01-20 19:30:12 +03:00
Nickolay Ponomarev
078eb677a1 Remove Value::String
Its existence alongside SingleQuotedString simply doesn't make sense:
`'a string'` is a string literal, while `a string` is not a "value".

It's only used in postgresql-specific tab-separated-values parser to
store the string representation of a field's value. For that use-case
Option<String> looks like a more appropriate choice than Value.
2019-01-20 19:26:58 +03:00
Nickolay Ponomarev
56884dc700 Remove Value::DoubleQuotedString
...and parser support for the corresponding token, as "..." in SQL[*] is
not a literal string like we parse it - but a quoted identifier (which I
intend to implement later).

[*] in all the RBDMSes I know, except for sqlite which has complex rules
in the name of "compatibility": https://www.sqlite.org/lang_keywords.html
2019-01-20 19:26:58 +03:00
Nickolay Ponomarev
efdbf0f9dc Remove Token::Identifier match arm from parse_value
An identifier is not a literal value, and parse_value is not called on
such a token anyway.
2019-01-20 19:26:57 +03:00
Nickolay Ponomarev
d0a65ffd05 Remove Token::String, as it's never emitted
Indeed, given that there is Token::SingleQuotedString and
Token::Identifier, there's no other "string" that would make sense...
2019-01-20 19:26:57 +03:00
Nickolay Ponomarev
45dab0e2d4 Run all the 'generic' tests with the PostgreSqlDialect too. 2019-01-20 19:15:05 +03:00
Nickolay Ponomarev
a1da7b4005 Reduce differences between "generic" and "postgresql" tests
Mainly by replacing `assert_eq!(sql, ast.to_string())` with a call to
the recently introduced `verified()` helper or using `parses_to()` where
the expected serialization differs from the original SQL string.

There was one case (parse_implicit_join), where the inputs were different:
let sql = "SELECT * FROM t1,t2";
//vs
let sql = "SELECT * FROM t1, t2";

and since we don't test the whitespace handling in other tests, I just
used the canonical representation as input.
2019-01-20 19:14:53 +03:00
Andy Grove
82b1467324 (cargo-release) start next development iteration 0.2.2-alpha.0 2019-01-13 09:19:46 -07:00
Andy Grove
bde2e2d660 (cargo-release) version 0.2.1 2019-01-13 09:19:37 -07:00
Andy Grove
47e00af15b
Merge pull request #35 from nickolay/consume-token
Clean up consume_token() and parse/expect_keyword()
2019-01-13 09:16:13 -07:00
Nickolay Ponomarev
ae06dc7901 Return bool from consume_token(), mark as #[must_use] 2019-01-13 01:09:47 +03:00
Nickolay Ponomarev
fd9e2818d7 Introduce expect_token(), failing when the expected token was not found 2019-01-13 01:08:17 +03:00
Nickolay Ponomarev
b3ab4aca88 Use expect_keyword() instead of consume_token() where appropriate
Before this missing keywords THEN/WHEN/AS would be parsed as if they
were in the text as the code didn't check the return value of
consume_token() - see upcoming commit.
2019-01-13 01:07:58 +03:00
Nickolay Ponomarev
de4ccd3cb7 Fail when expected keyword is not found
Add #[must_use] to warn against unchecked results of parse_keyword/s in
the future.
2019-01-13 01:07:58 +03:00
Nickolay Ponomarev
89cfa9e599 Don't consume a second DoubleColon in parse_pg_cast
The function is invoked after a DoubleColon was already matched.
2019-01-13 01:07:58 +03:00
Nickolay Ponomarev
dce09f8054 Fix a mistake in merge conflict resolution earlier 2019-01-13 00:56:51 +03:00
Andy Grove
ac365bd44e (cargo-release) start next development iteration 0.2.1-alpha.0 2019-01-12 11:23:33 -07:00
Andy Grove
a987503b2c (cargo-release) version 0.2.0 2019-01-12 11:23:20 -07:00
Andy Grove
115c8e5595
Merge pull request #33 from andygrove/not
implement NOT
2019-01-12 11:19:59 -07:00
Andy Grove
c0cafb7308 specialized parser for DEFAULT expression in CREATE TABLE 2019-01-12 11:18:21 -07:00
Andy Grove
777fd4c2ee Merge branch 'master' into not 2019-01-12 11:14:07 -07:00
Andy Grove
a52b59e3ab Merge branch 'fredrikroos-join-support' 2019-01-12 11:11:28 -07:00
Andy Grove
f8c6fa96f4 fix regression 2019-01-12 11:11:18 -07:00
Andy Grove
8c351fe10a Merge branch 'join-support' of https://github.com/fredrikroos/sqlparser-rs into fredrikroos-join-support 2019-01-12 11:09:41 -07:00
Andy Grove
32d53a6b7e Update README 2019-01-12 10:00:00 -07:00
Andy Grove
7233a7e71f (cargo-release) start next development iteration 0.1.11-alpha.0 2019-01-12 09:30:19 -07:00
Andy Grove
81954bffb8 (cargo-release) version 0.1.10 2019-01-12 09:30:08 -07:00
Andy Grove
25718b8028
Merge pull request #34 from nickolay/misc
Miscellaneous fixes
2019-01-12 09:29:11 -07:00
Andy Grove
ab423bc9dc
Merge branch 'master' into join-support 2019-01-12 08:33:12 -07:00
Nickolay Ponomarev
3b13e153a8 Fix parse_time() handling of fractional seconds
There's no Token::Period in such situation, so fractional part (from sec) was silently truncated.

Can't uncomment the test yet, because parse_timestamp() is effectively
unused: the code added to parse_value() in 5abd9e7dec
was wrong as it attempted to handle unquoted date/time literals. One
part of it was commented out earlier, the other can't work as far as I
can see, as it tries to parse a Number token - `([0-9]|\.)+` - as a
timestamp, so I removed it as well.
2019-01-11 02:37:36 +03:00
Nickolay Ponomarev
52277c3025 Remove parse_function_or_pg_cast, since fn(...) :: type is taken care of in parse_infix() 2019-01-11 02:37:36 +03:00
Nickolay Ponomarev
eff92a2dc1 Remove special handling of ::type1::type2 from parse_pg_cast
...it gets handled just as well by the infix parser.
(Add a test while we're at it.)
2019-01-11 02:37:36 +03:00
Nickolay Ponomarev
f21cd697c3 Simplify custom datatypes handling and add a test
1) Simplified the bit in parse_datatype()
2) Made sure it was covered by the test (the "public.year" bit)
2a) ...the rest of changes in the test are to fix incorrect variable
 names: c_name/c_lat/c_lng were copy-pasted from a previous test.
3) Removed the branch from parse_pg_cast, which duplicated what
parse_data_type already handled (added in the same commit even
2007995938 )
2019-01-11 02:37:36 +03:00
Nickolay Ponomarev
7c6e6970fa Simplify the {next|prev|peek}_token functions
Remove `pub` from the "internal" ones. Remove ones that duplicate each
other completely.
2019-01-11 02:37:36 +03:00
Nickolay Ponomarev
2873b0cee2 Combine multiple patterns with the same action in parse_prefix() 2019-01-11 01:49:13 +03:00
Andy Grove
ee1944b9d9 Implemented NOT LIKE 2018-12-16 16:30:32 -07:00
Andy Grove
5d62167d6e rename rex to expr in ASTNode 2018-12-16 14:04:51 -07:00
Andy Grove
7aab880387 implement NOT 2018-12-16 14:03:03 -07:00
Andy Grove
2240dd09ff (cargo-release) start next development iteration 0.1.10-alpha.0 2018-12-16 13:57:25 -07:00