/* * Copyright (c) 2021, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace SQL { class Parser { struct Position { size_t line { 0 }; size_t column { 0 }; }; struct Error { String message; Position position; String to_string() const { return String::formatted("{} (line: {}, column: {})", message, position.line, position.column); } }; public: explicit Parser(Lexer lexer); NonnullRefPtr next_statement(); bool has_errors() const { return m_parser_state.m_errors.size(); } const Vector& errors() const { return m_parser_state.m_errors; } protected: NonnullRefPtr parse_expression(); // Protected for unit testing. private: struct ParserState { explicit ParserState(Lexer); Lexer m_lexer; Token m_token; Vector m_errors; }; NonnullRefPtr parse_statement(); NonnullRefPtr parse_statement_with_expression_list(RefPtr); NonnullRefPtr parse_create_table_statement(); NonnullRefPtr parse_alter_table_statement(); NonnullRefPtr parse_drop_table_statement(); NonnullRefPtr parse_insert_statement(RefPtr); NonnullRefPtr parse_update_statement(RefPtr); NonnullRefPtr parse_delete_statement(RefPtr); NonnullRefPtr