Serenity Operating System
at master 61 lines 1.7 kB view raw
1/* 2 * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org> 3 * Copyright (c) 2021, Jan de Visser <jan@de-visser.net> 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#pragma once 9 10#include "Token.h" 11#include <AK/DeprecatedString.h> 12#include <AK/HashMap.h> 13#include <AK/StringView.h> 14 15namespace SQL::AST { 16 17class Lexer { 18public: 19 explicit Lexer(StringView source); 20 21 Token next(); 22 23private: 24 void consume(StringBuilder* = nullptr); 25 26 bool consume_whitespace_and_comments(); 27 bool consume_numeric_literal(StringBuilder&); 28 bool consume_string_literal(StringBuilder&); 29 bool consume_quoted_identifier(StringBuilder&); 30 bool consume_blob_literal(StringBuilder&); 31 bool consume_exponent(StringBuilder&); 32 bool consume_hexadecimal_number(StringBuilder&); 33 34 bool match(char a, char b) const; 35 bool is_identifier_start() const; 36 bool is_identifier_middle() const; 37 bool is_numeric_literal_start() const; 38 bool is_string_literal_start() const; 39 bool is_string_literal_end() const; 40 bool is_quoted_identifier_start() const; 41 bool is_quoted_identifier_end() const; 42 bool is_blob_literal_start() const; 43 bool is_line_comment_start() const; 44 bool is_block_comment_start() const; 45 bool is_block_comment_end() const; 46 bool is_line_break() const; 47 bool is_eof() const; 48 49 static HashMap<DeprecatedString, TokenType> s_keywords; 50 static HashMap<char, TokenType> s_one_char_tokens; 51 static HashMap<DeprecatedString, TokenType> s_two_char_tokens; 52 53 StringView m_source; 54 size_t m_line_number { 1 }; 55 size_t m_line_column { 0 }; 56 char m_current_char { 0 }; 57 bool m_eof { false }; 58 size_t m_position { 0 }; 59}; 60 61}