2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-10-25 19:52:44 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-03-12 12:28:20 +02:00
|
|
|
#include "LibCpp/Token.h"
|
2019-10-25 19:52:44 +02:00
|
|
|
#include <AK/StringView.h>
|
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
|
|
2020-09-28 16:21:25 +03:00
|
|
|
namespace Cpp {
|
2020-02-07 20:07:15 +01:00
|
|
|
|
2020-09-28 16:21:25 +03:00
|
|
|
class Lexer {
|
2019-10-25 19:52:44 +02:00
|
|
|
public:
|
2021-08-06 10:16:53 +03:00
|
|
|
explicit Lexer(StringView const&, size_t start_line = 0);
|
2019-10-25 19:52:44 +02:00
|
|
|
|
2020-09-28 16:21:25 +03:00
|
|
|
Vector<Token> lex();
|
2019-10-25 19:52:44 +02:00
|
|
|
|
|
|
|
|
private:
|
2019-12-09 17:45:40 +01:00
|
|
|
char peek(size_t offset = 0) const;
|
2019-10-25 19:52:44 +02:00
|
|
|
char consume();
|
|
|
|
|
|
|
|
|
|
StringView m_input;
|
2019-12-09 17:45:40 +01:00
|
|
|
size_t m_index { 0 };
|
2020-09-28 16:21:25 +03:00
|
|
|
Position m_previous_position { 0, 0 };
|
|
|
|
|
Position m_position { 0, 0 };
|
2019-10-25 19:52:44 +02:00
|
|
|
};
|
2020-02-07 20:07:15 +01:00
|
|
|
|
|
|
|
|
}
|