Commit Graph

232 Commits

Author SHA1 Message Date
Linus Groh
0aab774343 Everywhere: Fix a bunch of typos 2021-05-17 17:48:55 +01:00
Dylan Katz
984b6e08cf LibSQL: Add a syntax highlighter 2021-05-09 09:39:05 +02:00
Brian Gianforcaro
597de3356f Tests: Move LibSQL tests to Tests/LibSQL 2021-05-06 17:54:28 +02:00
Gunnar Beutner
beae2d5caa LibSQL: Fix incorrect return types
Right now RefPtr<T> is way more lenient than it should be. That might
change in the future though.
2021-05-05 22:00:57 +02:00
Andrew Kaster
35c0a6c54d AK+Userland: Move AK/TestSuite.h into LibTest and rework Tests' CMake
As many macros as possible are moved to Macros.h, while the
macros to create a test case are moved to TestCase.h. TestCase is now
the only user-facing header for creating a test case. TestSuite and its
helpers have moved into a .cpp file. Instead of requiring a TEST_MAIN
macro to be instantiated into the test file, a TestMain.cpp file is
provided instead that will be linked against each test. This has the
side effect that, if we wanted to have test cases split across multiple
files, it's as simple as adding them all to the same executable.

The test main should be portable to kernel mode as well, so if
there's a set of tests that should be run in self-test mode in kernel
space, we can accomodate that.

A new serenity_test CMake function streamlines adding a new test with
arguments for the test source file, subdirectory under /usr/Tests to
install the test application and an optional list of libraries to link
against the test application. To accomodate future test where the
provided TestMain.cpp is not suitable (e.g. test-js), a CUSTOM_MAIN
parameter can be passed to the function to not link against the
boilerplate main function.
2021-04-25 09:36:49 +02:00
Timothy Flynn
1500479a1d LibSQL: Parse ALTER TABLE statement
There are 4 forms an ALTER TABLE statement can take, and each are very
distinct, so they each get their own AST node class.
2021-04-24 14:22:08 +02:00
Timothy Flynn
0764a68616 LibSQL: Parse UPDATE statement
This also migrates parsing of conflict resolution to a helper method,
since both INSERT and UPDATE need it.
2021-04-24 14:22:08 +02:00
Timothy Flynn
8d79b4a3e1 LibSQL: Parse INSERT statement
This also adds missing '&' on a couple AST getter methods.
2021-04-24 14:22:08 +02:00
Timothy Flynn
35f0450dd8 LibSQL: Add missing forward declarations 2021-04-24 14:22:08 +02:00
Timothy Flynn
fa59d02692 LibSQL: Parse IN / NOT IN expressions with a nested SELECT statement 2021-04-23 22:36:07 +02:00
Timothy Flynn
004025c3c4 LibSQL: Parse common-table-expressions with a nested SELECT statement
This also moves testing of common-table-expression to its own test case.
2021-04-23 22:36:07 +02:00
Timothy Flynn
cb943a2179 LibSQL: Parse CREATE TABLE statements with a nested SELECT statement 2021-04-23 22:36:07 +02:00
Timothy Flynn
99b38aa3fa LibSQL: Parse EXISTS expressions
The EXISTS expression is a bit of an odd-man-out because it can appear
as any of the following forms:

    EXISTS (select-stmt)
    NOT EXISTS (select-stmt)
    (select-stmt)

Which makes it the only keyword expression that doesn't require its
keyword to actually be used. The consequence is that we might come
across an EXISTS expression while parsing another expression type;
NOT would have triggered a unary operator expression, and an opening
parentheses would have triggered an expression chain.
2021-04-23 22:36:07 +02:00
Timothy Flynn
e62e76ca1a LibSQL: Parse terminating semi-colon in top-level statement parser
Currently, every parse_*_statement method ends by parsing a semi-colon.
This will prevent nested statements, e.g. a SELECT statement may be
nested in a CREATE TABLE statement. Move the semi-colon expectation up
and out of the individual statement parsers.
2021-04-23 22:36:07 +02:00
Timothy Flynn
27685bc799 LibSQL: Add Parser::parse_schema_and_table_name helper
Another common semantic is parsing an identifier of the form
"schema_name.table_name" / "table_name". Add a helper to do this work.

This helper does not parse any optional alias after the table name.
some syntaxes specify an alias using the AS keyword, some let the AS
keyword be optional, and others just parse it as an identifier. So
callers to this helper will just continue parsing the alias however
they require.
2021-04-23 22:36:07 +02:00
Timothy Flynn
418884ab64 LibSQL: Add Parser::parse_comma_separated_list helper
A quite common semantic emerged for parsing comma-separated expressions:

    consume(TokenType::ParenOpen);

    do {
        // do something

        if (!match(TokenType::Comma))
            break;

        consume(TokenType::Comma);
    } while (!match(TokenType::Eof));

    consume(TokenType::ParenClose);

Add a helper to do the bulk of the while loop.
2021-04-23 22:36:07 +02:00
Timothy Flynn
6a69b8efa7 LibSQL: Fix handling of optional AS keywords
In some syntaxes, using the 'AS' keyword to define an alias is optional.
But if it does appear, an identifier better appear afterwards.
2021-04-23 22:36:07 +02:00
Andreas Kling
b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Timothy Flynn
ac0e387beb LibSQL: Parse (most of) SELECT statement
This doesn't yet parse join clauses, windowing functions, or compound
SELECT statements.
2021-04-22 18:08:15 +02:00
Timothy Flynn
9331293e44 LibSQL: Separate parsing of common-table-expression list
Statements like SELECT, INSERT, and UPDATE also optionally include this
list, so move its parsing out of parse_delete_statement(). Since it will
appear before the actual statement, parse it first in next_statement();
then only parse for statements that are allowed to include the list.
2021-04-22 18:08:15 +02:00
Timothy Flynn
6a7d7624a7 LibSQL: Fix parsing of lists of common-table-expression
Misread the graph: In the "WITH [RECURSIVE] common-table-expression"
section, common-table-expression is actually a repeating list. This
changes the parser to correctly parse this section as a list. Create a
new AST node, CommonTableExpressionList, to store both this list and the
boolean RECURSIVE attribute (because every statement that uses this list
also includes the RECURSIVE attribute beforehand).
2021-04-22 18:08:15 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Timothy Flynn
6cbf88ad4c LibSQL: Rename TestSqlParser -> TestSqlStatementParser
A little bit clearer what is being tested now, since the expression
parser also lives in its own file.
2021-04-21 21:37:55 +02:00
Timothy Flynn
733806b6a1 LibSQL: Parse DELETE statement 2021-04-21 21:37:55 +02:00
Timothy Flynn
ce6c7ae18a LibSQL: Parse most language expressions
https://sqlite.org/lang_expr.html

The entry point to using expressions, parse_expression(), is not used
by SQL::Parser in this commit. But there's so much here that it's easier
to grok as its own commit.
2021-04-21 21:37:55 +02:00
Timothy Flynn
8c8d611fb3 LibSQL: Add forwarding header
SQL AST nodes will need to have other node types forward declared before
using them.
2021-04-21 21:37:55 +02:00
Timothy Flynn
a11f49f627 LibSQL: Add Parser::consume_if helper
The following is a common (and soon to be *very* common) expression:

    if (match(token_type))
        consume();

Using consume_if() makes this a bit simpler and makes it less likely to
forget to invoke consume() after the match().
2021-04-21 21:37:55 +02:00
Timothy Flynn
570aa57df3 LibSQL: Lex string and blob literals
Blob literals are the same as string literals except prefixed with an
'x' or 'X'.
2021-04-21 21:37:55 +02:00
Timothy Flynn
e92bffb2e3 LibSQL: Parse DROP TABLE statement 2021-04-20 18:28:34 +02:00
Timothy Flynn
d41d1d2035 LibSQL: Add unit testing of the SQL parser 2021-04-20 18:28:34 +02:00
Timothy Flynn
377992d33e LibSQL: Create a very barebones SQL parser
This parser builds on the LibSQL lexer and currently only allows users
to parse 'CREATE TABLE' statements.
2021-04-20 18:28:34 +02:00
Timothy Flynn
90517da9ca LibSQL: Introduce a SQL library with a tokenizer
LibSQL aims to be a SQLite clone for SerenityOS. Step 1 is creating a
tokenizer to lex SQL tokens. This lexer is heavily influenced by the
LibJS lexer.
2021-04-20 18:28:34 +02:00