From 99b38aa3fab3ee545d8467aff3b64565092d497e Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 23 Apr 2021 15:29:28 -0400 Subject: [PATCH] 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. --- Userland/Libraries/LibSQL/AST.h | 16 +++++++++ Userland/Libraries/LibSQL/Parser.cpp | 35 ++++++++++++++++--- Userland/Libraries/LibSQL/Parser.h | 1 + .../LibSQL/Tests/TestSqlExpressionParser.cpp | 33 +++++++++++++++++ 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibSQL/AST.h b/Userland/Libraries/LibSQL/AST.h index 922432b48a..96f0e970dc 100644 --- a/Userland/Libraries/LibSQL/AST.h +++ b/Userland/Libraries/LibSQL/AST.h @@ -537,6 +537,22 @@ private: RefPtr m_else_expression; }; +class ExistsExpression : public Expression { +public: + ExistsExpression(NonnullRefPtr& select_statement() const { return m_select_statement; } + bool invert_expression() const { return m_invert_expression; } + +private: + NonnullRefPtr